-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
OOP Bus #1
Open
duongxinh2003
wants to merge
29
commits into
master
Choose a base branch
from
SonNH
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
OOP Bus #1
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
5e8dc7d
OOP Bus
4ab978e
Chapter 1, 2, 3
41acdf5
Day 2: chapter 3 4 5pg 149
89c8f4a
day 3 chapter 5 page 168
6bdbe8f
day 4 chapter 7
72fd643
day 5 I/O
ab7ec0c
removed unusal file
9be19c7
Removing ignored files
f2dd4ab
day6
4951784
day7
03fce58
day8
67bac59
day9
05a9a4d
day 10
f022e23
queue and linkedlist
ba5b48d
day 11
04bf44d
try exercise
182e3bf
60%
8951f1c
At home
duongxinh2003 c8325f0
BlockingQueue
aa839bd
03/01/19
b6a716c
04/01/19
7aa5613
04/01/19
d161a1a
solution3
duongxinh2003 3992648
solution4
duongxinh2003 c31233d
16/01/2019
3fef608
Merge branch 'SonNH' of https://github.com/duongxinh2003/Learning-Jav…
a5c3bfe
16/01/2019
d6ebc9d
add last file
95e60b1
a java 8
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/.metadata/ | ||
/.recommenders/ | ||
/.project |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?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-1.8"/> | ||
<classpathentry kind="src" path="src"/> | ||
<classpathentry kind="lib" path="C:/Users/Son.NguyenHong/.m2/repository/org/springframework/spring-core/5.0.8.RELEASE/spring-core-5.0.8.RELEASE.jar" sourcepath="C:/Users/Son.NguyenHong/.m2/repository/org/springframework/spring-core/5.0.8.RELEASE/spring-core-5.0.8.RELEASE-sources.jar"> | ||
<attributes> | ||
<attribute name="maven.pomderived" value="true"/> | ||
<attribute name="maven.groupId" value="org.springframework"/> | ||
<attribute name="maven.artifactId" value="spring-core"/> | ||
<attribute name="maven.version" value="5.0.8.RELEASE"/> | ||
<attribute name="maven.scope" value="compile"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="output" path="bin"/> | ||
</classpath> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>A Java 8</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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
eclipse.preferences.version=1 | ||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled | ||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 | ||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve | ||
org.eclipse.jdt.core.compiler.compliance=1.8 | ||
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.enumIdentifier=error | ||
org.eclipse.jdt.core.compiler.source=1.8 |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"bus-seat-type-a" : { | ||
"mappings" : { | ||
"bus-seat-type" : { | ||
"properties" : { | ||
"seatTypeId" : { | ||
"type" : "text", | ||
"fields" : { | ||
"keyword" : { | ||
"type" : "keyword", | ||
"ignore_above" : 256 | ||
} | ||
} | ||
}, | ||
"seatTypeName" : { | ||
"type" : "text", | ||
"fields" : { | ||
"keyword" : { | ||
"type" : "keyword", | ||
"ignore_above" : 256 | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package sonnh.lambdaexpression; | ||
|
||
@FunctionalInterface | ||
public interface Adder { | ||
double add(double n1, double n2); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package sonnh.lambdaexpression; | ||
|
||
@FunctionalInterface | ||
public interface Comparator<T> { | ||
// Abstract method declare in interface | ||
int compare(T o1, T o2); | ||
|
||
@Override | ||
boolean equals(Object object); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package sonnh.lambdaexpression; | ||
|
||
@FunctionalInterface | ||
public interface Joiner { | ||
String join(String s1, String s2); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package sonnh.lambdaexpression; | ||
|
||
public class LambdaUtil { | ||
public void testAdder(Adder adder) { | ||
double x = 190.90; | ||
double y = 8.50; | ||
double sum = adder.add(x, y); | ||
System.out.println("Using an Adder: "); | ||
System.out.println(x + " + " + y + " = " + sum); | ||
} | ||
|
||
public void testJoiner(Joiner joiner) { | ||
String s1 = "Hello"; | ||
String s2 = "World"; | ||
String s3 = joiner.join(s1, s2); | ||
System.out.println("Using a Joiner: "); | ||
System.out.println("\"" + s1 + "\" + \"" + s2 + "\" = \"" + s3 + "\""); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package sonnh.lambdaexpression; | ||
|
||
public class LambdaUtil2 { | ||
public void test(Adder adder) { | ||
double x = 199.90; | ||
double y = 8.50; | ||
double sum = adder.add(x, y); | ||
System.out.println("Using an adder: "); | ||
System.out.println(x + " + " + y + " = " + sum); | ||
} | ||
|
||
public void test(Joiner joiner) { | ||
String s1 = "Hello"; | ||
String s2 = "World"; | ||
String s3 = joiner.join(s1, s2); | ||
System.out.println("Using a joiner: "); | ||
System.out.println("\"" + s1 + "\" + \"" + s2 + "\" = \"" + s3 + "\""); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package sonnh.lambdaexpression; | ||
|
||
public class LambdaUtil2Test { | ||
public static void main(String[] args) { | ||
LambdaUtil2 util2 = new LambdaUtil2(); | ||
// A compile error | ||
// util2.test((x, y) -> x + y); | ||
// Fix error | ||
util2.test((double x, double y) -> x + y); // solution 1 | ||
util2.test((Adder) (x, y) -> x + y); // solution 2 | ||
// Solution 3 | ||
Adder adder = (x, y) -> x + y; | ||
util2.test(adder); | ||
|
||
// Calls the testJoiner() method | ||
util2.test((String x, String y) -> x + y); | ||
|
||
// Calls the testJoiner() method. The Joiner will | ||
// add a space between the two strings | ||
util2.test((Joiner) (x, y) -> x + y); | ||
|
||
// Call the testJoiner() method. The joiner will | ||
// reserve the strings and join resulting strings in | ||
// reserve order adding a comma in between | ||
util2.test((Joiner) (x, y) -> { | ||
StringBuilder sbx = new StringBuilder(x); | ||
StringBuilder sby = new StringBuilder(y); | ||
sby.reverse().append(",").append(sbx.reverse()); | ||
return sby.toString(); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package sonnh.lambdaexpression; | ||
|
||
public class LambdaUtilTest { | ||
public static void main(String[] args) { | ||
LambdaUtil util = new LambdaUtil(); | ||
|
||
// Call the testAdder() method | ||
util.testAdder((x, y) -> x + y); | ||
|
||
// Call the testJoiner() method | ||
util.testJoiner((x, y) -> x + y); | ||
|
||
// Call the testJoiner() method. The joiner will add a space between the two strings | ||
util.testJoiner((x, y) -> x + " " + y); | ||
|
||
// Call the testJoiner() method. The Joiner will add a space between the two string in reserve | ||
// order adding a comma in between | ||
util.testJoiner((x, y) -> { | ||
StringBuilder sbx = new StringBuilder(x); | ||
StringBuilder sby = new StringBuilder(y); | ||
sby.reverse().append(",").append(sbx.reverse()); | ||
return sby.toString(); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package sonnh.lambdaexpression; | ||
|
||
public interface Mapper<T> { | ||
// An abstract method | ||
int map(T array); | ||
|
||
// A generic static method | ||
public static <U> int[] listToMapper(U[] list, Mapper<? super U> mapper) { | ||
int[] mapperValue = new int[list.length]; | ||
for (int i = 0; i < list.length; i++) { | ||
// Map the object to an int | ||
mapperValue[i] = mapper.map(list[i]); | ||
} | ||
return mapperValue; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package sonnh.lambdaexpression; | ||
|
||
public class MapperTest { | ||
public static void main(String[] args) { | ||
// Mapp names using their length | ||
System.out.println("Mapping names to their lengths: "); | ||
String[] names = {"David", "Son", "Trng"}; | ||
int[] lengthMapping = Mapper.listToMapper(names, (String name) -> name.length()); | ||
printMapping(names, lengthMapping); | ||
|
||
System.out.println("\nMapping integers to theirs squares: "); | ||
Integer[] numbers = {7, 3, 67}; | ||
int[] countMapping = Mapper.listToMapper(numbers, (Integer n) -> n * n); | ||
printMapping(numbers, countMapping); | ||
} | ||
|
||
public static void printMapping(Object[] from, int[] to) { | ||
for (int i = 0; i < from.length; i++) { | ||
System.out.println(from[i] + " mapped to " + to[i]); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package sonnh.lambdaexpression; | ||
|
||
@FunctionalInterface | ||
public interface Processor { | ||
<T> void process(T[] list); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package sonnh.lambdaexpression; | ||
|
||
public class TargetTypeTest { | ||
public static void main(String[] args) { | ||
// Create an Adder using a Lambda expression | ||
Adder adder = (x, y) -> x + y; | ||
|
||
// Creates a Joiner using a Lambda expression | ||
Joiner joiner = (x, y) -> x + y; | ||
|
||
// Adds two doubles | ||
double sum1 = adder.add(10.34, 89.22); | ||
|
||
// Add two lists | ||
double sum2 = adder.add(10, 89); | ||
|
||
// Joins two strings | ||
String str = joiner.join("Hello", " lambda"); | ||
|
||
System.out.println("sum1 = " + sum1); | ||
System.out.println("sum2 = " + sum2); | ||
System.out.println("str = " + str); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
package sonnh.reflection; | ||
|
||
import java.lang.reflect.Modifier; | ||
import java.lang.reflect.TypeVariable; | ||
|
||
public class ClassReflection { | ||
|
||
public static void main(String[] args) { | ||
// Print the class declaration for the Person class | ||
String classDescription = getClassDescription(Person.class); | ||
System.out.println(classDescription); | ||
} | ||
|
||
public static String getClassDescription(Class<Person> c) { | ||
StringBuilder classDesc = new StringBuilder(); | ||
|
||
// Prepare the modifiers and construct keyword(class, enum, interface,...) | ||
int modifierBits = 0; | ||
String keyword = ""; | ||
|
||
// Add keyword @interface, interface or class | ||
if (c.isPrimitive()) { | ||
// do not want to add any thing | ||
} else if (c.isInterface()) { | ||
modifierBits = c.getModifiers() & Modifier.interfaceModifiers(); | ||
|
||
// An annotation is an interface | ||
if (c.isAnnotation()) { | ||
keyword = "@interface"; | ||
} else { | ||
keyword = "interface"; | ||
} | ||
} else if (c.isEnum()) { | ||
modifierBits = c.getModifiers() & Modifier.classModifiers(); | ||
keyword = "enum"; | ||
} else { | ||
modifierBits = c.getModifiers() & Modifier.classModifiers(); | ||
keyword = "class"; | ||
} | ||
|
||
// Convert modifiers to their string representation | ||
String modifiers = Modifier.toString(modifierBits); | ||
|
||
// Append modifiers | ||
classDesc.append(modifiers); | ||
|
||
// Append the construct keyword | ||
classDesc.append(" " + keyword); | ||
|
||
// Append simple name | ||
String simpleName = c.getSimpleName(); | ||
classDesc.append(" " + simpleName); | ||
|
||
// Append generic parameters | ||
String genericParams = getGenericTypeParams(c); | ||
classDesc.append(genericParams); | ||
|
||
// Append super class | ||
Class<?> superClass = c.getSuperclass(); | ||
if (superClass != null) { | ||
String superClassSimpleName = superClass.getSimpleName(); | ||
classDesc.append(" extends " + superClassSimpleName); | ||
} | ||
|
||
// Append Interfaces | ||
String interfaces = ClassReflection.getClassInterfaces(c); | ||
if (interfaces != null) { | ||
classDesc.append(" implements " + interfaces); | ||
} | ||
return classDesc.toString(); | ||
} | ||
|
||
public static String getClassInterfaces(Class<Person> c) { | ||
// Get a comma-separated list of interfaces implemented by the class | ||
Class<?>[] interfaces = c.getInterfaces(); | ||
String interfaceList = null; | ||
if (interfaces.length > 0) { | ||
String[] interfaceNames = new String[interfaces.length]; | ||
for (int i = 0; i < interfaceNames.length; i++) { | ||
interfaceNames[i] = interfaces[i].getSimpleName(); | ||
} | ||
interfaceList = String.join(", ", interfaceNames); | ||
} | ||
return interfaceList; | ||
} | ||
|
||
public static String getGenericTypeParams(Class<Person> c) { | ||
StringBuilder sb = new StringBuilder(); | ||
TypeVariable<?>[] typeParams = c.getTypeParameters(); | ||
|
||
if (typeParams.length > 0) { | ||
String[] paramNames = new String[typeParams.length]; | ||
for (int i = 0; i < typeParams.length; i++) { | ||
paramNames[i] = typeParams[i].getName(); | ||
} | ||
|
||
sb.append('<'); | ||
String paramList = String.join(",", paramNames); | ||
sb.append(paramList); | ||
sb.append('>'); | ||
} | ||
return sb.toString(); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@duongxinh2003 Khi làm thì chú ý bỏ các file ko liên quan ra khỏi commit.