Merge pull request 'Java 8 文档内容和版本更新' (#25) from java-8 into main

Reviewed-on: #25
This commit is contained in:
honeymoose 2024-05-01 12:13:55 -04:00
commit 45197b3db5
46 changed files with 47 additions and 646 deletions

16
.idea/checkstyle-idea.xml Normal file
View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CheckStyle-IDEA" serialisationVersion="2">
<checkstyleVersion>10.14.2</checkstyleVersion>
<scanScope>JavaOnly</scanScope>
<copyLibs>true</copyLibs>
<option name="thirdPartyClasspath" />
<option name="activeLocationIds" />
<option name="locations">
<list>
<ConfigurationLocation id="bundled-sun-checks" type="BUNDLED" scope="All" description="Sun Checks">(bundled)</ConfigurationLocation>
<ConfigurationLocation id="bundled-google-checks" type="BUNDLED" scope="All" description="Google Checks">(bundled)</ConfigurationLocation>
</list>
</option>
</component>
</project>

View File

@ -20,6 +20,7 @@
<module name="core-java-lambdas" />
<module name="junit-5-basics" />
<module name="activejdbc" />
<module name="spring-data-jpa-repo" />
<module name="codebank" />
<module name="core-java-collections-list" />
<module name="image-compressing" />
@ -42,6 +43,7 @@
<module name="core-java-11-2" target="11" />
<module name="core-java-8-2" target="11" />
<module name="core-java-collections-list-3" target="11" />
<module name="spring-data-jpa-repo-2" target="17" />
</bytecodeTargetLevel>
</component>
<component name="JavacSettings">

View File

@ -61,6 +61,8 @@
<file url="file://$PROJECT_DIR$/persistence-modules/activejdbc/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/persistence-modules/spring-data-jpa-repo-2/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/persistence-modules/spring-data-jpa-repo-2/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/persistence-modules/spring-data-jpa-repo/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/persistence-modules/spring-data-jpa-repo/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/persistence-modules/spring-data-redis/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/persistence-modules/spring-data-redis/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/persistence-modules/src/main/java" charset="UTF-8" />

View File

@ -20,7 +20,7 @@
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${version.guava}</version>
<version>${guava.version}</version>
</dependency>
<dependency>
<groupId>org.openjdk.jmh</groupId>

View File

@ -1,73 +0,0 @@
package com.baeldung.game;
import java.util.*;
class RockPaperScissorsGame {
enum Move {
ROCK("rock"),
PAPER("paper"),
SCISSORS("scissors");
private String value;
Move(String value) {
this.value = value;
}
public String getValue() {
return value;
}
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int wins = 0;
int losses = 0;
System.out.println("Welcome to Rock-Paper-Scissors! Please enter \"rock\", \"paper\", \"scissors\", or \"quit\" to exit.");
while (true) {
System.out.println("-------------------------");
System.out.print("Enter your move: ");
String playerMove = scanner.nextLine();
if (playerMove.equals("quit")) {
System.out.println("You won " + wins + " times and lost " + losses + " times.");
System.out.println("Thanks for playing! See you again.");
break;
}
if (Arrays.stream(Move.values()).noneMatch(x -> x.getValue().equals(playerMove))) {
System.out.println("Your move isn't valid!");
continue;
}
String computerMove = getComputerMove();
if (playerMove.equals(computerMove)) {
System.out.println("It's a tie!");
} else if (isPlayerWin(playerMove, computerMove)) {
System.out.println("You won!");
wins++;
} else {
System.out.println("You lost!");
losses++;
}
}
}
private static boolean isPlayerWin(String playerMove, String computerMove) {
return playerMove.equals(Move.ROCK.value) && computerMove.equals(Move.SCISSORS.value)
|| (playerMove.equals(Move.SCISSORS.value) && computerMove.equals(Move.PAPER.value))
|| (playerMove.equals(Move.PAPER.value) && computerMove.equals(Move.ROCK.value));
}
private static String getComputerMove() {
Random random = new Random();
int randomNumber = random.nextInt(3);
String computerMove = Move.values()[randomNumber].getValue();
System.out.println("Computer move: " + computerMove);
return computerMove;
}
}

View File

@ -1,14 +0,0 @@
package com.baeldung.interfaceVsAbstractClass;
public class ChidlCircleInterfaceImpl implements CircleInterface {
private String color;
@Override
public String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
}
}

View File

@ -1,5 +0,0 @@
package com.baeldung.interfaceVsAbstractClass;
public class ChildCircleClass extends CircleClass {
}

View File

@ -1,23 +0,0 @@
package com.baeldung.interfaceVsAbstractClass;
import java.util.Arrays;
import java.util.List;
public abstract class CircleClass {
private String color;
private List<String> allowedColors = Arrays.asList("RED", "GREEN", "BLUE");
public boolean isValid() {
return allowedColors.contains(getColor());
}
public String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
}
}

View File

@ -1,14 +0,0 @@
package com.baeldung.interfaceVsAbstractClass;
import java.util.Arrays;
import java.util.List;
public interface CircleInterface {
List<String> allowedColors = Arrays.asList("RED", "GREEN", "BLUE");
String getColor();
public default boolean isValid() {
return allowedColors.contains(getColor());
}
}

View File

@ -1,18 +0,0 @@
package com.baeldung.jarArguments;
public class JarExample {
public static void main(String[] args) {
System.out.println("Hello Baeldung Reader in JarExample!");
if(args == null) {
System.out.println("You have not provided any arguments!");
}else {
System.out.println("There are "+args.length+" argument(s)!");
for(int i=0; i<args.length; i++) {
System.out.println("Argument("+(i+1)+"):" + args[i]);
}
}
}
}

View File

@ -1,21 +0,0 @@
package com.baeldung.localization;
import java.text.ParseException;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
public class App {
/**
* Runs all available formatter
* @throws ParseException
*/
public static void main(String[] args) {
List<Locale> locales = Arrays.asList(new Locale[] { Locale.UK, Locale.ITALY, Locale.FRANCE, Locale.forLanguageTag("pl-PL") });
Localization.run(locales);
JavaSEFormat.run(locales);
ICUFormat.run(locales);
}
}

View File

@ -1,29 +0,0 @@
package com.baeldung.localization;
import java.util.List;
import java.util.Locale;
import java.util.ResourceBundle;
import com.ibm.icu.text.MessageFormat;
public class ICUFormat {
public static String getLabel(Locale locale, Object[] data) {
ResourceBundle bundle = ResourceBundle.getBundle("formats", locale);
String format = bundle.getString("label-icu");
MessageFormat formatter = new MessageFormat(format, locale);
return formatter.format(data);
}
public static void run(List<Locale> locales) {
System.out.println("ICU formatter");
locales.forEach(locale -> System.out.println(getLabel(locale, new Object[] { "Alice", "female", 0 })));
locales.forEach(locale -> System.out.println(getLabel(locale, new Object[] { "Alice", "female", 1 })));
locales.forEach(locale -> System.out.println(getLabel(locale, new Object[] { "Alice", "female", 2 })));
locales.forEach(locale -> System.out.println(getLabel(locale, new Object[] { "Alice", "female", 3 })));
locales.forEach(locale -> System.out.println(getLabel(locale, new Object[] { "Bob", "male", 0 })));
locales.forEach(locale -> System.out.println(getLabel(locale, new Object[] { "Bob", "male", 1 })));
locales.forEach(locale -> System.out.println(getLabel(locale, new Object[] { "Bob", "male", 2 })));
locales.forEach(locale -> System.out.println(getLabel(locale, new Object[] { "Bob", "male", 3 })));
}
}

View File

@ -1,24 +0,0 @@
package com.baeldung.localization;
import java.text.MessageFormat;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.ResourceBundle;
public class JavaSEFormat {
public static String getLabel(Locale locale, Object[] data) {
ResourceBundle bundle = ResourceBundle.getBundle("formats", locale);
final String pattern = bundle.getString("label");
final MessageFormat formatter = new MessageFormat(pattern, locale);
return formatter.format(data);
}
public static void run(List<Locale> locales) {
System.out.println("Java formatter");
final Date date = new Date(System.currentTimeMillis());
locales.forEach(locale -> System.out.println(getLabel(locale, new Object[] { date, "Alice", 0 })));
locales.forEach(locale -> System.out.println(getLabel(locale, new Object[] { date, "Alice", 2 })));
}
}

View File

@ -1,18 +0,0 @@
package com.baeldung.localization;
import java.util.List;
import java.util.Locale;
import java.util.ResourceBundle;
public class Localization {
public static String getLabel(Locale locale) {
final ResourceBundle bundle = ResourceBundle.getBundle("messages", locale);
return bundle.getString("label");
}
public static void run(List<Locale> locales) {
locales.forEach(locale -> System.out.println(getLabel(locale)));
}
}

View File

@ -1,46 +0,0 @@
package com.baeldung.stream;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public class SkipLimitComparison {
public static void main(String[] args) {
skipExample();
limitExample();
limitInfiniteStreamExample();
getEvenNumbers(10, 10).stream()
.forEach(System.out::println);
}
public static void skipExample() {
Stream.of(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
.filter(i -> i % 2 == 0)
.skip(2)
.forEach(i -> System.out.print(i + " "));
}
public static void limitExample() {
Stream.of(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
.filter(i -> i % 2 == 0)
.limit(2)
.forEach(i -> System.out.print(i + " "));
}
public static void limitInfiniteStreamExample() {
Stream.iterate(0, i -> i + 1)
.filter(i -> i % 2 == 0)
.limit(10)
.forEach(System.out::println);
}
private static List<Integer> getEvenNumbers(int offset, int limit) {
return Stream.iterate(0, i -> i + 1)
.filter(i -> i % 2 == 0)
.skip(offset)
.limit(limit)
.collect(Collectors.toList());
}
}

View File

@ -1,33 +0,0 @@
package com.baeldung.uuid;
import java.nio.ByteBuffer;
import java.util.Arrays;
import java.util.UUID;
public class UuidHelper {
public static byte[] convertUUIDToBytes(UUID uuid) {
ByteBuffer bb = ByteBuffer.wrap(new byte[16]);
bb.putLong(uuid.getMostSignificantBits());
bb.putLong(uuid.getLeastSignificantBits());
return bb.array();
}
public static UUID convertBytesToUUID(byte[] bytes) {
ByteBuffer byteBuffer = ByteBuffer.wrap(bytes);
long high = byteBuffer.getLong();
long low = byteBuffer.getLong();
return new UUID(high, low);
}
public static void main(String[] args) {
UUID uuid = UUID.randomUUID();
System.out.println("Original UUID: " + uuid);
byte[] bytes = convertUUIDToBytes(uuid);
System.out.println("Converted byte array: " + Arrays.toString(bytes));
UUID uuidNew = convertBytesToUUID(bytes);
System.out.println("Converted UUID: " + uuidNew);
}
}

View File

@ -1,34 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.0">
<persistence-unit
name="com.baeldung.optionalreturntype"
transaction-type="RESOURCE_LOCAL">
<description>Persist Optional Return Type Demo</description>
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<class>com.baeldung.optionalreturntype.User</class>
<class>com.baeldung.optionalreturntype.UserOptional</class>
<!--
<class>com.baeldung.optionalreturntype.UserOptionalField</class>
-->
<exclude-unlisted-classes>true</exclude-unlisted-classes>
<properties>
<property name="javax.persistence.jdbc.driver"
value="org.h2.Driver" />
<property name="javax.persistence.jdbc.url"
value="jdbc:h2:mem:test" />
<property name="javax.persistence.jdbc.user" value="sa" />
<property name="javax.persistence.jdbc.password" value="" />
<property name="hibernate.dialect"
value="org.hibernate.dialect.H2Dialect" />
<property name="hibernate.hbm2ddl.auto" value="create-drop" />
<property name="show_sql" value="true" />
<property name="hibernate.temp.use_jdbc_metadata_defaults"
value="false" />
</properties>
</persistence-unit>
</persistence>

View File

@ -1 +0,0 @@
Main-Class: com.baeldung.jarArguments.JarExample

View File

@ -1,2 +0,0 @@
label=On {0, date, short} {1} has sent you {2, choice, 0#no messages|1#a message|2#two messages|2<{2,number,integer} messages}.
label-icu={0} has sent you {2, plural, =0 {no messages} =1 {a message} other {{2, number, integer} messages}}.

View File

@ -1,2 +0,0 @@
label={0, date, short}, {1}{2, choice, 0# ne|0<} vous a envoyé {2, choice, 0#aucun message|1#un message|2#deux messages|2<{2,number,integer} messages}.
label-icu={0} {2, plural, =0 {ne } other {}}vous a envoyé {2, plural, =0 {aucun message} =1 {un message} other {{2, number, integer} messages}}.

View File

@ -1,2 +0,0 @@
label={0, date, short} {1} ti ha inviato {2, choice, 0#nessun messagio|1#un messaggio|2#due messaggi|2<{2, number, integer} messaggi}.
label-icu={0} {2, plural, =0 {non } other {}}ti ha inviato {2, plural, =0 {nessun messaggio} =1 {un messaggio} other {{2, number, integer} messaggi}}.

View File

@ -1,2 +0,0 @@
label=W {0, date, short} {1}{2, choice, 0# nie|0<} wys\u0142a\u0142a ci {2, choice, 0#\u017Cadnych wiadomo\u015Bci|1#wiadomo\u015B\u0107|2#dwie wiadomo\u015Bci|2<{2, number, integer} wiadomo\u015Bci}.
label-icu={0} {2, plural, =0 {nie } other {}}{1, select, male {wys\u0142a\u0142} female {wys\u0142a\u0142a} other {wys\u0142a\u0142o}} ci {2, plural, =0 {\u017Cadnej wiadomo\u015Bci} =1 {wiadomo\u015B\u0107} other {{2, number, integer} wiadomo\u015Bci}}.

View File

@ -1 +0,0 @@
label=Alice has sent you a message.

View File

@ -1 +0,0 @@
label=Alice vous a envoyé un message.

View File

@ -1 +0,0 @@
label=Alice ti ha inviato un messaggio.

View File

@ -1 +0,0 @@
label=Alice wys\u0142a\u0142a ci wiadomo\u015B\u0107.

View File

@ -1,164 +0,0 @@
package com.baeldung.bifunction;
import org.junit.Test;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.function.BiFunction;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import static org.assertj.core.api.Assertions.assertThat;
public class BiFunctionalInterfacesUnitTest {
@Test
public void givenStreamValues_whenMappedToNewValues() {
List<String> mapped = Stream.of("hello", "world")
.map(word -> word + "!")
.collect(Collectors.toList());
assertThat(mapped).containsExactly("hello!", "world!");
}
@Test
public void givenStreamValues_whenReducedWithPrefixingOperation() {
String result = Stream.of("hello", "world")
.reduce("", (a, b) -> b + "-" + a);
assertThat(result).isEqualTo("world-hello-");
}
@Test
public void givenStreamValues_whenReducedWithPrefixingLambda_thenHasNoTrailingDash() {
String result = Stream.of("hello", "world")
.reduce("", (a, b) -> combineWithoutTrailingDash(a, b));
assertThat(result).isEqualTo("world-hello");
}
private String combineWithoutTrailingDash(String a, String b) {
if (a.isEmpty()) {
return b;
}
return b + "-" + a;
}
@Test
public void givenStreamValues_whenReducedWithPrefixingMethodReference_thenHasNoTrailingDash() {
String result = Stream.of("hello", "world")
.reduce("", this::combineWithoutTrailingDash);
assertThat(result).isEqualTo("world-hello");
}
@Test
public void givenTwoLists_whenCombined() {
List<String> list1 = Arrays.asList("a", "b", "c");
List<Integer> list2 = Arrays.asList(1, 2, 3);
List<String> result = new ArrayList<>();
for (int i=0; i < list1.size(); i++) {
result.add(list1.get(i) + list2.get(i));
}
assertThat(result).containsExactly("a1", "b2", "c3");
}
@Test
public void givenTwoLists_whenCombinedWithGeneralPurposeCombiner() {
List<String> list1 = Arrays.asList("a", "b", "c");
List<Integer> list2 = Arrays.asList(1, 2, 3);
List<String> result = listCombiner(list1, list2, (letter, number) -> letter + number);
assertThat(result).containsExactly("a1", "b2", "c3");
}
private static <T, U, R> List<R> listCombiner(List<T> list1,
List<U> list2,
BiFunction<T, U, R> combiner) {
List<R> result = new ArrayList<>();
for (int i = 0; i < list1.size(); i++) {
result.add(combiner.apply(list1.get(i), list2.get(i)));
}
return result;
}
@Test
public void givenTwoLists_whenComparedWithCombiningFunction() {
List<Double> list1 = Arrays.asList(1.0d, 2.1d, 3.3d);
List<Float> list2 = Arrays.asList(0.1f, 0.2f, 4f);
// algorithm to determine if the value in list1 > value in list 2
List<Boolean> result = listCombiner(list1, list2, (doubleNumber, floatNumber) -> doubleNumber > floatNumber);
assertThat(result).containsExactly(true, true, false);
}
@Test
public void givenTwoLists_whenComparedWithCombiningFunctionByMethodReference() {
List<Double> list1 = Arrays.asList(1.0d, 2.1d, 3.3d);
List<Float> list2 = Arrays.asList(0.1f, 0.2f, 4f);
// algorithm to determine if the value in list1 > value in list 2
List<Boolean> result = listCombiner(list1, list2, this::firstIsGreaterThanSecond);
assertThat(result).containsExactly(true, true, false);
}
private boolean firstIsGreaterThanSecond(Double a, Float b) {
return a > b;
}
@Test
public void givenTwoLists_whenComparedForEqualityByCombiningFunction() {
List<Float> list1 = Arrays.asList(0.1f, 0.2f, 4f);
List<Float> list2 = Arrays.asList(0.1f, 0.2f, 4f);
List<Boolean> result = listCombiner(list1, list2, (float1, float2) -> float1.equals(float2));
assertThat(result).containsExactly(true, true, true);
}
@Test
public void givenTwoLists_whenComparedForEqualityByCombiningFunctionWithMethodReference() {
List<Float> list1 = Arrays.asList(0.1f, 0.2f, 4f);
List<Float> list2 = Arrays.asList(0.1f, 0.2f, 4f);
List<Boolean> result = listCombiner(list1, list2, Float::equals);
assertThat(result).containsExactly(true, true, true);
}
@Test
public void givenTwoLists_whenComparedWithCombiningFunctionWithCompareTo() {
List<Double> list1 = Arrays.asList(1.0d, 2.1d, 3.3d);
List<Double> list2 = Arrays.asList(0.1d, 0.2d, 4d);
List<Integer> result = listCombiner(list1, list2, Double::compareTo);
assertThat(result).containsExactly(1, 1, -1);
}
/**
* Allows you to to pass in a lambda or method reference and then
* get access to the BiFunction it is meant to become
*/
private static <T, U, R> BiFunction<T, U, R> asBiFunction(BiFunction<T, U, R> function) {
return function;
}
@Test
public void givenTwoLists_whenComparedWithCombiningFunctionWithComposedBiFunction() {
List<Double> list1 = Arrays.asList(1.0d, 2.1d, 3.3d);
List<Double> list2 = Arrays.asList(0.1d, 0.2d, 4d);
List<Boolean> result = listCombiner(list1, list2,
asBiFunction(Double::compareTo)
.andThen(i -> i > 0));
assertThat(result).containsExactly(true, true, false);
}
}

View File

@ -1,21 +0,0 @@
package com.baeldung.interfaceVsAbstractClass;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
public class InterfaceVsAbstractClassUnitTest {
@Test
public void givenAbstractClass_whenValidCircleUsed_thenPass() {
CircleClass redCircle = new ChildCircleClass();
redCircle.setColor("RED");
assertTrue(redCircle.isValid());
}
@Test
public void givenInterface_whenValidCircleWithoutStateUsed_thenPass() {
ChidlCircleInterfaceImpl redCircleWithoutState = new ChidlCircleInterfaceImpl();
redCircleWithoutState.setColor("RED");
assertTrue(redCircleWithoutState.isValid());
}
}

View File

@ -1,74 +0,0 @@
package com.baeldung.localization;
import static org.junit.Assert.assertEquals;
import java.util.Locale;
import org.junit.Test;
import com.baeldung.localization.ICUFormat;
public class ICUFormatUnitTest {
@Test
public void givenInUK_whenAliceSendsNothing_thenCorrectMessage() {
assertEquals("Alice has sent you no messages.", ICUFormat.getLabel(Locale.UK, new Object[] { "Alice", "female", 0 }));
}
@Test
public void givenInUK_whenAliceSendsOneMessage_thenCorrectMessage() {
assertEquals("Alice has sent you a message.", ICUFormat.getLabel(Locale.UK, new Object[] { "Alice", "female", 1 }));
}
@Test
public void givenInUK_whenBobSendsSixMessages_thenCorrectMessage() {
assertEquals("Bob has sent you 6 messages.", ICUFormat.getLabel(Locale.UK, new Object[] { "Bob", "male", 6 }));
}
@Test
public void givenInItaly_whenAliceSendsNothing_thenCorrectMessage() {
assertEquals("Alice non ti ha inviato nessun messaggio.", ICUFormat.getLabel(Locale.ITALY, new Object[] { "Alice", "female", 0 }));
}
@Test
public void givenInItaly_whenAliceSendsOneMessage_thenCorrectMessage() {
assertEquals("Alice ti ha inviato un messaggio.", ICUFormat.getLabel(Locale.ITALY, new Object[] { "Alice", "female", 1 }));
}
@Test
public void givenInItaly_whenBobSendsSixMessages_thenCorrectMessage() {
assertEquals("Bob ti ha inviato 6 messaggi.", ICUFormat.getLabel(Locale.ITALY, new Object[] { "Bob", "male", 6 }));
}
@Test
public void givenInFrance_whenAliceSendsNothing_thenCorrectMessage() {
assertEquals("Alice ne vous a envoyé aucun message.", ICUFormat.getLabel(Locale.FRANCE, new Object[] { "Alice", "female", 0 }));
}
@Test
public void givenInFrance_whenAliceSendsOneMessage_thenCorrectMessage() {
assertEquals("Alice vous a envoyé un message.", ICUFormat.getLabel(Locale.FRANCE, new Object[] { "Alice", "female", 1 }));
}
@Test
public void givenInFrance_whenBobSendsSixMessages_thenCorrectMessage() {
assertEquals("Bob vous a envoyé 6 messages.", ICUFormat.getLabel(Locale.FRANCE, new Object[] { "Bob", "male", 6 }));
}
@Test
public void givenInPoland_whenAliceSendsNothing_thenCorrectMessage() {
assertEquals("Alice nie wysłała ci żadnej wiadomości.", ICUFormat.getLabel(Locale.forLanguageTag("pl-PL"), new Object[] { "Alice", "female", 0 }));
}
@Test
public void givenInPoland_whenAliceSendsOneMessage_thenCorrectMessage() {
assertEquals("Alice wysłała ci wiadomość.", ICUFormat.getLabel(Locale.forLanguageTag("pl-PL"), new Object[] { "Alice", "female", 1 }));
}
@Test
public void givenInPoland_whenBobSendsSixMessages_thenCorrectMessage() {
assertEquals("Bob wysłał ci 6 wiadomości.", ICUFormat.getLabel(Locale.forLanguageTag("pl-PL"), new Object[] { "Bob", "male", 6 }));
}
}

View File

@ -18,4 +18,7 @@
- [Interface With Default Methods vs Abstract Class](https://www.baeldung.com/java-interface-default-method-vs-abstract-class)
- [Convert Between Byte Array and UUID in Java](https://www.baeldung.com/java-byte-array-to-uuid)
- [Create a Simple “Rock-Paper-Scissors” Game in Java](https://www.baeldung.com/java-rock-paper-scissors)
- [VarArgs vs Array Input Parameters in Java](https://www.baeldung.com/varargs-vs-array)
- [Lambda Expression vs. Anonymous Inner Class](https://www.baeldung.com/java-lambdas-vs-anonymous-class)
- [Java Helper vs. Utility Classes](https://www.baeldung.com/java-helper-vs-utility-classes)
- [Java 8 开始新增的 Optional 类](https://www.ossez.com/t/java-8-optional/13964)

View File

@ -1,4 +1,4 @@
package com.baeldung.anonymousclass;
package com.ossez.anonymousclass;
public class AnonymousClassExample{

View File

@ -1,4 +1,4 @@
package com.baeldung.argsVsvarargs;
package com.ossez.argsVsvarargs;
public class StringArrayAndVarargs {
public static void capitalizeNames(String[] args) {

View File

@ -1,4 +1,4 @@
package com.baeldung.helpervsutilityclasses;
package com.ossez.helpervsutilityclasses;
class MyHelperClass {
public double discount;

View File

@ -1,4 +1,4 @@
package com.baeldung.helpervsutilityclasses;
package com.ossez.helpervsutilityclasses;
public final class MyUtilityClass {

View File

@ -1,4 +1,4 @@
package com.baeldung.lambdaexpression;
package com.ossez.lambdaexpression;
public class LambdaExpressionExample{

View File

@ -5,6 +5,7 @@ import java.util.List;
import java.util.Locale;
public class App {
/**
* Runs all available formatter
*

View File

@ -1,7 +1,7 @@
package com.baeldung.argsVsvarargs;
package com.ossez.argsVsvarargs;
import static com.baeldung.argsVsvarargs.StringArrayAndVarargs.capitalizeNames;
import static com.baeldung.argsVsvarargs.StringArrayAndVarargs.firstLetterOfWords;
import static com.ossez.argsVsvarargs.StringArrayAndVarargs.capitalizeNames;
import static com.ossez.argsVsvarargs.StringArrayAndVarargs.firstLetterOfWords;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;

View File

@ -4,7 +4,6 @@ import org.junit.Test;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.function.BiFunction;
import java.util.stream.Collectors;
@ -71,7 +70,7 @@ public class BiFunctionalInterfacesUnitTest {
List<String> list1 = Arrays.asList("a", "b", "c");
List<Integer> list2 = Arrays.asList(1, 2, 3);
List<String> result = listCombiner(list1, list2, (a, b) -> a + b);
List<String> result = listCombiner(list1, list2, (letter, number) -> letter + number);
assertThat(result).containsExactly("a1", "b2", "c3");
}
@ -92,7 +91,7 @@ public class BiFunctionalInterfacesUnitTest {
List<Float> list2 = Arrays.asList(0.1f, 0.2f, 4f);
// algorithm to determine if the value in list1 > value in list 2
List<Boolean> result = listCombiner(list1, list2, (a, b) -> a > b);
List<Boolean> result = listCombiner(list1, list2, (doubleNumber, floatNumber) -> doubleNumber > floatNumber);
assertThat(result).containsExactly(true, true, false);
}
@ -117,7 +116,7 @@ public class BiFunctionalInterfacesUnitTest {
List<Float> list1 = Arrays.asList(0.1f, 0.2f, 4f);
List<Float> list2 = Arrays.asList(0.1f, 0.2f, 4f);
List<Boolean> result = listCombiner(list1, list2, (a, b) -> a.equals(b));
List<Boolean> result = listCombiner(list1, list2, (float1, float2) -> float1.equals(float2));
assertThat(result).containsExactly(true, true, true);
}

View File

@ -1,4 +1,4 @@
package com.baeldung.helpervsutilityclasses;
package com.ossez.helpervsutilityclasses;
import static org.junit.jupiter.api.Assertions.*;

View File

@ -1,4 +1,4 @@
package com.baeldung.helpervsutilityclasses;
package com.ossez.helpervsutilityclasses;
import static org.junit.jupiter.api.Assertions.*;

View File

@ -6,6 +6,8 @@ import java.util.Locale;
import org.junit.Test;
import com.ossez.localization.ICUFormat;
public class ICUFormatUnitTest {
@Test

View File

@ -8,9 +8,9 @@
<name>core-java-collections-list-2</name>
<parent>
<groupId>com.baeldung.core-java-modules</groupId>
<groupId>com.ossez.core-java-modules</groupId>
<artifactId>core-java-modules</artifactId>
<version>0.0.1-SNAPSHOT</version>
<version>0.0.2-SNAPSHOT</version>
</parent>
<dependencies>

View File

@ -8,9 +8,9 @@
<name>core-java-numbers</name>
<parent>
<groupId>com.baeldung.core-java-modules</groupId>
<groupId>com.ossez.core-java-modules</groupId>
<artifactId>core-java-modules</artifactId>
<version>0.0.1-SNAPSHOT</version>
<version>0.0.2-SNAPSHOT</version>
</parent>
<dependencies>

View File

@ -42,7 +42,7 @@
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${version.guava}</version>
<version>${guava.version}</version>
</dependency>
</dependencies>

View File

@ -7,7 +7,7 @@
<name>spring-data-jpa-repo</name>
<parent>
<groupId>com.baeldung</groupId>
<groupId>com.ossez</groupId>
<artifactId>parent-boot-3</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../../parent-boot-3</relativePath>

View File

@ -77,7 +77,7 @@
<maven-war-plugin.version>3.0.0</maven-war-plugin.version>
<!-- UTILS -->
<version.guava>31.1-jre</version.guava>
<guava.version>31.1-jre</guava.version>
<lombok.version>1.18.28</lombok.version>
<joda-time.version>2.12.5</joda-time.version>
<colt.version>1.2.0</colt.version>