Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
deepcloudlabs committed Jul 20, 2022
1 parent 48357b1 commit 9bda925
Show file tree
Hide file tree
Showing 12 changed files with 195 additions and 0 deletions.
10 changes: 10 additions & 0 deletions StudyInterfaces/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
17 changes: 17 additions & 0 deletions StudyInterfaces/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>StudyInterfaces</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
2 changes: 2 additions & 0 deletions StudyInterfaces/.settings/org.eclipse.core.resources.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
eclipse.preferences.version=1
encoding/<project>=UTF-8
14 changes: 14 additions & 0 deletions StudyInterfaces/.settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=17
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=17
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
org.eclipse.jdt.core.compiler.release=enabled
org.eclipse.jdt.core.compiler.source=17
21 changes: 21 additions & 0 deletions StudyInterfaces/src/com/example/Exercise01.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.example;

public class Exercise01 {

public static void main(String[] args) {

}

}

interface A {
}

interface B {
}

interface C {
}

interface D extends A, B, C { // multiple inheritance
}
21 changes: 21 additions & 0 deletions StudyInterfaces/src/com/example/Exercise02.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.example;

public class Exercise02 {

public static void main(String[] args) {
DD o = new DD();
System.out.println(o instanceof DD);
System.out.println(o instanceof CC);
// Error : System.out.println(o instanceof AA);
System.out.println(o instanceof BB);
}

}

abstract class AA {}
abstract class GG {}
interface BB {}
interface FF {}
abstract class CC {}

class DD extends CC implements BB, FF {}
27 changes: 27 additions & 0 deletions StudyInterfaces/src/com/example/Exercise03.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.example;

public class Exercise03 {
public static void main(String[] args) {

}
}

sealed interface Service permits ABC, XYZ {
int fun();
}

final class ABC implements Service {

@Override
public int fun() {
return 42;
}
}

final class XYZ implements Service {

@Override
public int fun() {
return 108;
}
}
10 changes: 10 additions & 0 deletions study-functional-programming/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
17 changes: 17 additions & 0 deletions study-functional-programming/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>study-functional-programming</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
eclipse.preferences.version=1
encoding/<project>=UTF-8
14 changes: 14 additions & 0 deletions study-functional-programming/.settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=17
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=17
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
org.eclipse.jdt.core.compiler.release=enabled
org.eclipse.jdt.core.compiler.source=17
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.example;

import java.util.List;
import java.util.function.Predicate;

public class DefineFunctionalProgramming {

public static void main(String[] args) {
// fp's function: 1) higher-order function
// 2) pure function -> immutable ->
// i. Lambda Expression
// ii. Method Reference
var numbers = List.of(4, 8, 15, 16, 23, 42);
// even -> cube -> sum
// New Type: function -> functional interface -> Single Abstract Method
MyFun x = u -> 2 * u - 5 ;

// Build-in Functional Interface: Predicate, Function, ...
Predicate<Integer> isEven = z -> z%2 == 0;
var result =
numbers.stream()
//.filter(z -> z%2 ==0) // 4 8 16 42
.filter(MyFun::ciftMi) // 4 8 16 42
//.mapToInt(p -> p*p*p) // 64 512 4096 74088
.mapToInt(MyFun::kubu) // 64 512 4096 74088
// (0,64) -> 64 -> (64,512) -> 576 -> (576,4096) -> 4672 -> (4672,74088) -> 78760
//.reduce(0, (s,r)->s+r);
//.reduce(0, Integer::sum);
.sum();
System.out.println(result);
}

}

@FunctionalInterface
interface MyFun {
int fun(int x);
static boolean ciftMi(int x) { return x%2 == 0;}
static int kubu(int x) {return x*x*x;}
}

0 comments on commit 9bda925

Please sign in to comment.