diff --git "a/\303\274bung1/.gitignore" "b/\303\274bung1/.gitignore" new file mode 100644 index 0000000000000000000000000000000000000000..5d99afea1020e5ed04c763f13de154c1deb3c212 --- /dev/null +++ "b/\303\274bung1/.gitignore" @@ -0,0 +1,6 @@ +target +target/ +target/* +target/** +.idea +*.iml diff --git "a/\303\274bung1/pom.xml" "b/\303\274bung1/pom.xml" index 664f1fb12e2dde3760058edcbe5d7017dd17de3d..c6c6bc73ede14c0b10890e2541f1dc379552fcbb 100644 --- "a/\303\274bung1/pom.xml" +++ "b/\303\274bung1/pom.xml" @@ -29,6 +29,21 @@ <version>5.6.1</version> <scope>test</scope> </dependency> + <dependency> + <groupId>com.opencsv</groupId> + <artifactId>opencsv</artifactId> + <version>5.1</version> + </dependency> + <dependency> + <groupId>com.fasterxml.jackson.core</groupId> + <artifactId>jackson-databind</artifactId> + <version>2.10.3</version> + </dependency> + <dependency> + <groupId>com.voodoodyne.jackson.jsog</groupId> + <artifactId>jackson-jsog</artifactId> + <version>1.1.1</version> + </dependency> </dependencies> <build> <plugins> @@ -36,8 +51,8 @@ <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> - <source>8</source> - <target>1.8</target> + <source>11</source> + <target>11</target> </configuration> </plugin> <plugin> diff --git "a/\303\274bung1/src/main/java/CSVUser/CSVUser.java" "b/\303\274bung1/src/main/java/CSVUser/CSVUser.java" deleted file mode 100644 index 04bcf5cc66e188365334722bbc764bd88fb9887e..0000000000000000000000000000000000000000 --- "a/\303\274bung1/src/main/java/CSVUser/CSVUser.java" +++ /dev/null @@ -1,153 +0,0 @@ -package de.unibremen.swp.data; - -import java.util.ArrayList; -import java.util.List; -import java.util.Objects; - -/** - * Represents a user imported from a CSV file. - */ -public class CSVUser { - - /** - * The identification number of a user. - */ - private int id = 1; - - /** - * A user's first name. - */ - private String firstName = ""; - - /** - * A user's last name. - */ - private String lastName = ""; - - /** - * A user's motto. - */ - private String motto = ""; - - /** - * Stores the ids of the friends. - */ - private List<Integer> friends = new ArrayList<>(); - - /** - * Returns the identification number. - * - * @return - * The identification number. - */ - public int getId() { - return id; - } - - /** - * Sets the identification number. - * - * @param id - * The identification number to set. - */ - public void setId(final int id) { - this.id = id; - } - - /** - * Returns the first name. - * - * @return - * The first name. - */ - public String getFirstName() { - return firstName; - } - - /** - * Sets the first name. - * - * @param firstName - * The first name to set. - * @throws NullPointerException - * If {@code firstName} is {@code null}. - */ - public void setFirstName(final String firstName) throws - NullPointerException { - this.firstName = Objects.requireNonNull(firstName); - } - - /** - * Returns the last name. - * - * @return - * The last name. - */ - public String getLastName() { - return lastName; - } - - /** - * Sets the last name. - * - * @param lastName - * The last name to set. - * @throws NullPointerException - * If {@code lastName} is {@code null}. - */ - public void setLastName(final String lastName) throws - NullPointerException { - this.lastName = Objects.requireNonNull(lastName); - } - - /** - * Returns the motto. - * - * @return - * The motto. - */ - public String getMotto() { - return motto; - } - - /** - * Sets the motto. - * - * @param motto - * The motto to set. - * @throws NullPointerException - * If {@code motto} is {@code null}. - */ - public void setMotto(final String motto) throws NullPointerException { - this.motto = Objects.requireNonNull(motto); - } - - /** - * Returns a flat copy of the friends (their id). - * - * @return - * A flat copy of the id of the friends. - */ - public List<Integer> getFriends() { - return new ArrayList<>(friends); - } - - /** - * Sets the friends (their id). Creates a flat copy of {@code friends}. - * - * @param friends - * The ids to set. - * @throws NullPointerException - * If {@code friends} is {@code null}. - * @throws IllegalArgumentException - * If {@code friends} contains {@code null}. - */ - public void setFriends(final List<Integer> friends) throws - NullPointerException, IllegalArgumentException { - if (Objects.requireNonNull(friends).stream() - .anyMatch(Objects::isNull)) { - throw new IllegalArgumentException(); - } - this.friends = new ArrayList<>(friends); - } -} diff --git "a/\303\274bung1/src/main/java/Converter/Converter.java" "b/\303\274bung1/src/main/java/Converter/Converter.java" deleted file mode 100644 index 7d6081df0541e4e9af2e0b69211ee99443aaa97a..0000000000000000000000000000000000000000 --- "a/\303\274bung1/src/main/java/Converter/Converter.java" +++ /dev/null @@ -1,66 +0,0 @@ -package de.unibremen.swp; - -import de.unibremen.swp.data.CSVUser; -import de.unibremen.swp.data.JSONUser; - -import java.text.ParseException; - -/** - * Allows to convert between {@link CSVUser} stored in CSV strings and - * {@link JSONUser} stored in JSON strings. Uses {@link Parser} for - * serialization and deserialization. - */ -public class Converter { - - /** - * The parser that is used to serialize and deserialize the corresponding - * {@link CSVUser} and {@link JSONUser} objects. - */ - private final Parser parser = new Parser(); - - /** - * Converts the given CSV string with {@link CSVUser} to a JSON string with - * {@link JSONUser}. - * - * @param csv - * The CSV string to convert. - * @return - * The converted JSON string. - * @throws NullPointerException - * If {@code csv} is {@code null}. - * @throws IllegalArgumentException - * If {@link Parser#readCSVUsers(String)} or - * {@link Parser#writeJSONUsers(List)} throws an - * {@link IllegalArgumentException}. - * @throws ParseException - * If {@link Parser#readCSVUsers(String)} throws a - * {@link ParseException}. - */ - public String csvToJSON(final String csv) throws NullPointerException, - IllegalArgumentException, ParseException { - throw new UnsupportedOperationException(); - } - - /** - * Converts the given JSON string with {@link JSONUser} to a CSV string - * with {@link CSVUser}. - * - * @param json - * The JSON string to convert. - * @return - * The converted CSV string. - * @throws NullPointerException - * If {@code json} is {@code null}. - * @throws IllegalArgumentException - * If {@link Parser#readJSONUsers(String)} or - * {@link Parser#writeCSVUsers(List)} throws an - * {@link IllegalArgumentException}. - * @throws ParseException - * If {@link Parser#readJSONUsers(String)} throws a - * {@link ParseException}. - */ - public String jsonToCSV(final String json) throws NullPointerException, - IllegalArgumentException, ParseException { - throw new UnsupportedOperationException(); - } -} diff --git "a/\303\274bung1/src/main/java/Parser/Parser.java" "b/\303\274bung1/src/main/java/Parser/Parser.java" deleted file mode 100644 index d70f80705d92c61549f0aadbb4d13197f2890b55..0000000000000000000000000000000000000000 --- "a/\303\274bung1/src/main/java/Parser/Parser.java" +++ /dev/null @@ -1,114 +0,0 @@ -package de.unibremen.swp; - -import de.unibremen.swp.data.CSVUser; -import de.unibremen.swp.data.JSONUser; - -import java.text.ParseException; -import java.util.List; - -/** - * Provides methods to read (also referred to as deserialization) and write - * (also referred to as serialization) {@link CSVUser} and {@link JSONUser} - * from and to strings. - */ -public class Parser { - - /** - * The delimiter used to separate values in CSV. - */ - private static final char CSV_DELIMITER = '‽'; - - /** - * Implements the integrity checks of {@link #readCSVUsers(String)} and - * {@link #writeCSVUsers(List)}. - */ - private void validate(final List<CSVUser> users) { - throw new UnsupportedOperationException(); - } - - /** - * Parses the given CSV string and creates a list of {@link CSVUser} from - * it. Duplicates (according to {@link CSVUser#equals(Object)}) are - * filtered out. - * - * @param csv - * The CSV string to parse. - * @return - * The users deserialized from {@code csv}. - * @throws NullPointerException - * If {@code csv} is {@code null}. - * @throws IllegalArgumentException - * If i) the id of a user is less than {@code 1} or greater than the - * total number of users stored in {@code csv}, ii) two users, - * {@code u1} and {@code u2} with {@code u1 != u2}, share the same id - * such that {@code u1.getId() == u2.getId()}, or iii) a user - * references a non-existing id in its list of friends (cf. - * {@link CSVUser#getFriends()}). - * @throws ParseException - * If an error occurred while parsing {@code csv}. - */ - public List<CSVUser> readCSVUsers(final String csv) throws - NullPointerException, IllegalArgumentException, ParseException { - throw new UnsupportedOperationException(); - } - - /** - * Creates a CSV string from the given list of {@link CSVUser}. Duplicates - * (according to {@link CSVUser#equals(Object)}) and {@code null} values in - * {@code users} are filtered out. - * - * @param users - * The users to serialize. - * @return - * The resulting CSV string. - * @throws NullPointerException - * If {@code users} is {@code null}. - * @throws IllegalArgumentException - * If i) the id of a user is less than {@code 1} or greater than the - * total number of users stored in {@code users}, ii) two users, - * {@code u1} and {@code u2} with {@code u1 != u2}, share the same id - * such that {@code u1.getId() == u2.getId()}, or iii) a user - * references a non-existing id in its list of friends (cf. - * {@link CSVUser#getFriends()}). - */ - public String writeCSVUsers(final List<CSVUser> users) throws - NullPointerException, IllegalArgumentException { - throw new UnsupportedOperationException(); - } - - /** - * Parses the given JSON string and creates a list of {@link JSONUser} from - * it. Duplicates (according to {@link JSONUser#equals(Object)}) are - * filtered out. - * - * @param json - * The JSON string to parse. - * @return - * The users deserialized from {@code json}. - * @throws NullPointerException - * If {@code json} is {@code null}. - * @throws ParseException - * If an error occurred while parsing {@code json}. - */ - public List<JSONUser> readJSONUsers(final String json) throws - NullPointerException, ParseException { - throw new UnsupportedOperationException(); - } - - /** - * Creates a JSON string from the given list of {@link JSONUser}. - * Duplicates (according to {@link JSONUser#equals(Object)}) and - * {@code null} values in {@code users} are filtered out. - * - * @param users - * The users to serialize. - * @return - * The resulting JSON string. - * @throws NullPointerException - * If {@code users} is {@code null}. - */ - public String writeJSONUsers(final List<JSONUser> users) throws - NullPointerException { - throw new UnsupportedOperationException(); - } -} diff --git "a/\303\274bung1/src/main/java/de/unibremen/swp/Converter.java" "b/\303\274bung1/src/main/java/de/unibremen/swp/Converter.java" new file mode 100644 index 0000000000000000000000000000000000000000..bb4d77e09e09bc1c0597e831d02989c7e3692752 --- /dev/null +++ "b/\303\274bung1/src/main/java/de/unibremen/swp/Converter.java" @@ -0,0 +1,125 @@ +package de.unibremen.swp; + +import de.unibremen.swp.data.CSVUser; +import de.unibremen.swp.data.JSONUser; + +import java.text.ParseException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +/** + * Allows to convert between {@link CSVUser} stored in CSV strings and + * {@link JSONUser} stored in JSON strings. Uses {@link Parser} for + * serialization and deserialization. + */ +public class Converter { + + /** + * The parser that is used to serialize and deserialize the corresponding + * {@link CSVUser} and {@link JSONUser} objects. + */ + private final Parser parser = new Parser(); + + /** + * Converts the given CSV string with {@link CSVUser} to a JSON string with + * {@link JSONUser}. + * + * @param csv + * The CSV string to convert. + * @return + * The converted JSON string. + * @throws NullPointerException + * If {@code csv} is {@code null}. + * @throws IllegalArgumentException + * If {@link Parser#readCSVUsers(String)} or + * {@link Parser#writeJSONUsers(List)} throws an + * {@link IllegalArgumentException}. + * @throws ParseException + * If {@link Parser#readCSVUsers(String)} throws a + * {@link ParseException}. + */ + public String csvToJSON(final String csv) throws NullPointerException, + IllegalArgumentException, ParseException { + if(csv==null){ + throw new NullPointerException(String.format("The String is null",csv)); + } + final List<CSVUser> csvUsers = parser.readCSVUsers(csv); + final List<JSONUser> jsonUsers = new ArrayList<>(csvUsers.size()); + + final Map<Integer, JSONUser> idMap = new HashMap<>(); //Liste mit den Id's + + for(final CSVUser csvUser: csvUsers){ + final JSONUser jsonUser = new JSONUser(); + jsonUser.setFirstName(csvUser.getFirstName()); + jsonUser.setLastName(csvUser.getLastName()); + jsonUser.setMotto(csvUser.getMotto()); + + + idMap.put(csvUser.getId(),jsonUser); + jsonUsers.add(jsonUser); + } + + for(final CSVUser csvUser: csvUsers){ + final JSONUser jsonUser = idMap.get(csvUser.getId()); + + final List<JSONUser> friends = csvUser.getFriends()//Eine Liste der Freunde + .stream() //WIr eröffnen einen stream von Integern + .map(idMap::get) //Jeder ID packen wir in idMap rein in die Methode get. Das gibt uns das entsprechende JSONUserObjekt + .collect(Collectors.toList()); //Aus dem allen erzeugen wir eine Liste + jsonUser.setFriends(friends); //Die Liste wurde nun auf die JSONUser gesetzt + + } + return parser.writeJSONUsers(jsonUsers); + } + + /** + * Converts the given JSON string with {@link JSONUser} to a CSV string + * with {@link CSVUser}. + * + * @param json + * The JSON string to convert. + * @return + * The converted CSV string. + * @throws NullPointerException + * If {@code json} is {@code null}. + * @throws IllegalArgumentException + * If {@link Parser#readJSONUsers(String)} or + * {@link Parser#writeCSVUsers(List)} throws an + * {@link IllegalArgumentException}. + * @throws ParseException + * If {@link Parser#readJSONUsers(String)} throws a + * {@link ParseException}. + */ + public String jsonToCSV(final String json) throws NullPointerException, + IllegalArgumentException, ParseException { + if(json==null){ + throw new NullPointerException("json is null"); + } + + final List<JSONUser> jsonUsers = parser.readJSONUsers(json); //Eine Liste mit den gelesenen JSONUsers aus der Datei + final List<CSVUser> csvUsers = new ArrayList<>(jsonUsers.size()); + + //ID-Generierung folgt jetzt + for(int id=1; id <= jsonUsers.size();id++){ + final JSONUser jsonUser = jsonUsers.get(id - 1); + final CSVUser csvUser = new CSVUser(); + csvUser.setId(id); + csvUser.setFirstName(jsonUser.getFirstName()); + csvUser.setLastName(jsonUser.getLastName()); + csvUser.setMotto(jsonUser.getMotto()); + + final List<Integer> friends = jsonUser.getFriends() + .stream() + .map(friend -> jsonUsers.indexOf(friend) +1) //+1, weil wir ja von der ID 1 starten bis zur Macimalen Anzahl der Nutzer, die es gibt + .collect(Collectors.toList()); + csvUser.setFriends(friends); + + csvUsers.add(csvUser); + } + + return parser.writeCSVUsers(csvUsers); + } +} diff --git "a/\303\274bung1/src/main/java/Main/Main.java" "b/\303\274bung1/src/main/java/de/unibremen/swp/Main.java" similarity index 100% rename from "\303\274bung1/src/main/java/Main/Main.java" rename to "\303\274bung1/src/main/java/de/unibremen/swp/Main.java" diff --git "a/\303\274bung1/src/main/java/de/unibremen/swp/Parser.java" "b/\303\274bung1/src/main/java/de/unibremen/swp/Parser.java" new file mode 100644 index 0000000000000000000000000000000000000000..34b45ddff76bd8dd1eeebfe759fe6590b5f5aaba --- /dev/null +++ "b/\303\274bung1/src/main/java/de/unibremen/swp/Parser.java" @@ -0,0 +1,217 @@ +package de.unibremen.swp; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.opencsv.bean.CsvToBeanBuilder; +import com.opencsv.bean.StatefulBeanToCsv; +import com.opencsv.bean.StatefulBeanToCsvBuilder; +import com.opencsv.exceptions.CsvDataTypeMismatchException; +import com.opencsv.exceptions.CsvRequiredFieldEmptyException; +import de.unibremen.swp.data.CSVUser; +import de.unibremen.swp.data.JSONUser; + +import java.io.IOException; +import java.io.StringReader; +import java.io.StringWriter; +import java.text.ParseException; +import java.util.*; +import java.util.stream.Collectors; + +/** + * Provides methods to read (also referred to as deserialization) and write + * (also referred to as serialization) {@link CSVUser} and {@link JSONUser} + * from and to strings. + */ +public class Parser { + + /** + * The delimiter used to separate values in CSV. + */ + private static final char CSV_DELIMITER = '‽'; + + /** + * Implements the integrity checks of {@link #readCSVUsers(String)} and + * {@link #writeCSVUsers(List)}. + * Throws IllegalArgumentException.class: + * If i) the id of a user is less than {@code 1} or greater than the + * * total number of users stored in {@code users}, ii) two users, + * * {@code u1} and {@code u2} with {@code u1 != u2}, share the same id + * * such that {@code u1.getId() == u2.getId()}, or iii) a user + * * references a non-existing id in its list of friends (cf. + * * {@link CSVUser#getFriends()}). + */ + private void validate(final List<CSVUser> users) { + final int userCount= users.size(); + final Set<Integer> ids = new HashSet<>();//Die Vergleichsliste von users + + for(final CSVUser user: users){ + if(user.getId() < 1){ + throw new IllegalArgumentException("Id is smaller than 1."); + } + + if(user.getId() > userCount){ + throw new IllegalArgumentException("Id is greater than the number of users."); + } + if(ids.contains(user.getId())) { + throw new IllegalArgumentException(String.format("There is more than one user with id '%d'",user.getId())); + } + + ids.add(user.getId()); + for(final int friendId : user.getFriends()) { + if(friendId < 1 || friendId > userCount) { + throw new IllegalArgumentException(String.format("The user with id '%d' has got an illegal friend id '%d'.",user.getId(),friendId)); + } + } + + + } + } + + /** + * Parses the given CSV string and creates a list of {@link CSVUser} from + * it. Duplicates (according to {@link CSVUser#equals(Object)}) are + * filtered out. + * + * @param csv + * The CSV string to parse. + * @return + * The users deserialized from {@code csv}. + * @throws NullPointerException + * If {@code csv} is {@code null}. + * @throws IllegalArgumentException + * If i) the id of a user is less than {@code 1} or greater than the + * total number of users stored in {@code csv}, ii) two users, + * {@code u1} and {@code u2} with {@code u1 != u2}, share the same id + * such that {@code u1.getId() == u2.getId()}, or iii) a user + * references a non-existing id in its list of friends (cf. + * {@link CSVUser#getFriends()}). + * @throws ParseException + * If an error occurred while parsing {@code csv}. + */ + public List<CSVUser> readCSVUsers(final String csv) throws + NullPointerException, IllegalArgumentException, ParseException { + Objects.requireNonNull(csv, "csv is null"); + final List<CSVUser> users; + try (StringReader reader = new StringReader(csv)) { + users = new CsvToBeanBuilder<CSVUser>(reader) + .withType(CSVUser.class) + .withSeparator(CSV_DELIMITER) + .build().stream() + .collect(Collectors.toList()); + } catch (final RuntimeException e) { + // Thrown by opencsv in case of a parse exception. + throw new ParseException(e.getMessage(), -1 /* not provided */); + } + validate(users); + return users.stream() + .distinct() + .collect(Collectors.toList()); + } + + + /** + * Creates a CSV string from the given list of {@link CSVUser}. Duplicates + * (according to {@link CSVUser#equals(Object)}) and {@code null} values in + * {@code users} are filtered out. + * + * @param users + * The users to serialize. + * @return + * The resulting CSV string. + * @throws NullPointerException + * If {@code users} is {@code null}. + * @throws IllegalArgumentException + * If i) the id of a user is less than {@code 1} or greater than the + * total number of users stored in {@code users}, ii) two users, + * {@code u1} and {@code u2} with {@code u1 != u2}, share the same id + * such that {@code u1.getId() == u2.getId()}, or iii) a user + * references a non-existing id in its list of friends (cf. + * {@link CSVUser#getFriends()}). + */ + public String writeCSVUsers(final List<CSVUser> users) throws + NullPointerException, IllegalArgumentException { + Objects.requireNonNull(users, "users is null"); + final List<CSVUser> filteredUsers = users.stream() + .filter(Objects::nonNull) + .distinct() + .collect(Collectors.toList()); + validate(filteredUsers); + try (StringWriter writer = new StringWriter()) { + new StatefulBeanToCsvBuilder<CSVUser>(writer) + .withSeparator(CSV_DELIMITER) + .build() + .write(filteredUsers); + return writer.toString(); + } catch (final IOException e) { + throw new IllegalStateException( + "Internal error: Could not close string writer", e); + } catch (final CsvRequiredFieldEmptyException e) { + throw new IllegalStateException( + "Internal error: Required field is missing", e); + } catch (CsvDataTypeMismatchException e) { + throw new IllegalStateException( + "Internal error: Type mismatch", e); + } + } + + + /** + * Parses the given JSON string and creates a list of {@link JSONUser} from + * it. Duplicates (according to {@link JSONUser#equals(Object)}) are + * filtered out. + * + * @param json + * The JSON string to parse. + * @return + * The users deserialized from {@code json}. + * @throws NullPointerException + * If {@code json} is {@code null}. + * @throws ParseException + * If an error occurred while parsing {@code json}. + * + * Erklärung: Ein Objectmapper macht aus einem String ein Objekt. Dies brauchen wir + * bei Jason-Dateien, weil die Strings zu Objekten convertiert werden. + */ + public List<JSONUser> readJSONUsers(final String json) throws + NullPointerException, ParseException { + Objects.requireNonNull(json, "json is null"); + try { + final JSONUser[] users = new ObjectMapper() + .readValue(json, JSONUser[].class); //Wir erwarten einen Array von JSONUser + return Arrays.stream(users) + .distinct() + .collect(Collectors.toList()); + } catch (final JsonProcessingException e) { + throw new ParseException(e.getMessage(), (int) e.getLocation().getCharOffset()); + } + } + + /** + * Creates a JSON string from the given list of {@link JSONUser}. + * Duplicates (according to {@link JSONUser#equals(Object)}) and + * {@code null} values in {@code users} are filtered out. + * + * @param users + * The users to serialize. + * @return + * The resulting JSON string. + * @throws NullPointerException + * If {@code users} is {@code null}. + */ + public String writeJSONUsers(final List<JSONUser> users) throws + NullPointerException { + Objects.requireNonNull(users, "users is null"); + final List<JSONUser> filteredUsers = users.stream() //Stream zum ausfiltern von Null-Users + .filter(Objects::nonNull) + .distinct() //Distinct wirft die dopplungen raus, die wir gefiltert haben(oben) + .collect(Collectors.toList()); //Das gefilterte(gute) wird in einer Liste neu gesammelt + try { + return new ObjectMapper() //Eine Liste von JSONUser erzeugen mit Objectmapper + .writerWithDefaultPrettyPrinter() //Prettyprinter formatieren alles viel schöner, als in derJSON datei selbst + .writeValueAsString(filteredUsers); + } catch (JsonProcessingException e) { + throw new IllegalStateException("Internal error: Jackson failed", e); + } + + } +} diff --git "a/\303\274bung1/src/main/java/de/unibremen/swp/data/CSVUser.java" "b/\303\274bung1/src/main/java/de/unibremen/swp/data/CSVUser.java" new file mode 100644 index 0000000000000000000000000000000000000000..b8be1bd5aad13cc0a5a2887c59358b20c1e4d341 --- /dev/null +++ "b/\303\274bung1/src/main/java/de/unibremen/swp/data/CSVUser.java" @@ -0,0 +1,232 @@ +package de.unibremen.swp.data; + +import com.opencsv.bean.AbstractBeanField; +import com.opencsv.bean.CsvBindByName; +import com.opencsv.bean.CsvCustomBindByName; +import com.opencsv.exceptions.CsvDataTypeMismatchException; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Objects; +import java.util.stream.Collectors; + +/** + * Represents a user imported from a CSV file. + */ +public class CSVUser { + + /** + * * Converts the "Friends" column to a list of integers. + * WICHTIG: Durch Leerzeichen und Zeilenumbrüche in der csv kann vieles schief laufen, deshalb ist die Verwendung + * von der Methode trim und Zeilenumbruchentfernung so wichtig. + * + * Nachrage: Warum wird das trimmen so geschrieben: .map(String::trim)? + * + */ + public static class FriendsConverter extends AbstractBeanField<List<Integer>, String> { + @Override + protected Object convert(final String value) + throws CsvDataTypeMismatchException { + if (value.isBlank()) + { + return new ArrayList<Integer>(); + } + + final List<String> strIds = Arrays.stream(value.split(",")) + .map(s -> s.replace("\n","")) + .map(s -> s.replace("\r","")) + .map(String::trim) + .collect(Collectors.toList()); + final List<Integer> result = new ArrayList<>(); + + for (final String s : strIds) + { + try { + result.add(Integer.parseInt(s)); + } catch (final NumberFormatException e) + { + throw new CsvDataTypeMismatchException(String.format("Unable to convert '%s' to int" ,s)); + } + } + return result; + } + + @Override + /* + Ein Delimeter ist ein Zeichen, was zwischen die Strings geschrieben wird. + */ + protected String convertToWrite(final Object value) throws CsvDataTypeMismatchException { + if(value ==null){ + return ""; + } + if (!(value instanceof List)) { + throw new CsvDataTypeMismatchException(String.format("Only able to operate on lists/collections. Attribute is of type '%s'",value.getClass().getName())); + } + final List<?> values= (List<?>)value; + final List<String> strIDs= new ArrayList<>(); + + for(final Object obj: values){ + if(obj==null){ + throw new CsvDataTypeMismatchException(String.format("Expected instances of Integer. Got 'null'.")); + } + if(!(obj instanceof Integer)) { + throw new CsvDataTypeMismatchException(String.format("Expected instances of Integer, got instance of '%s'",obj.getClass().getName())); + } + strIDs.add(obj.toString()); + } + return String.join(",", strIDs); // String join, nimmt ein itteriebares Object und konkateniert es zu einem string. + + + } + } + + + /** + * The identification number of a user. + */ + @CsvBindByName(column = "ID") + private int id = 1; + + /** + * A user's first name. + */ + @CsvBindByName(column = "First Name") //Csvbindbyname kopiert die gespeicherten Einträge der CSV in das Attribut unten + private String firstName = ""; //das column haben wir aus der users.csv datei geholt + + /** + * A user's last name. + */ + @CsvBindByName(column = "Last Name") + private String lastName = ""; + + /** + * A user's motto. + */ + @CsvBindByName(column = "Motto") + private String motto = ""; + + /** + * Stores the ids of the friends. + * Um Listen in eine Csv datei hinzufügen, brauchen wir eine custom bindbyname klasse, die wir selbst erstellen müssen + */ + @CsvCustomBindByName(column = "Friends",converter = FriendsConverter.class) + private List<Integer> friends = new ArrayList<>(); + + /** + * Returns the identification number. + * + * @return + * The identification number. + */ + public int getId() { + return id; + } + + /** + * Sets the identification number. + * + * @param id + * The identification number to set. + */ + public void setId(final int id) { + this.id = id; + } + + /** + * Returns the first name. + * + * @return + * The first name. + */ + public String getFirstName() { + return firstName; + } + + /** + * Sets the first name. + * + * @param firstName + * The first name to set. + * @throws NullPointerException + * If {@code firstName} is {@code null}. + */ + public void setFirstName(final String firstName) throws + NullPointerException { + this.firstName = Objects.requireNonNull(firstName); + } + + /** + * Returns the last name. + * + * @return + * The last name. + */ + public String getLastName() { + return lastName; + } + + /** + * Sets the last name. + * + * @param lastName + * The last name to set. + * @throws NullPointerException + * If {@code lastName} is {@code null}. + */ + public void setLastName(final String lastName) throws + NullPointerException { + this.lastName = Objects.requireNonNull(lastName); + } + + /** + * Returns the motto. + * + * @return + * The motto. + */ + public String getMotto() { + return motto; + } + + /** + * Sets the motto. + * + * @param motto + * The motto to set. + * @throws NullPointerException + * If {@code motto} is {@code null}. + */ + public void setMotto(final String motto) throws NullPointerException { + this.motto = Objects.requireNonNull(motto); + } + + /** + * Returns a flat copy of the friends (their id). + * + * @return + * A flat copy of the id of the friends. + */ + public List<Integer> getFriends() { + return new ArrayList<>(friends); + } + + /** + * Sets the friends (their id). Creates a flat copy of {@code friends}. + * + * @param friends + * The ids to set. + * @throws NullPointerException + * If {@code friends} is {@code null}. + * @throws IllegalArgumentException + * If {@code friends} contains {@code null}. + */ + public void setFriends(final List<Integer> friends) throws + NullPointerException, IllegalArgumentException { + if (Objects.requireNonNull(friends).stream() + .anyMatch(Objects::isNull)) { + throw new IllegalArgumentException(); + } + this.friends = new ArrayList<>(friends); + } +} diff --git "a/\303\274bung1/src/main/java/JSONUser/JSONUser.java" "b/\303\274bung1/src/main/java/de/unibremen/swp/data/JSONUser.java" similarity index 94% rename from "\303\274bung1/src/main/java/JSONUser/JSONUser.java" rename to "\303\274bung1/src/main/java/de/unibremen/swp/data/JSONUser.java" index dfc6a8e8fd7e3662afd50508651fd5812c32aac1..8508231bbfc543f92d134d047735a49e364dac6c 100644 --- "a/\303\274bung1/src/main/java/JSONUser/JSONUser.java" +++ "b/\303\274bung1/src/main/java/de/unibremen/swp/data/JSONUser.java" @@ -1,5 +1,8 @@ package de.unibremen.swp.data; +import com.fasterxml.jackson.annotation.JsonIdentityInfo; +import com.voodoodyne.jackson.jsog.JSOGGenerator; + import java.util.ArrayList; import java.util.List; import java.util.Objects; @@ -7,6 +10,7 @@ import java.util.Objects; /** * Represents a user imported from a JSON file. */ +@JsonIdentityInfo(generator= JSOGGenerator.class) public class JSONUser { /** diff --git "a/\303\274bung1/src/test/java/Convertertest/ConverterTest.java" "b/\303\274bung1/src/test/java/de/unibremen/swp/ConverterTest.java" similarity index 100% rename from "\303\274bung1/src/test/java/Convertertest/ConverterTest.java" rename to "\303\274bung1/src/test/java/de/unibremen/swp/ConverterTest.java" diff --git "a/\303\274bung1/src/test/java/Parsertest/ParserTest.java" "b/\303\274bung1/src/test/java/de/unibremen/swp/ParserTest.java" similarity index 100% rename from "\303\274bung1/src/test/java/Parsertest/ParserTest.java" rename to "\303\274bung1/src/test/java/de/unibremen/swp/ParserTest.java" diff --git "a/\303\274bung1/target/classes/de/unibremen/swp/Converter.class" "b/\303\274bung1/target/classes/de/unibremen/swp/Converter.class" index cc8b2199b6b22db153b4988b7c0a670e507cdf25..9354395ab91fb58c9ea872cfeee963d229ac529a 100644 Binary files "a/\303\274bung1/target/classes/de/unibremen/swp/Converter.class" and "b/\303\274bung1/target/classes/de/unibremen/swp/Converter.class" differ diff --git "a/\303\274bung1/target/classes/de/unibremen/swp/Main.class" "b/\303\274bung1/target/classes/de/unibremen/swp/Main.class" index 271cad051d7b81b3c9b6da812d9dfb08bc8676af..455acab25cb6eb29e0ce710dbd394af741b171ce 100644 Binary files "a/\303\274bung1/target/classes/de/unibremen/swp/Main.class" and "b/\303\274bung1/target/classes/de/unibremen/swp/Main.class" differ diff --git "a/\303\274bung1/target/classes/de/unibremen/swp/Parser.class" "b/\303\274bung1/target/classes/de/unibremen/swp/Parser.class" index f0b1dc751f420546a6b302ccbd1fd96068677527..41596e89e38f66a288978e3298ac9119daa3a269 100644 Binary files "a/\303\274bung1/target/classes/de/unibremen/swp/Parser.class" and "b/\303\274bung1/target/classes/de/unibremen/swp/Parser.class" differ diff --git "a/\303\274bung1/target/classes/de/unibremen/swp/data/CSVUser.class" "b/\303\274bung1/target/classes/de/unibremen/swp/data/CSVUser.class" index 91faf9155ffdf67057f08712b21111ea9e04b828..a49cc5dddfa7cce565fe7e9bdd314b18af0e58b6 100644 Binary files "a/\303\274bung1/target/classes/de/unibremen/swp/data/CSVUser.class" and "b/\303\274bung1/target/classes/de/unibremen/swp/data/CSVUser.class" differ diff --git "a/\303\274bung1/target/classes/de/unibremen/swp/data/JSONUser.class" "b/\303\274bung1/target/classes/de/unibremen/swp/data/JSONUser.class" index 66f6ca16f0c560636c5702a71d47e6218527ccda..661ee61f858a0c80ab7ee1fc47d3767d75fcb2bf 100644 Binary files "a/\303\274bung1/target/classes/de/unibremen/swp/data/JSONUser.class" and "b/\303\274bung1/target/classes/de/unibremen/swp/data/JSONUser.class" differ diff --git "a/\303\274bung1/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst" "b/\303\274bung1/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst" index bf0d2fd4af8a8661157f22839731f7aaf777d503..c9f5b171cb266724210bf987c189c01d9f2712c9 100644 --- "a/\303\274bung1/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst" +++ "b/\303\274bung1/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst" @@ -1,6 +1,5 @@ -C:\Users\Administrator\Desktop\Universität Bremen\Semester 5\SWP2\Vorbereitung\Repository\MiniProjekt\src\main\java\Parser\Parser.java -C:\Users\Administrator\Desktop\Universität Bremen\Semester 5\SWP2\Vorbereitung\Repository\MiniProjekt\src\main\java\de\unibremen\swp\App.java -C:\Users\Administrator\Desktop\Universität Bremen\Semester 5\SWP2\Vorbereitung\Repository\MiniProjekt\src\main\java\Main\Main.java -C:\Users\Administrator\Desktop\Universität Bremen\Semester 5\SWP2\Vorbereitung\Repository\MiniProjekt\src\main\java\Converter\Converter.java -C:\Users\Administrator\Desktop\Universität Bremen\Semester 5\SWP2\Vorbereitung\Repository\MiniProjekt\src\main\java\CSVUser\CSVUser.java -C:\Users\Administrator\Desktop\Universität Bremen\Semester 5\SWP2\Vorbereitung\Repository\MiniProjekt\src\main\java\JSONUser\JSONUser.java +C:\Users\Administrator\Desktop\Universität Bremen\Semester 5\SWP2\Vorbereitung\Repository\miniprojekt2020\übung1\src\main\java\JSONUser\JSONUser.java +C:\Users\Administrator\Desktop\Universität Bremen\Semester 5\SWP2\Vorbereitung\Repository\miniprojekt2020\übung1\src\main\java\CSVUser\CSVUser.java +C:\Users\Administrator\Desktop\Universität Bremen\Semester 5\SWP2\Vorbereitung\Repository\miniprojekt2020\übung1\src\main\java\Main\Main.java +C:\Users\Administrator\Desktop\Universität Bremen\Semester 5\SWP2\Vorbereitung\Repository\miniprojekt2020\übung1\src\main\java\Parser\Parser.java +C:\Users\Administrator\Desktop\Universität Bremen\Semester 5\SWP2\Vorbereitung\Repository\miniprojekt2020\übung1\src\main\java\Converter\Converter.java diff --git "a/\303\274bung1/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst" "b/\303\274bung1/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst" index 60481e073c7a8a785d542fbf9fdeb8302d522c03..6b788d2ebfa8c4bf223507a768d94787598f0133 100644 --- "a/\303\274bung1/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst" +++ "b/\303\274bung1/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst" @@ -1,3 +1,2 @@ -C:\Users\Administrator\Desktop\Universität Bremen\Semester 5\SWP2\Vorbereitung\Repository\MiniProjekt\src\test\java\de\unibremen\swp\AppTest.java -C:\Users\Administrator\Desktop\Universität Bremen\Semester 5\SWP2\Vorbereitung\Repository\MiniProjekt\src\test\java\Convertertest\ConverterTest.java -C:\Users\Administrator\Desktop\Universität Bremen\Semester 5\SWP2\Vorbereitung\Repository\MiniProjekt\src\test\java\Parsertest\ParserTest.java +C:\Users\Administrator\Desktop\Universität Bremen\Semester 5\SWP2\Vorbereitung\Repository\miniprojekt2020\übung1\src\test\java\Convertertest\ConverterTest.java +C:\Users\Administrator\Desktop\Universität Bremen\Semester 5\SWP2\Vorbereitung\Repository\miniprojekt2020\übung1\src\test\java\Parsertest\ParserTest.java diff --git "a/\303\274bung1/target/surefire-reports/TEST-de.unibremen.swp.ConverterTest.xml" "b/\303\274bung1/target/surefire-reports/TEST-de.unibremen.swp.ConverterTest.xml" index ad4ab9c4dcd0ba5cad4cd1d564e00f37dc0ddfd9..ea2a31a6e0485fb1d9ebbf789008aa7faa2761ec 100644 --- "a/\303\274bung1/target/surefire-reports/TEST-de.unibremen.swp.ConverterTest.xml" +++ "b/\303\274bung1/target/surefire-reports/TEST-de.unibremen.swp.ConverterTest.xml" @@ -1,12 +1,12 @@ <?xml version="1.0" encoding="UTF-8"?> -<testsuite xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://maven.apache.org/surefire/maven-surefire-plugin/xsd/surefire-test-report.xsd" name="de.unibremen.swp.ConverterTest" time="0.031" tests="2" errors="2" skipped="0" failures="0"> +<testsuite xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://maven.apache.org/surefire/maven-surefire-plugin/xsd/surefire-test-report.xsd" name="de.unibremen.swp.ConverterTest" time="0.037" tests="2" errors="2" skipped="0" failures="0"> <properties> <property name="sun.desktop" value="windows"/> <property name="awt.toolkit" value="sun.awt.windows.WToolkit"/> <property name="java.specification.version" value="11"/> <property name="sun.cpu.isalist" value="amd64"/> <property name="sun.jnu.encoding" value="Cp1252"/> - <property name="java.class.path" value="C:\Users\Administrator\Desktop\Universität Bremen\Semester 5\SWP2\Vorbereitung\Repository\MiniProjekt\target\test-classes;C:\Users\Administrator\Desktop\Universität Bremen\Semester 5\SWP2\Vorbereitung\Repository\MiniProjekt\target\classes;C:\Users\Administrator\.m2\repository\junit\junit\3.8.1\junit-3.8.1.jar;C:\Users\Administrator\.m2\repository\org\junit\jupiter\junit-jupiter-engine\5.6.1\junit-jupiter-engine-5.6.1.jar;C:\Users\Administrator\.m2\repository\org\apiguardian\apiguardian-api\1.1.0\apiguardian-api-1.1.0.jar;C:\Users\Administrator\.m2\repository\org\junit\platform\junit-platform-engine\1.6.1\junit-platform-engine-1.6.1.jar;C:\Users\Administrator\.m2\repository\org\opentest4j\opentest4j\1.2.0\opentest4j-1.2.0.jar;C:\Users\Administrator\.m2\repository\org\junit\platform\junit-platform-commons\1.6.1\junit-platform-commons-1.6.1.jar;C:\Users\Administrator\.m2\repository\org\junit\jupiter\junit-jupiter-api\5.6.1\junit-jupiter-api-5.6.1.jar;"/> + <property name="java.class.path" value="C:\Users\Administrator\Desktop\Universität Bremen\Semester 5\SWP2\Vorbereitung\Repository\miniprojekt2020\übung1\target\test-classes;C:\Users\Administrator\Desktop\Universität Bremen\Semester 5\SWP2\Vorbereitung\Repository\miniprojekt2020\übung1\target\classes;C:\Users\Administrator\.m2\repository\junit\junit\3.8.1\junit-3.8.1.jar;C:\Users\Administrator\.m2\repository\org\junit\jupiter\junit-jupiter-engine\5.6.1\junit-jupiter-engine-5.6.1.jar;C:\Users\Administrator\.m2\repository\org\apiguardian\apiguardian-api\1.1.0\apiguardian-api-1.1.0.jar;C:\Users\Administrator\.m2\repository\org\junit\platform\junit-platform-engine\1.6.1\junit-platform-engine-1.6.1.jar;C:\Users\Administrator\.m2\repository\org\opentest4j\opentest4j\1.2.0\opentest4j-1.2.0.jar;C:\Users\Administrator\.m2\repository\org\junit\platform\junit-platform-commons\1.6.1\junit-platform-commons-1.6.1.jar;C:\Users\Administrator\.m2\repository\org\junit\jupiter\junit-jupiter-api\5.6.1\junit-jupiter-api-5.6.1.jar;"/> <property name="java.vm.vendor" value="AdoptOpenJDK"/> <property name="sun.arch.data.model" value="64"/> <property name="user.variant" value=""/> @@ -17,9 +17,9 @@ <property name="sun.java.launcher" value="SUN_STANDARD"/> <property name="user.country" value="DE"/> <property name="sun.boot.library.path" value="C:\Program Files\AdoptOpenJDK\jdk-11.0.8.10-hotspot\bin"/> - <property name="sun.java.command" value="C:\Users\ADMINI~1\AppData\Local\Temp\surefire16384117284068919217\surefirebooter6360847745344186146.jar C:\Users\Administrator\AppData\Local\Temp\surefire16384117284068919217 2020-10-28T22-13-34_783-jvmRun1 surefire12350635713470639493tmp surefire_01285077207227050327tmp"/> + <property name="sun.java.command" value="C:\Users\ADMINI~1\AppData\Local\Temp\surefire13874946890087837961\surefirebooter5134790969064718219.jar C:\Users\Administrator\AppData\Local\Temp\surefire13874946890087837961 2020-10-28T23-40-03_390-jvmRun1 surefire6103472893634614880tmp surefire_05194153551236232086tmp"/> <property name="jdk.debug" value="release"/> - <property name="surefire.test.class.path" value="C:\Users\Administrator\Desktop\Universität Bremen\Semester 5\SWP2\Vorbereitung\Repository\MiniProjekt\target\test-classes;C:\Users\Administrator\Desktop\Universität Bremen\Semester 5\SWP2\Vorbereitung\Repository\MiniProjekt\target\classes;C:\Users\Administrator\.m2\repository\junit\junit\3.8.1\junit-3.8.1.jar;C:\Users\Administrator\.m2\repository\org\junit\jupiter\junit-jupiter-engine\5.6.1\junit-jupiter-engine-5.6.1.jar;C:\Users\Administrator\.m2\repository\org\apiguardian\apiguardian-api\1.1.0\apiguardian-api-1.1.0.jar;C:\Users\Administrator\.m2\repository\org\junit\platform\junit-platform-engine\1.6.1\junit-platform-engine-1.6.1.jar;C:\Users\Administrator\.m2\repository\org\opentest4j\opentest4j\1.2.0\opentest4j-1.2.0.jar;C:\Users\Administrator\.m2\repository\org\junit\platform\junit-platform-commons\1.6.1\junit-platform-commons-1.6.1.jar;C:\Users\Administrator\.m2\repository\org\junit\jupiter\junit-jupiter-api\5.6.1\junit-jupiter-api-5.6.1.jar;"/> + <property name="surefire.test.class.path" value="C:\Users\Administrator\Desktop\Universität Bremen\Semester 5\SWP2\Vorbereitung\Repository\miniprojekt2020\übung1\target\test-classes;C:\Users\Administrator\Desktop\Universität Bremen\Semester 5\SWP2\Vorbereitung\Repository\miniprojekt2020\übung1\target\classes;C:\Users\Administrator\.m2\repository\junit\junit\3.8.1\junit-3.8.1.jar;C:\Users\Administrator\.m2\repository\org\junit\jupiter\junit-jupiter-engine\5.6.1\junit-jupiter-engine-5.6.1.jar;C:\Users\Administrator\.m2\repository\org\apiguardian\apiguardian-api\1.1.0\apiguardian-api-1.1.0.jar;C:\Users\Administrator\.m2\repository\org\junit\platform\junit-platform-engine\1.6.1\junit-platform-engine-1.6.1.jar;C:\Users\Administrator\.m2\repository\org\opentest4j\opentest4j\1.2.0\opentest4j-1.2.0.jar;C:\Users\Administrator\.m2\repository\org\junit\platform\junit-platform-commons\1.6.1\junit-platform-commons-1.6.1.jar;C:\Users\Administrator\.m2\repository\org\junit\jupiter\junit-jupiter-api\5.6.1\junit-jupiter-api-5.6.1.jar;"/> <property name="sun.cpu.endian" value="little"/> <property name="user.home" value="C:\Users\Administrator"/> <property name="user.language" value="de"/> @@ -27,13 +27,13 @@ <property name="java.version.date" value="2020-07-14"/> <property name="java.home" value="C:\Program Files\AdoptOpenJDK\jdk-11.0.8.10-hotspot"/> <property name="file.separator" value="\"/> - <property name="basedir" value="C:\Users\Administrator\Desktop\Universität Bremen\Semester 5\SWP2\Vorbereitung\Repository\MiniProjekt"/> + <property name="basedir" value="C:\Users\Administrator\Desktop\Universität Bremen\Semester 5\SWP2\Vorbereitung\Repository\miniprojekt2020\übung1"/> <property name="java.vm.compressedOopsMode" value="32-bit"/> <property name="line.separator" value=" "/> <property name="java.specification.name" value="Java Platform API Specification"/> <property name="java.vm.specification.vendor" value="Oracle Corporation"/> <property name="java.awt.graphicsenv" value="sun.awt.Win32GraphicsEnvironment"/> - <property name="surefire.real.class.path" value="C:\Users\ADMINI~1\AppData\Local\Temp\surefire16384117284068919217\surefirebooter6360847745344186146.jar"/> + <property name="surefire.real.class.path" value="C:\Users\ADMINI~1\AppData\Local\Temp\surefire13874946890087837961\surefirebooter5134790969064718219.jar"/> <property name="user.script" value=""/> <property name="sun.management.compiler" value="HotSpot 64-Bit Tiered Compilers"/> <property name="java.runtime.version" value="11.0.8+10"/> @@ -48,7 +48,7 @@ <property name="java.vendor.url.bug" value="https://github.com/AdoptOpenJDK/openjdk-support/issues"/> <property name="java.io.tmpdir" value="C:\Users\ADMINI~1\AppData\Local\Temp\"/> <property name="java.version" value="11.0.8"/> - <property name="user.dir" value="C:\Users\Administrator\Desktop\Universität Bremen\Semester 5\SWP2\Vorbereitung\Repository\MiniProjekt"/> + <property name="user.dir" value="C:\Users\Administrator\Desktop\Universität Bremen\Semester 5\SWP2\Vorbereitung\Repository\miniprojekt2020\übung1"/> <property name="os.arch" value="amd64"/> <property name="java.vm.specification.name" value="Java Virtual Machine Specification"/> <property name="java.awt.printerjob" value="sun.awt.windows.WPrinterJob"/> @@ -60,12 +60,12 @@ <property name="sun.io.unicode.encoding" value="UnicodeLittle"/> <property name="java.class.version" value="55.0"/> </properties> - <testcase name="CSVToJSON" classname="de.unibremen.swp.ConverterTest" time="0.031"> + <testcase name="CSVToJSON" classname="de.unibremen.swp.ConverterTest" time="0.027"> <error type="java.lang.UnsupportedOperationException">java.lang.UnsupportedOperationException at de.unibremen.swp.ConverterTest.CSVToJSON(ConverterTest.java:26) </error> </testcase> - <testcase name="JSONToCSV" classname="de.unibremen.swp.ConverterTest" time="0"> + <testcase name="JSONToCSV" classname="de.unibremen.swp.ConverterTest" time="0.001"> <error type="java.lang.UnsupportedOperationException">java.lang.UnsupportedOperationException at de.unibremen.swp.ConverterTest.JSONToCSV(ConverterTest.java:132) </error> diff --git "a/\303\274bung1/target/surefire-reports/TEST-de.unibremen.swp.ParserTest.xml" "b/\303\274bung1/target/surefire-reports/TEST-de.unibremen.swp.ParserTest.xml" index 0530632318292a76df3fd9f1b40dd38aa5926262..8c8951dcaa3317c11dd03b29e3415f4c2cb98b15 100644 --- "a/\303\274bung1/target/surefire-reports/TEST-de.unibremen.swp.ParserTest.xml" +++ "b/\303\274bung1/target/surefire-reports/TEST-de.unibremen.swp.ParserTest.xml" @@ -1,12 +1,12 @@ <?xml version="1.0" encoding="UTF-8"?> -<testsuite xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://maven.apache.org/surefire/maven-surefire-plugin/xsd/surefire-test-report.xsd" name="de.unibremen.swp.ParserTest" time="0" tests="18" errors="8" skipped="0" failures="10"> +<testsuite xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://maven.apache.org/surefire/maven-surefire-plugin/xsd/surefire-test-report.xsd" name="de.unibremen.swp.ParserTest" time="0.008" tests="18" errors="8" skipped="0" failures="10"> <properties> <property name="sun.desktop" value="windows"/> <property name="awt.toolkit" value="sun.awt.windows.WToolkit"/> <property name="java.specification.version" value="11"/> <property name="sun.cpu.isalist" value="amd64"/> <property name="sun.jnu.encoding" value="Cp1252"/> - <property name="java.class.path" value="C:\Users\Administrator\Desktop\Universität Bremen\Semester 5\SWP2\Vorbereitung\Repository\MiniProjekt\target\test-classes;C:\Users\Administrator\Desktop\Universität Bremen\Semester 5\SWP2\Vorbereitung\Repository\MiniProjekt\target\classes;C:\Users\Administrator\.m2\repository\junit\junit\3.8.1\junit-3.8.1.jar;C:\Users\Administrator\.m2\repository\org\junit\jupiter\junit-jupiter-engine\5.6.1\junit-jupiter-engine-5.6.1.jar;C:\Users\Administrator\.m2\repository\org\apiguardian\apiguardian-api\1.1.0\apiguardian-api-1.1.0.jar;C:\Users\Administrator\.m2\repository\org\junit\platform\junit-platform-engine\1.6.1\junit-platform-engine-1.6.1.jar;C:\Users\Administrator\.m2\repository\org\opentest4j\opentest4j\1.2.0\opentest4j-1.2.0.jar;C:\Users\Administrator\.m2\repository\org\junit\platform\junit-platform-commons\1.6.1\junit-platform-commons-1.6.1.jar;C:\Users\Administrator\.m2\repository\org\junit\jupiter\junit-jupiter-api\5.6.1\junit-jupiter-api-5.6.1.jar;"/> + <property name="java.class.path" value="C:\Users\Administrator\Desktop\Universität Bremen\Semester 5\SWP2\Vorbereitung\Repository\miniprojekt2020\übung1\target\test-classes;C:\Users\Administrator\Desktop\Universität Bremen\Semester 5\SWP2\Vorbereitung\Repository\miniprojekt2020\übung1\target\classes;C:\Users\Administrator\.m2\repository\junit\junit\3.8.1\junit-3.8.1.jar;C:\Users\Administrator\.m2\repository\org\junit\jupiter\junit-jupiter-engine\5.6.1\junit-jupiter-engine-5.6.1.jar;C:\Users\Administrator\.m2\repository\org\apiguardian\apiguardian-api\1.1.0\apiguardian-api-1.1.0.jar;C:\Users\Administrator\.m2\repository\org\junit\platform\junit-platform-engine\1.6.1\junit-platform-engine-1.6.1.jar;C:\Users\Administrator\.m2\repository\org\opentest4j\opentest4j\1.2.0\opentest4j-1.2.0.jar;C:\Users\Administrator\.m2\repository\org\junit\platform\junit-platform-commons\1.6.1\junit-platform-commons-1.6.1.jar;C:\Users\Administrator\.m2\repository\org\junit\jupiter\junit-jupiter-api\5.6.1\junit-jupiter-api-5.6.1.jar;"/> <property name="java.vm.vendor" value="AdoptOpenJDK"/> <property name="sun.arch.data.model" value="64"/> <property name="user.variant" value=""/> @@ -17,9 +17,9 @@ <property name="sun.java.launcher" value="SUN_STANDARD"/> <property name="user.country" value="DE"/> <property name="sun.boot.library.path" value="C:\Program Files\AdoptOpenJDK\jdk-11.0.8.10-hotspot\bin"/> - <property name="sun.java.command" value="C:\Users\ADMINI~1\AppData\Local\Temp\surefire16384117284068919217\surefirebooter6360847745344186146.jar C:\Users\Administrator\AppData\Local\Temp\surefire16384117284068919217 2020-10-28T22-13-34_783-jvmRun1 surefire12350635713470639493tmp surefire_01285077207227050327tmp"/> + <property name="sun.java.command" value="C:\Users\ADMINI~1\AppData\Local\Temp\surefire13874946890087837961\surefirebooter5134790969064718219.jar C:\Users\Administrator\AppData\Local\Temp\surefire13874946890087837961 2020-10-28T23-40-03_390-jvmRun1 surefire6103472893634614880tmp surefire_05194153551236232086tmp"/> <property name="jdk.debug" value="release"/> - <property name="surefire.test.class.path" value="C:\Users\Administrator\Desktop\Universität Bremen\Semester 5\SWP2\Vorbereitung\Repository\MiniProjekt\target\test-classes;C:\Users\Administrator\Desktop\Universität Bremen\Semester 5\SWP2\Vorbereitung\Repository\MiniProjekt\target\classes;C:\Users\Administrator\.m2\repository\junit\junit\3.8.1\junit-3.8.1.jar;C:\Users\Administrator\.m2\repository\org\junit\jupiter\junit-jupiter-engine\5.6.1\junit-jupiter-engine-5.6.1.jar;C:\Users\Administrator\.m2\repository\org\apiguardian\apiguardian-api\1.1.0\apiguardian-api-1.1.0.jar;C:\Users\Administrator\.m2\repository\org\junit\platform\junit-platform-engine\1.6.1\junit-platform-engine-1.6.1.jar;C:\Users\Administrator\.m2\repository\org\opentest4j\opentest4j\1.2.0\opentest4j-1.2.0.jar;C:\Users\Administrator\.m2\repository\org\junit\platform\junit-platform-commons\1.6.1\junit-platform-commons-1.6.1.jar;C:\Users\Administrator\.m2\repository\org\junit\jupiter\junit-jupiter-api\5.6.1\junit-jupiter-api-5.6.1.jar;"/> + <property name="surefire.test.class.path" value="C:\Users\Administrator\Desktop\Universität Bremen\Semester 5\SWP2\Vorbereitung\Repository\miniprojekt2020\übung1\target\test-classes;C:\Users\Administrator\Desktop\Universität Bremen\Semester 5\SWP2\Vorbereitung\Repository\miniprojekt2020\übung1\target\classes;C:\Users\Administrator\.m2\repository\junit\junit\3.8.1\junit-3.8.1.jar;C:\Users\Administrator\.m2\repository\org\junit\jupiter\junit-jupiter-engine\5.6.1\junit-jupiter-engine-5.6.1.jar;C:\Users\Administrator\.m2\repository\org\apiguardian\apiguardian-api\1.1.0\apiguardian-api-1.1.0.jar;C:\Users\Administrator\.m2\repository\org\junit\platform\junit-platform-engine\1.6.1\junit-platform-engine-1.6.1.jar;C:\Users\Administrator\.m2\repository\org\opentest4j\opentest4j\1.2.0\opentest4j-1.2.0.jar;C:\Users\Administrator\.m2\repository\org\junit\platform\junit-platform-commons\1.6.1\junit-platform-commons-1.6.1.jar;C:\Users\Administrator\.m2\repository\org\junit\jupiter\junit-jupiter-api\5.6.1\junit-jupiter-api-5.6.1.jar;"/> <property name="sun.cpu.endian" value="little"/> <property name="user.home" value="C:\Users\Administrator"/> <property name="user.language" value="de"/> @@ -27,13 +27,13 @@ <property name="java.version.date" value="2020-07-14"/> <property name="java.home" value="C:\Program Files\AdoptOpenJDK\jdk-11.0.8.10-hotspot"/> <property name="file.separator" value="\"/> - <property name="basedir" value="C:\Users\Administrator\Desktop\Universität Bremen\Semester 5\SWP2\Vorbereitung\Repository\MiniProjekt"/> + <property name="basedir" value="C:\Users\Administrator\Desktop\Universität Bremen\Semester 5\SWP2\Vorbereitung\Repository\miniprojekt2020\übung1"/> <property name="java.vm.compressedOopsMode" value="32-bit"/> <property name="line.separator" value=" "/> <property name="java.specification.name" value="Java Platform API Specification"/> <property name="java.vm.specification.vendor" value="Oracle Corporation"/> <property name="java.awt.graphicsenv" value="sun.awt.Win32GraphicsEnvironment"/> - <property name="surefire.real.class.path" value="C:\Users\ADMINI~1\AppData\Local\Temp\surefire16384117284068919217\surefirebooter6360847745344186146.jar"/> + <property name="surefire.real.class.path" value="C:\Users\ADMINI~1\AppData\Local\Temp\surefire13874946890087837961\surefirebooter5134790969064718219.jar"/> <property name="user.script" value=""/> <property name="sun.management.compiler" value="HotSpot 64-Bit Tiered Compilers"/> <property name="java.runtime.version" value="11.0.8+10"/> @@ -48,7 +48,7 @@ <property name="java.vendor.url.bug" value="https://github.com/AdoptOpenJDK/openjdk-support/issues"/> <property name="java.io.tmpdir" value="C:\Users\ADMINI~1\AppData\Local\Temp\"/> <property name="java.version" value="11.0.8"/> - <property name="user.dir" value="C:\Users\Administrator\Desktop\Universität Bremen\Semester 5\SWP2\Vorbereitung\Repository\MiniProjekt"/> + <property name="user.dir" value="C:\Users\Administrator\Desktop\Universität Bremen\Semester 5\SWP2\Vorbereitung\Repository\miniprojekt2020\übung1"/> <property name="os.arch" value="amd64"/> <property name="java.vm.specification.name" value="Java Virtual Machine Specification"/> <property name="java.awt.printerjob" value="sun.awt.windows.WPrinterJob"/> @@ -70,7 +70,7 @@ at de.unibremen.swp.ParserTest$CSV.readFromExampleFile(ParserTest.java:31) </error> </testcase> - <testcase name="writeNullParameter" classname="de.unibremen.swp.ParserTest$JSON" time="0"> + <testcase name="writeNullParameter" classname="de.unibremen.swp.ParserTest$JSON" time="0.001"> <failure message="Unexpected exception type thrown ==> expected: <java.lang.NullPointerException> but was: <java.lang.UnsupportedOperationException>" type="org.opentest4j.AssertionFailedError"><![CDATA[org.opentest4j.AssertionFailedError: Unexpected exception type thrown ==> expected: <java.lang.NullPointerException> but was: <java.lang.UnsupportedOperationException> at de.unibremen.swp.ParserTest$JSON.writeNullParameter(ParserTest.java:555) Caused by: java.lang.UnsupportedOperationException @@ -156,7 +156,7 @@ Caused by: java.lang.UnsupportedOperationException at de.unibremen.swp.ParserTest$CSV.writeDifferentWithSameId(ParserTest.java:282) ]]></failure> </testcase> - <testcase name="writeWithInvalidFriends" classname="de.unibremen.swp.ParserTest$CSV" time="0"> + <testcase name="writeWithInvalidFriends" classname="de.unibremen.swp.ParserTest$CSV" time="0.001"> <failure message="Unexpected exception type thrown ==> expected: <java.lang.IllegalArgumentException> but was: <java.lang.UnsupportedOperationException>" type="org.opentest4j.AssertionFailedError"><![CDATA[org.opentest4j.AssertionFailedError: Unexpected exception type thrown ==> expected: <java.lang.IllegalArgumentException> but was: <java.lang.UnsupportedOperationException> at de.unibremen.swp.ParserTest$CSV.writeWithInvalidFriends(ParserTest.java:312) Caused by: java.lang.UnsupportedOperationException diff --git "a/\303\274bung1/target/surefire-reports/de.unibremen.swp.ConverterTest.txt" "b/\303\274bung1/target/surefire-reports/de.unibremen.swp.ConverterTest.txt" index 6a3bb70d10d59dd498054c2d02faeef94da1e63f..701836b7e7549af2d0f77216b3ad81491b3cb8fb 100644 --- "a/\303\274bung1/target/surefire-reports/de.unibremen.swp.ConverterTest.txt" +++ "b/\303\274bung1/target/surefire-reports/de.unibremen.swp.ConverterTest.txt" @@ -1,12 +1,12 @@ ------------------------------------------------------------------------------- Test set: de.unibremen.swp.ConverterTest ------------------------------------------------------------------------------- -Tests run: 2, Failures: 0, Errors: 2, Skipped: 0, Time elapsed: 0.031 s <<< FAILURE! - in de.unibremen.swp.ConverterTest -CSVToJSON Time elapsed: 0.031 s <<< ERROR! +Tests run: 2, Failures: 0, Errors: 2, Skipped: 0, Time elapsed: 0.037 s <<< FAILURE! - in de.unibremen.swp.ConverterTest +CSVToJSON Time elapsed: 0.027 s <<< ERROR! java.lang.UnsupportedOperationException at de.unibremen.swp.ConverterTest.CSVToJSON(ConverterTest.java:26) -JSONToCSV Time elapsed: 0 s <<< ERROR! +JSONToCSV Time elapsed: 0.001 s <<< ERROR! java.lang.UnsupportedOperationException at de.unibremen.swp.ConverterTest.JSONToCSV(ConverterTest.java:132) diff --git "a/\303\274bung1/target/surefire-reports/de.unibremen.swp.ParserTest.txt" "b/\303\274bung1/target/surefire-reports/de.unibremen.swp.ParserTest.txt" index 47c0fd9858ce7dd2189f6d07c1fe6d071884a456..b73e101b58c81e9e06c96305af91aa1f84686d0a 100644 --- "a/\303\274bung1/target/surefire-reports/de.unibremen.swp.ParserTest.txt" +++ "b/\303\274bung1/target/surefire-reports/de.unibremen.swp.ParserTest.txt" @@ -1,12 +1,12 @@ ------------------------------------------------------------------------------- Test set: de.unibremen.swp.ParserTest ------------------------------------------------------------------------------- -Tests run: 18, Failures: 10, Errors: 8, Skipped: 0, Time elapsed: 0 s <<< FAILURE! - in de.unibremen.swp.ParserTest +Tests run: 18, Failures: 10, Errors: 8, Skipped: 0, Time elapsed: 0.008 s <<< FAILURE! - in de.unibremen.swp.ParserTest readFromExampleFile Time elapsed: 0 s <<< ERROR! java.lang.UnsupportedOperationException at de.unibremen.swp.ParserTest$JSON.readFromExampleFile(ParserTest.java:355) -writeNullParameter Time elapsed: 0 s <<< FAILURE! +writeNullParameter Time elapsed: 0.001 s <<< FAILURE! org.opentest4j.AssertionFailedError: Unexpected exception type thrown ==> expected: <java.lang.NullPointerException> but was: <java.lang.UnsupportedOperationException> at de.unibremen.swp.ParserTest$JSON.writeNullParameter(ParserTest.java:555) Caused by: java.lang.UnsupportedOperationException @@ -64,7 +64,7 @@ Caused by: java.lang.UnsupportedOperationException at de.unibremen.swp.ParserTest$CSV.lambda$writeNullParameter$9(ParserTest.java:325) at de.unibremen.swp.ParserTest$CSV.writeNullParameter(ParserTest.java:324) -writeWithInvalidFriends Time elapsed: 0 s <<< FAILURE! +writeWithInvalidFriends Time elapsed: 0.001 s <<< FAILURE! org.opentest4j.AssertionFailedError: Unexpected exception type thrown ==> expected: <java.lang.IllegalArgumentException> but was: <java.lang.UnsupportedOperationException> at de.unibremen.swp.ParserTest$CSV.writeWithInvalidFriends(ParserTest.java:312) Caused by: java.lang.UnsupportedOperationException diff --git "a/\303\274bung1/target/test-classes/de/unibremen/swp/ConverterTest.class" "b/\303\274bung1/target/test-classes/de/unibremen/swp/ConverterTest.class" index 3d39ba842dc1ce5beef1a7f10905bad35bb61411..ae9568b1e9d777cd5e7507e15db626a7237f65ce 100644 Binary files "a/\303\274bung1/target/test-classes/de/unibremen/swp/ConverterTest.class" and "b/\303\274bung1/target/test-classes/de/unibremen/swp/ConverterTest.class" differ diff --git "a/\303\274bung1/target/test-classes/de/unibremen/swp/ParserTest$CSV.class" "b/\303\274bung1/target/test-classes/de/unibremen/swp/ParserTest$CSV.class" index a77e3e3d4dbc6152d961e1ca3051e0aa492cee02..ad975cb68794608e48b414fadd92d8b4d7840a83 100644 Binary files "a/\303\274bung1/target/test-classes/de/unibremen/swp/ParserTest$CSV.class" and "b/\303\274bung1/target/test-classes/de/unibremen/swp/ParserTest$CSV.class" differ diff --git "a/\303\274bung1/target/test-classes/de/unibremen/swp/ParserTest$JSON.class" "b/\303\274bung1/target/test-classes/de/unibremen/swp/ParserTest$JSON.class" index d558c64725383c679773151793315cbb64eaf32c..979b39a019c6568d3a5b0f307dd9f87a7f9deba0 100644 Binary files "a/\303\274bung1/target/test-classes/de/unibremen/swp/ParserTest$JSON.class" and "b/\303\274bung1/target/test-classes/de/unibremen/swp/ParserTest$JSON.class" differ diff --git "a/\303\274bung1/target/test-classes/de/unibremen/swp/ParserTest.class" "b/\303\274bung1/target/test-classes/de/unibremen/swp/ParserTest.class" index 0506e5f2daf41d8043c1523b1e4b0083d9af12fb..ab01f6578125fe76172ee9fa09e194a3df11b8e8 100644 Binary files "a/\303\274bung1/target/test-classes/de/unibremen/swp/ParserTest.class" and "b/\303\274bung1/target/test-classes/de/unibremen/swp/ParserTest.class" differ diff --git "a/\303\274bung1/uebung1.iml" "b/\303\274bung1/uebung1.iml" index 3a8eafeba0c37b5ed6bd27acfd61088374b09f31..39f4bcaefa1b8f2913a4c362e1b2a762f121b4bb 100644 --- "a/\303\274bung1/uebung1.iml" +++ "b/\303\274bung1/uebung1.iml" @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="UTF-8"?> <module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4"> - <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8"> + <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_11"> <output url="file://$MODULE_DIR$/target/classes" /> <output-test url="file://$MODULE_DIR$/target/test-classes" /> <content url="file://$MODULE_DIR$"> @@ -19,5 +19,16 @@ <orderEntry type="library" scope="TEST" name="Maven: org.opentest4j:opentest4j:1.2.0" level="project" /> <orderEntry type="library" scope="TEST" name="Maven: org.junit.platform:junit-platform-commons:1.6.1" level="project" /> <orderEntry type="library" scope="TEST" name="Maven: org.junit.jupiter:junit-jupiter-api:5.6.1" level="project" /> + <orderEntry type="library" name="Maven: com.opencsv:opencsv:5.1" level="project" /> + <orderEntry type="library" name="Maven: org.apache.commons:commons-lang3:3.9" level="project" /> + <orderEntry type="library" name="Maven: org.apache.commons:commons-text:1.8" level="project" /> + <orderEntry type="library" name="Maven: commons-beanutils:commons-beanutils:1.9.4" level="project" /> + <orderEntry type="library" name="Maven: commons-logging:commons-logging:1.2" level="project" /> + <orderEntry type="library" name="Maven: commons-collections:commons-collections:3.2.2" level="project" /> + <orderEntry type="library" name="Maven: org.apache.commons:commons-collections4:4.4" level="project" /> + <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-databind:2.10.3" level="project" /> + <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.10.3" level="project" /> + <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-core:2.10.3" level="project" /> + <orderEntry type="library" name="Maven: com.voodoodyne.jackson.jsog:jackson-jsog:1.1.1" level="project" /> </component> </module> \ No newline at end of file