maven fix and small formatting work
This commit is contained in:
parent
b4ac6c6ec5
commit
d66d9fb2c0
@ -106,6 +106,13 @@
|
||||
|
||||
<!-- test scoped -->
|
||||
|
||||
<dependency>
|
||||
<groupId>org.hamcrest</groupId>
|
||||
<artifactId>hamcrest-all</artifactId>
|
||||
<version>1.3</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
@ -254,8 +261,7 @@
|
||||
<configuration>
|
||||
<shadedArtifactAttached>true</shadedArtifactAttached>
|
||||
<transformers>
|
||||
<transformer
|
||||
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
|
||||
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
|
||||
<mainClass>org.baeldung.executable.ExecutableMavenJar</mainClass>
|
||||
</transformer>
|
||||
</transformers>
|
||||
|
@ -5,8 +5,7 @@ public class SimulatedAnnealing {
|
||||
private static Travel travel = new Travel(10);
|
||||
|
||||
public static double simulateAnnealing(double startingTemperature, int numberOfIterations, double coolingRate) {
|
||||
System.out.println("Starting SA with temperature: " + startingTemperature + ", # of iterations: "
|
||||
+ numberOfIterations + " and colling rate: " + coolingRate);
|
||||
System.out.println("Starting SA with temperature: " + startingTemperature + ", # of iterations: " + numberOfIterations + " and colling rate: " + coolingRate);
|
||||
double t = startingTemperature;
|
||||
travel.generateInitialTravel();
|
||||
double bestDistance = travel.getDistance();
|
||||
|
@ -22,7 +22,6 @@ public class EncoderDecoderUnitTest {
|
||||
private static final String testUrl = "http://www.baeldung.com?key1=value+1&key2=value%40%21%242&key3=value%253";
|
||||
private static final String testUrlWithPath = "http://www.baeldung.com/path+1?key1=value+1&key2=value%40%21%242&key3=value%253";
|
||||
|
||||
|
||||
private String encodeValue(String value) {
|
||||
String encoded = null;
|
||||
try {
|
||||
@ -59,9 +58,7 @@ public class EncoderDecoderUnitTest {
|
||||
requestParams.put("key2", "value@!$2");
|
||||
requestParams.put("key3", "value%3");
|
||||
|
||||
String encodedURL = requestParams.keySet().stream()
|
||||
.map(key -> key + "=" + encodeValue(requestParams.get(key)))
|
||||
.collect(joining("&", "http://www.baeldung.com?", ""));
|
||||
String encodedURL = requestParams.keySet().stream().map(key -> key + "=" + encodeValue(requestParams.get(key))).collect(joining("&", "http://www.baeldung.com?", ""));
|
||||
|
||||
Assert.assertThat(testUrl, is(encodedURL));
|
||||
}
|
||||
@ -103,12 +100,9 @@ public class EncoderDecoderUnitTest {
|
||||
|
||||
String path = "path+1";
|
||||
|
||||
String encodedURL = requestParams.keySet().stream()
|
||||
.map(key -> key + "=" + encodeValue(requestParams.get(key)))
|
||||
.collect(joining("&", "http://www.baeldung.com/" + encodePath(path) + "?", ""));
|
||||
String encodedURL = requestParams.keySet().stream().map(key -> key + "=" + encodeValue(requestParams.get(key))).collect(joining("&", "http://www.baeldung.com/" + encodePath(path) + "?", ""));
|
||||
|
||||
Assert.assertThat(testUrlWithPath, is(encodedURL));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -17,9 +17,7 @@ public class Java8CollectionCleanupUnitTest {
|
||||
@Test
|
||||
public void givenListContainsNulls_whenFilteringParallel_thenCorrect() {
|
||||
final List<Integer> list = Lists.newArrayList(null, 1, 2, null, 3, null);
|
||||
final List<Integer> listWithoutNulls = list.parallelStream()
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.toList());
|
||||
final List<Integer> listWithoutNulls = list.parallelStream().filter(Objects::nonNull).collect(Collectors.toList());
|
||||
|
||||
assertThat(listWithoutNulls, hasSize(3));
|
||||
}
|
||||
@ -27,9 +25,7 @@ public class Java8CollectionCleanupUnitTest {
|
||||
@Test
|
||||
public void givenListContainsNulls_whenFilteringSerial_thenCorrect() {
|
||||
final List<Integer> list = Lists.newArrayList(null, 1, 2, null, 3, null);
|
||||
final List<Integer> listWithoutNulls = list.stream()
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.toList());
|
||||
final List<Integer> listWithoutNulls = list.stream().filter(Objects::nonNull).collect(Collectors.toList());
|
||||
|
||||
assertThat(listWithoutNulls, hasSize(3));
|
||||
}
|
||||
@ -45,9 +41,7 @@ public class Java8CollectionCleanupUnitTest {
|
||||
@Test
|
||||
public void givenListContainsDuplicates_whenRemovingDuplicatesWithJava8_thenCorrect() {
|
||||
final List<Integer> listWithDuplicates = Lists.newArrayList(1, 1, 2, 2, 3, 3);
|
||||
final List<Integer> listWithoutDuplicates = listWithDuplicates.parallelStream()
|
||||
.distinct()
|
||||
.collect(Collectors.toList());
|
||||
final List<Integer> listWithoutDuplicates = listWithDuplicates.parallelStream().distinct().collect(Collectors.toList());
|
||||
|
||||
assertThat(listWithoutDuplicates, hasSize(3));
|
||||
}
|
||||
|
@ -93,6 +93,7 @@ public class OptionalTest {
|
||||
boolean is2017 = yearOptional.filter(y -> y == 2017).isPresent();
|
||||
assertFalse(is2017);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenFiltersWithoutOptional_thenCorrect() {
|
||||
assertTrue(priceIsInRange1(new Modem(10.0)));
|
||||
@ -121,12 +122,9 @@ public class OptionalTest {
|
||||
}
|
||||
|
||||
public boolean priceIsInRange2(Modem modem2) {
|
||||
return Optional.ofNullable(modem2)
|
||||
.map(Modem::getPrice)
|
||||
.filter(p -> p >= 10)
|
||||
.filter(p -> p <= 15)
|
||||
.isPresent();
|
||||
return Optional.ofNullable(modem2).map(Modem::getPrice).filter(p -> p >= 10).filter(p -> p <= 15).isPresent();
|
||||
}
|
||||
|
||||
// Transforming Value With map()
|
||||
@Test
|
||||
public void givenOptional_whenMapWorks_thenCorrect() {
|
||||
|
@ -38,20 +38,17 @@ public class GrepWithUnix4JTest {
|
||||
int expectedLineCount = 178687;
|
||||
|
||||
// grep -v "NINETEEN" dictionary.txt
|
||||
List<Line> lines = grep(Options.v, "NINETEEN", fileToGrep).
|
||||
toLineList();
|
||||
List<Line> lines = grep(Options.v, "NINETEEN", fileToGrep).toLineList();
|
||||
|
||||
assertEquals(expectedLineCount, lines.size());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void whenGrepWithRegex_thenCorrect() {
|
||||
int expectedLineCount = 151;
|
||||
|
||||
// grep -c ".*?NINE.*?" dictionary.txt
|
||||
String patternCount = grep(Options.c, ".*?NINE.*?", fileToGrep).
|
||||
cut(fields, ":", 1).toStringResult();
|
||||
String patternCount = grep(Options.c, ".*?NINE.*?", fileToGrep).cut(fields, ":", 1).toStringResult();
|
||||
|
||||
assertEquals(expectedLineCount, Integer.parseInt(patternCount));
|
||||
}
|
||||
|
@ -15,8 +15,7 @@ public class JoinSplitCollectionsUnitTest {
|
||||
public void whenJoiningTwoArrays_thenJoined() {
|
||||
String[] animals1 = new String[] { "Dog", "Cat" };
|
||||
String[] animals2 = new String[] { "Bird", "Cow" };
|
||||
String[] result = Stream.concat(
|
||||
Arrays.stream(animals1), Arrays.stream(animals2)).toArray(String[]::new);
|
||||
String[] result = Stream.concat(Arrays.stream(animals1), Arrays.stream(animals2)).toArray(String[]::new);
|
||||
|
||||
assertArrayEquals(result, new String[] { "Dog", "Cat", "Bird", "Cow" });
|
||||
}
|
||||
@ -25,9 +24,7 @@ public class JoinSplitCollectionsUnitTest {
|
||||
public void whenJoiningTwoCollections_thenJoined() {
|
||||
Collection<String> collection1 = Arrays.asList("Dog", "Cat");
|
||||
Collection<String> collection2 = Arrays.asList("Bird", "Cow", "Moose");
|
||||
Collection<String> result = Stream.concat(
|
||||
collection1.stream(), collection2.stream())
|
||||
.collect(Collectors.toList());
|
||||
Collection<String> result = Stream.concat(collection1.stream(), collection2.stream()).collect(Collectors.toList());
|
||||
|
||||
assertTrue(result.equals(Arrays.asList("Dog", "Cat", "Bird", "Cow", "Moose")));
|
||||
}
|
||||
@ -36,10 +33,7 @@ public class JoinSplitCollectionsUnitTest {
|
||||
public void whenJoiningTwoCollectionsWithFilter_thenJoined() {
|
||||
Collection<String> collection1 = Arrays.asList("Dog", "Cat");
|
||||
Collection<String> collection2 = Arrays.asList("Bird", "Cow", "Moose");
|
||||
Collection<String> result = Stream.concat(
|
||||
collection1.stream(), collection2.stream())
|
||||
.filter(e -> e.length() == 3)
|
||||
.collect(Collectors.toList());
|
||||
Collection<String> result = Stream.concat(collection1.stream(), collection2.stream()).filter(e -> e.length() == 3).collect(Collectors.toList());
|
||||
|
||||
assertTrue(result.equals(Arrays.asList("Dog", "Cat", "Cow")));
|
||||
}
|
||||
@ -67,9 +61,7 @@ public class JoinSplitCollectionsUnitTest {
|
||||
animals.put(2, "Cat");
|
||||
animals.put(3, "Cow");
|
||||
|
||||
String result = animals.entrySet().stream()
|
||||
.map(entry -> entry.getKey() + " = " + entry.getValue())
|
||||
.collect(Collectors.joining(", "));
|
||||
String result = animals.entrySet().stream().map(entry -> entry.getKey() + " = " + entry.getValue()).collect(Collectors.joining(", "));
|
||||
|
||||
assertEquals(result, "1 = Dog, 2 = Cat, 3 = Cow");
|
||||
}
|
||||
@ -80,10 +72,7 @@ public class JoinSplitCollectionsUnitTest {
|
||||
nested.add(Arrays.asList("Dog", "Cat"));
|
||||
nested.add(Arrays.asList("Cow", "Pig"));
|
||||
|
||||
String result = nested.stream().map(
|
||||
nextList -> nextList.stream()
|
||||
.collect(Collectors.joining("-")))
|
||||
.collect(Collectors.joining("; "));
|
||||
String result = nested.stream().map(nextList -> nextList.stream().collect(Collectors.joining("-"))).collect(Collectors.joining("; "));
|
||||
|
||||
assertEquals(result, "Dog-Cat; Cow-Pig");
|
||||
}
|
||||
@ -91,17 +80,14 @@ public class JoinSplitCollectionsUnitTest {
|
||||
@Test
|
||||
public void whenConvertCollectionToStringAndSkipNull_thenConverted() {
|
||||
Collection<String> animals = Arrays.asList("Dog", "Cat", null, "Moose");
|
||||
String result = animals.stream()
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.joining(", "));
|
||||
String result = animals.stream().filter(Objects::nonNull).collect(Collectors.joining(", "));
|
||||
|
||||
assertEquals(result, "Dog, Cat, Moose");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSplitCollectionHalf_thenConverted() {
|
||||
Collection<String> animals = Arrays.asList(
|
||||
"Dog", "Cat", "Cow", "Bird", "Moose", "Pig");
|
||||
Collection<String> animals = Arrays.asList("Dog", "Cat", "Cow", "Bird", "Moose", "Pig");
|
||||
Collection<String> result1 = new ArrayList<>();
|
||||
Collection<String> result2 = new ArrayList<>();
|
||||
AtomicInteger count = new AtomicInteger();
|
||||
@ -123,8 +109,7 @@ public class JoinSplitCollectionsUnitTest {
|
||||
@Test
|
||||
public void whenSplitArrayByWordLength_thenConverted() {
|
||||
String[] animals = new String[] { "Dog", "Cat", "Bird", "Cow", "Pig", "Moose" };
|
||||
Map<Integer, List<String>> result = Arrays.stream(animals)
|
||||
.collect(Collectors.groupingBy(String::length));
|
||||
Map<Integer, List<String>> result = Arrays.stream(animals).collect(Collectors.groupingBy(String::length));
|
||||
|
||||
assertTrue(result.get(3).equals(Arrays.asList("Dog", "Cat", "Cow", "Pig")));
|
||||
assertTrue(result.get(4).equals(Arrays.asList("Bird")));
|
||||
@ -151,9 +136,7 @@ public class JoinSplitCollectionsUnitTest {
|
||||
public void whenConvertStringToMap_thenConverted() {
|
||||
String animals = "1 = Dog, 2 = Cat, 3 = Bird";
|
||||
|
||||
Map<Integer, String> result = Arrays.stream(
|
||||
animals.split(", ")).map(next -> next.split(" = "))
|
||||
.collect(Collectors.toMap(entry -> Integer.parseInt(entry[0]), entry -> entry[1]));
|
||||
Map<Integer, String> result = Arrays.stream(animals.split(", ")).map(next -> next.split(" = ")).collect(Collectors.toMap(entry -> Integer.parseInt(entry[0]), entry -> entry[1]));
|
||||
|
||||
assertEquals(result.get(1), "Dog");
|
||||
assertEquals(result.get(2), "Cat");
|
||||
@ -164,10 +147,7 @@ public class JoinSplitCollectionsUnitTest {
|
||||
public void whenConvertCollectionToStringMultipleSeparators_thenConverted() {
|
||||
String animals = "Dog. , Cat, Bird. Cow";
|
||||
|
||||
Collection<String> result = Arrays.stream(animals.split("[,|.]"))
|
||||
.map(String::trim)
|
||||
.filter(next -> !next.isEmpty())
|
||||
.collect(Collectors.toList());
|
||||
Collection<String> result = Arrays.stream(animals.split("[,|.]")).map(String::trim).filter(next -> !next.isEmpty()).collect(Collectors.toList());
|
||||
|
||||
assertTrue(result.equals(Arrays.asList("Dog", "Cat", "Bird", "Cow")));
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user