diff --git a/lesson_07/conditionals/src/lesson7.ts b/lesson_07/conditionals/src/lesson7.ts deleted file mode 100644 index 52f45df8b..000000000 --- a/lesson_07/conditionals/src/lesson7.ts +++ /dev/null @@ -1,102 +0,0 @@ -import { computeLexicographicDistance } from "./util.js"; - -/** - * Returns true if the provided age meets the minimum US voting age and false otherwise. - * - * @param age The age to check. - * @return True if the age corresponds to a voting age and false otherwise. - */ -export function canVote(age: number): boolean { - return false; -} - -/** - * Compares two strings lexicographically. - * - * @param a The first `string` to compare. - * @param b The second `string` to compare. - * @return -1 if a is less than b, 1 if a is greater than b, and 0 otherwise. - */ -export function compareStrings(a: string, b: string): number { - // The distance will be a number less than 0 if string `a` is lexicographically less than `b`, 1 - // if it is greater, and 0 if the strings are equal. - const distance = computeLexicographicDistance(a, b); - - // TODO(you): Finish this method. - - return 0; -} - -/** - * Converts a GPA on the 4.0 scale to the corresponding letter grade using the college board - * scale. See - * https://bigfuture.collegeboard.org/plan-for-college/college-basics/how-to-convert-gpa-4.0-scale - * for details. - * - * @param gpa The GPA value. - * @return The letter grade ("A+", "A", "A-", "B+", etc.). - */ -export function convertGpaToLetterGrade(gpa: number): string { - return "F"; -} - -/** - * Computes the factorial of the given value of `n`. - * - * @param n The value for which to compute the factorial. - * @return The factorial of n. - */ -export function computeFactorial(n: number): number { - return 0; -} - -/** - * Adds all of the provided values and returns the sum. - * - * @param values The values to sum. - * @return The sum of all the values. - */ -export function addNumbers(values: number[]): number { - return 0; -} - -/** - * Returns an array of the first `n` Fibonacci numbers starting from 1. - * - * @param n The first `n` of Fibonacci values to compute. - * @return An array containing the first `n` Fibonacci values. - */ -export function getFirstNFibonacciNumbers(n: number): number[] { - return []; -} - -/** - * Finds a value in an array of values. - * - * @param values The values to search. - * @param start The left most index to search. - * @param end The right most index to search. - * @param value The value to look for. - * @return The index of the value if found in the array and -1 otherwise. - */ -export function binarySearch( - values: number[], - start: number, - end: number, - value: number, -): number { - if (end < start) { - // The range is not valid so just return -1. - return -1; - } - - const pivotIndex = Math.floor((start + end) / 2); // The index in the middle of the array. - - // TODO(you): Finish implementing this algorithm - - // If values[pivotIndex] is equal to value then return `pivotIndex`. - // Else if values[pivotIndex] is greater than the value, then - // call `binarySearch(values, start, pivotIndex - 1, value)` and return its value; - // Else call `binarySearch(values, pivotIndex + 1, end, value)` and return its value. - return -1; -} diff --git a/lesson_09/types/types_app/src/main/java/com/codedifferently/lesson9/dataprovider/AnthonyMaysProvider.java b/lesson_09/types/types_app/src/main/java/com/codedifferently/lesson9/dataprovider/AnthonyMaysProvider.java deleted file mode 100644 index 437665660..000000000 --- a/lesson_09/types/types_app/src/main/java/com/codedifferently/lesson9/dataprovider/AnthonyMaysProvider.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.codedifferently.lesson9.dataprovider; - -import java.util.Map; -import org.springframework.stereotype.Service; - -@Service -public class AnthonyMaysProvider extends DataProvider { - public String getProviderName() { - return "anthonymays"; - } - - public Map getColumnTypeByName() { - return Map.of( - "column1", Integer.class, - "column2", String.class, - "column3", Boolean.class, - "column4", Float.class, - "column5", Double.class, - "column6", Long.class, - "column7", Short.class); - } -} diff --git a/lesson_09/types/types_app/src/main/java/com/codedifferently/lesson9/dataprovider/DataProvider.java b/lesson_09/types/types_app/src/main/java/com/codedifferently/lesson9/dataprovider/DataProvider.java index 595357609..f7dc65528 100644 --- a/lesson_09/types/types_app/src/main/java/com/codedifferently/lesson9/dataprovider/DataProvider.java +++ b/lesson_09/types/types_app/src/main/java/com/codedifferently/lesson9/dataprovider/DataProvider.java @@ -1,51 +1,5 @@ package com.codedifferently.lesson9.dataprovider; -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; +public class DataProvider { -/** - * This class is a base class for data providers. It provides a method for parsing data from a list - * of maps. - */ -public abstract class DataProvider { - /** Returns the name of the provider. */ - public abstract String getProviderName(); - - /** Gets a map of column types keyed by column name. */ - public abstract Map getColumnTypeByName(); - - /** - * Given a list of data objects, returns the list with values converted to the appropriate type. - * - * @param data A list of data objects containing values keyed by column name. - * @return A new list with object values converted to the appropriate type. - */ - public List> parseData(List> data) throws Exception { - Map columnTypeByName = getColumnTypeByName(); - return data.stream().map(row -> parseRow(columnTypeByName, row)).collect(Collectors.toList()); - } - - /** - * Parses a single row of data using the provided column types mapping. - * - * @param columnTypeByName A map containing the type of a column keyed by its name. - * @param row A bag of values keyed by column name. - * @return A new list of data values converted to the appropriate type. - */ - private Map parseRow( - Map columnTypeByName, Map row) { - var parsedRow = new java.util.HashMap(); - row.forEach( - (key, value) -> { - Class type = columnTypeByName.get(key); - try { - parsedRow.put(key, type.getConstructor(String.class).newInstance(value)); - } catch (Exception e) { - throw new RuntimeException( - "Error parsing data for " + key + " as type " + type.getName()); - } - }); - return parsedRow; - } } diff --git a/lesson_09/types/types_app/src/main/java/com/codedifferently/lesson9/dataprovider/NileJackProvider.java b/lesson_09/types/types_app/src/main/java/com/codedifferently/lesson9/dataprovider/NileJackProvider.java new file mode 100644 index 000000000..a5bd8b0c8 --- /dev/null +++ b/lesson_09/types/types_app/src/main/java/com/codedifferently/lesson9/dataprovider/NileJackProvider.java @@ -0,0 +1,24 @@ +package com.codedifferently.lesson9.dataprovider; + +import java.util.Map; + +import org.springframework.stereotype.Service; + +@Service +public class NileJackProvider extends DataProvider { + public String getProviderName() { + return "nilejack"; + } + + @SuppressWarnings("rawtypes") + public Map getColumnTypeByName() { + return Map.of( + "column1", Float.class, + "column2", Integer.class, + "column3", Short.class, + "column4", String.class, + "column5", Boolean.class, + "column6", Double.class, + "column7", Long.class); + } +} diff --git a/lesson_09/types/types_app/src/main/java/com/codedifferently/lesson9/dataprovider/NileJacksonProvider.java b/lesson_09/types/types_app/src/main/java/com/codedifferently/lesson9/dataprovider/NileJacksonProvider.java new file mode 100644 index 000000000..fe24b0d4a --- /dev/null +++ b/lesson_09/types/types_app/src/main/java/com/codedifferently/lesson9/dataprovider/NileJacksonProvider.java @@ -0,0 +1,23 @@ +package com.codedifferently.lesson9.dataprovider; + +import java.util.Map; + +import org.springframework.stereotype.Service; + +@Service +public class NileJackProvider extends DataProvider { + public String getProviderName() { + return "nilejack"; + } + + public Map getColumnTypeByName() { + return Map.of( + "column1", Float.class, + "column2", Integer.class, + "column3", Short.class, + "column4", String.class, + "column5", Boolean.class, + "column6", Double.class, + "column7", Long.class); + } +} \ No newline at end of file diff --git a/lesson_09/types/types_app/src/main/resources/data/nilejack.json b/lesson_09/types/types_app/src/main/resources/data/nilejack.json new file mode 100644 index 000000000..03fa75333 --- /dev/null +++ b/lesson_09/types/types_app/src/main/resources/data/nilejack.json @@ -0,0 +1,92 @@ +[ + { + "column1": "2.788476E38", + "column2": "23906", + "column3": "1.951334947469109E306", + "column4": "4vynlcbme89", + "column5": "true", + "column6": "1946511983", + "column7": "871716420668780160" + }, + { + "column1": "2.9218724E38", + "column2": "5982", + "column3": "1.6613559878792952E308", + "column4": "kcy91i4", + "column5": "true", + "column6": "467285300", + "column7": "717033365520104960" + }, + { + "column1": "2.6791138E38", + "column2": "3087", + "column3": "1.4531283019824207E307", + "column4": "5gdku", + "column5": "false", + "column6": "1339783318", + "column7": "8609205761188083712" + }, + { + "column1": "2.7654423E38", + "column2": "22857", + "column3": "1.3125501238039668E308", + "column4": "2ab3nxz", + "column5": "false", + "column6": "1166125928", + "column7": "3850529467803900928" + }, + { + "column1": "7.978512E37", + "column2": "30614", + "column3": "1.0016443609479493E308", + "column4": "jh490kp25z8", + "column5": "true", + "column6": "684136174", + "column7": "2530680619863128064" + }, + { + "column1": "5.8039073E37", + "column2": "4886", + "column3": "1.3705152061964327E308", + "column4": "ak5we9tfr", + "column5": "false", + "column6": "728654337", + "column7": "1671706500207470592" + }, + { + "column1": "5.139036E37", + "column2": "9019", + "column3": "1.2523590249164425E308", + "column4": "5tefqwblim3", + "column5": "true", + "column6": "14150416", + "column7": "4871306662885839872" + }, + { + "column1": "2.6188858E37", + "column2": "2398", + "column3": "1.444754024326182E308", + "column4": "w8hfk7nl1s", + "column5": "false", + "column6": "2000776131", + "column7": "8280646876683382784" + }, + { + "column1": "3.1079513E38", + "column2": "32074", + "column3": "9.799167831142151E307", + "column4": "glx5ze96mk", + "column5": "false", + "column6": "2134631706", + "column7": "3840235999993978368" + }, + { + "column1": "1.1965353E38", + "column2": "30848", + "column3": "1.0643709914035035E308", + "column4": "s51gxi7hm3", + "column5": "false", + "column6": "1598587760", + "column7": "8883551926143157248" + } +] \ No newline at end of file diff --git a/lesson_09/types/types_app/src/test/java/com/codedifferently/lesson9/Lesson9Test.java b/lesson_09/types/types_app/src/test/java/com/codedifferently/lesson9/Lesson9Test.java index 397136446..0083c4ae1 100644 --- a/lesson_09/types/types_app/src/test/java/com/codedifferently/lesson9/Lesson9Test.java +++ b/lesson_09/types/types_app/src/test/java/com/codedifferently/lesson9/Lesson9Test.java @@ -1,14 +1,12 @@ package com.codedifferently.lesson9; -import static org.assertj.core.api.Assertions.assertThat; - -import com.codedifferently.lesson9.dataprovider.DataProvider; -import com.codedifferently.lesson9.loader.DataFileLoader; import java.io.IOException; import java.util.List; import java.util.Map; import java.util.Set; import java.util.stream.Collectors; + +import static org.assertj.core.api.Assertions.assertThat; import org.assertj.core.api.junit.jupiter.SoftAssertionsExtension; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -16,6 +14,9 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.ContextConfiguration; +import com.codedifferently.lesson9.dataprovider.DataProvider; +import com.codedifferently.lesson9.loader.DataFileLoader; + @SpringBootTest @ContextConfiguration(classes = Lesson9.class) @ExtendWith(SoftAssertionsExtension.class)