-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9593890
commit 6349212
Showing
24 changed files
with
276 additions
and
0 deletions.
There are no files selected for viewing
File renamed without changes.
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>study-annotations-and-reflection-api</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> |
File renamed without changes.
File renamed without changes.
15 changes: 15 additions & 0 deletions
15
study-annotations-and-reflection-api/src/com/example/lottery/application/LotteryApp.java
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 @@ | ||
package com.example.lottery.application; | ||
|
||
import com.example.lottery.model.LotteryViewModel; | ||
import com.example.lottery.service.RandomNumberGeneratorService; | ||
|
||
public class LotteryApp { | ||
|
||
public static void main(String[] args) { | ||
var lotteryModel = new LotteryViewModel(); | ||
var service = new RandomNumberGeneratorService(); | ||
service.generate(lotteryModel); | ||
System.out.println(lotteryModel.getNumbers()); | ||
} | ||
|
||
} |
15 changes: 15 additions & 0 deletions
15
study-annotations-and-reflection-api/src/com/example/lottery/model/LotteryViewModel.java
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 @@ | ||
package com.example.lottery.model; | ||
|
||
import java.util.List; | ||
|
||
import com.example.lottery.service.RandomNumber; | ||
|
||
public class LotteryViewModel { | ||
@RandomNumber(min = 1, max = 60, distinct = true, sorted = true, size = 6) | ||
private List<Integer> numbers; | ||
|
||
public List<Integer> getNumbers() { | ||
return numbers; | ||
} | ||
|
||
} |
22 changes: 22 additions & 0 deletions
22
study-annotations-and-reflection-api/src/com/example/lottery/service/RandomNumber.java
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 com.example.lottery.service; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
@Target(ElementType.FIELD) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
public @interface RandomNumber { | ||
|
||
int min(); | ||
|
||
int max(); | ||
|
||
boolean distinct(); | ||
|
||
boolean sorted(); | ||
|
||
int size(); | ||
|
||
} |
33 changes: 33 additions & 0 deletions
33
...ions-and-reflection-api/src/com/example/lottery/service/RandomNumberGeneratorService.java
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,33 @@ | ||
package com.example.lottery.service; | ||
|
||
import java.util.concurrent.ThreadLocalRandom; | ||
|
||
public class RandomNumberGeneratorService { | ||
|
||
public void generate(Object o) { | ||
var clazz = o.getClass(); | ||
for (var field : clazz.getDeclaredFields()) { | ||
if (field.isAnnotationPresent(RandomNumber.class)) { | ||
var randomNumberAnnotation = field.getAnnotation(RandomNumber.class); | ||
var min = randomNumberAnnotation.min(); | ||
var max = randomNumberAnnotation.max(); | ||
var size = randomNumberAnnotation.size(); | ||
var streamOfNumbers = ThreadLocalRandom.current().ints(min, max); | ||
if (randomNumberAnnotation.distinct()) | ||
streamOfNumbers = streamOfNumbers.distinct(); | ||
|
||
streamOfNumbers = streamOfNumbers.limit(size); | ||
if (randomNumberAnnotation.sorted()) | ||
streamOfNumbers = streamOfNumbers.sorted(); | ||
var numbers = streamOfNumbers.boxed().toList(); | ||
try { | ||
field.setAccessible(true); | ||
field.set(o, numbers); | ||
field.setAccessible(false); | ||
} catch (IllegalArgumentException | IllegalAccessException e) { | ||
System.err.println("Error: %s".formatted(e.getMessage())); | ||
} | ||
} | ||
} | ||
} | ||
} |
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 @@ | ||
<?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> |
File renamed without changes.
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,2 @@ | ||
eclipse.preferences.version=1 | ||
encoding/<project>=UTF-8 |
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,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 |
File renamed without changes.
File renamed without changes.
File renamed without changes.
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 @@ | ||
<?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> |
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>study-utility-classes</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
2
study-utility-classes/.settings/org.eclipse.core.resources.prefs
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,2 @@ | ||
eclipse.preferences.version=1 | ||
encoding/<project>=UTF-8 |
14 changes: 14 additions & 0 deletions
14
study-utility-classes/.settings/org.eclipse.jdt.core.prefs
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,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 |
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,44 @@ | ||
package com.example; | ||
|
||
import java.text.Collator; | ||
import java.text.ParseException; | ||
import java.text.RuleBasedCollator; | ||
import java.util.ArrayList; | ||
import java.util.Locale; | ||
|
||
public class StudyCollation { | ||
|
||
public static void main(String[] args) throws ParseException { | ||
var name1 = "müller"; | ||
var name2 = "mueller"; | ||
System.out.println(name1.equals(name2)); | ||
var names = new ArrayList<String>(); | ||
names.add("şule"); | ||
names.add("şima"); | ||
names.add("sema"); | ||
names.add("ayşegül"); | ||
names.add("zehra"); | ||
names.add("ali"); | ||
names.add("veli"); | ||
System.out.println(names); | ||
names.sort(String::compareTo); | ||
System.out.println(names); | ||
// şule == schule | ||
System.out.println("şule".equals("schule")); | ||
// şima == shema | ||
System.out.println("şima".equals("shema")); | ||
String basicRules= "< z < b < c < ç < d < e < f < g < ğ < h "+ | ||
"< ı < i < j < k < l < m < n < o < ö < p "+ | ||
"< r < s < ş < t < u < ü < v < y < a "; | ||
String trExpension= "& şi ; she & ş ; sch & s ; ş & u ; ü & i ; ı " + | ||
"& c ; ç & o ; ö & ğ ; g" ; | ||
final Collator collator= new RuleBasedCollator(basicRules + trExpension); | ||
Collator.getInstance(new Locale("tr","TR")); | ||
collator.setStrength(Collator.PRIMARY); | ||
System.out.println(collator.equals("şule","schule")); | ||
System.out.println(collator.equals("şima","shema")); | ||
names.sort(collator::compare); | ||
System.out.println(names); | ||
} | ||
|
||
} |
20 changes: 20 additions & 0 deletions
20
study-utility-classes/src/com/example/StudyDynamicString.java
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,20 @@ | ||
package com.example; | ||
|
||
public class StudyDynamicString { | ||
|
||
@SuppressWarnings("unused") | ||
public static void main(String[] args) { | ||
String name = "jack"; // immutable | ||
int result = 42; | ||
// StringBuilder: not thread-safe | ||
// StringBuffer: thread-safe | ||
StringBuffer message = new StringBuffer(388888890); | ||
var start = System.currentTimeMillis(); | ||
for (var i=0;i<50_000_000;++i) | ||
message.append(i); | ||
var stop = System.currentTimeMillis(); | ||
System.out.println(message.length()); | ||
System.err.println("Duration: %d".formatted(stop-start)); | ||
} | ||
|
||
} |
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,39 @@ | ||
package com.example; | ||
|
||
import java.text.DecimalFormat; | ||
import java.text.MessageFormat; | ||
import java.time.ZonedDateTime; | ||
import java.time.format.DateTimeFormatter; | ||
import java.time.format.FormatStyle; | ||
import java.util.Locale; | ||
import java.util.ResourceBundle; | ||
|
||
public class StudyString { | ||
|
||
public static void main(String[] args) { | ||
System.setProperty("user.language", "tr"); // ISO2 | ||
System.setProperty("user.country", "TR"); | ||
System.getenv().forEach((key,value) -> System.out.println("%s: %s".formatted(key,value))); | ||
System.getProperties().forEach((key,value) -> System.out.println("%s: %s".formatted(key,value))); | ||
String city = "izmir"; | ||
Locale tr_TR= new Locale("tr", "TR"); | ||
System.out.println(city.toUpperCase(tr_TR)); | ||
|
||
var now = ZonedDateTime.now(); | ||
DateTimeFormatter dtf = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.FULL) | ||
.withLocale(Locale.GERMAN); | ||
System.out.println(dtf.format(now)); | ||
|
||
double money = 12_345.67; | ||
DecimalFormat df = (DecimalFormat) DecimalFormat.getCurrencyInstance(Locale.CHINA); | ||
System.out.println(df.format(money)); | ||
|
||
String fullname= "Jack Bauer"; | ||
var resourceBundle= ResourceBundle.getBundle("messages",Locale.US); | ||
var helloTemplate = resourceBundle.getString("hello"); | ||
var formatter = new MessageFormat(helloTemplate, tr_TR); | ||
|
||
System.out.println(formatter.format(new Object[] {fullname})); | ||
} | ||
|
||
} |
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 @@ | ||
hello:Hello, {0}! |
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 @@ | ||
hello=Merhaba, {0}! |