diff --git a/simple-algorithms/biggest-price/build.gradle b/simple-algorithms/biggest-price/build.gradle index 5584480..9f5b988 100644 --- a/simple-algorithms/biggest-price/build.gradle +++ b/simple-algorithms/biggest-price/build.gradle @@ -2,7 +2,7 @@ plugins { id 'java' } -def junitJupiterVersion = '5.7.0' +def junitJupiterVersion = '5.10.2' group 'com.josdem.kata' version '1.0-SNAPSHOT' diff --git a/simple-algorithms/biggest-price/gradle/wrapper/gradle-wrapper.properties b/simple-algorithms/biggest-price/gradle/wrapper/gradle-wrapper.properties index aa991fc..a595206 100644 --- a/simple-algorithms/biggest-price/gradle/wrapper/gradle-wrapper.properties +++ b/simple-algorithms/biggest-price/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/simple-algorithms/biggest-price/src/main/java/com/josdem/kata/BiggestNumberFinder.java b/simple-algorithms/biggest-price/src/main/java/com/josdem/kata/BiggestNumberFinder.java index 2586a8a..e2f3148 100644 --- a/simple-algorithms/biggest-price/src/main/java/com/josdem/kata/BiggestNumberFinder.java +++ b/simple-algorithms/biggest-price/src/main/java/com/josdem/kata/BiggestNumberFinder.java @@ -1,23 +1,12 @@ package com.josdem.kata; -/* -Messages with random data are coming! But we just care about prices! -Your task is to implement a function which removes all non numeric data and return just the biggest price -messages = ["hi", "2", "@#$%", "32"] -result = 32 -*/ - import java.util.List; +import java.util.Optional; public class BiggestNumberFinder { - - private String regex = "-?[0-9]+.?[0-9]+"; - - public double find(List numbers) { - return numbers.stream() - .filter(it -> it.matches(regex)) - .map(it -> Double.parseDouble(it)) - .max(Double::compare) - .get(); - } + private static final String REGEX = "-?[0-9]+.?[0-9]+"; + public double find(List numbers) { + Optional result = numbers.stream().filter(it -> it.matches(REGEX)).map(Double::parseDouble).max(Double::compare); + return result.orElseThrow(RuntimeException::new); + } } diff --git a/simple-algorithms/biggest-price/src/test/java/com/josdem/kata/BiggestNumberFinderTest.java b/simple-algorithms/biggest-price/src/test/java/com/josdem/kata/BiggestNumberFinderTest.java index 5e89ace..faea302 100644 --- a/simple-algorithms/biggest-price/src/test/java/com/josdem/kata/BiggestNumberFinderTest.java +++ b/simple-algorithms/biggest-price/src/test/java/com/josdem/kata/BiggestNumberFinderTest.java @@ -6,9 +6,16 @@ import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; +/* +Messages with random data are coming! But we just care about prices! +Your task is to implement a function which removes all non-numeric data and return just the biggest price +messages = ["hi", "2", "@#$%", "32"] +result = 32 +*/ + class BiggestNumberFinderTest { - private BiggestNumberFinder biggestNumberFinder = new BiggestNumberFinder(); + private final BiggestNumberFinder biggestNumberFinder = new BiggestNumberFinder(); @Test @DisplayName("Find biggest")