hw2: cleanup

This commit is contained in:
Claudio Maggioni 2022-10-19 13:27:26 +02:00
parent af7c772881
commit 6d56bcc5ce
2 changed files with 9 additions and 33 deletions

View File

@ -22,19 +22,19 @@ public class Main {
/**
* 3 Points
* TODO: Create a public static void function called "transformPeople".
* input: a List from which People are read, called "src";
* a List in which People are inserted, called "dst".
* This function iterates over all the elements of "src" and copies them in the "dst" List.
* If the element in "src" starts with the "z" or "Z" character then in the "dst" list is
* added a Wizard instead of a person. The Wizard's age must be 100 times the person's age.
* Create a public static void function called "transformPeople".
* input: a List from which People are read, called "src";
* a List in which People are inserted, called "dst".
* This function iterates over all the elements of "src" and copies them in the "dst" List.
* If the element in "src" starts with the "z" or "Z" character then in the "dst" list is
* added a Wizard instead of a person. The Wizard's age must be 100 times the person's age.
* <p>
* Remember to use the get-put principle properly.
*/
public static void transformPeople(List<? extends People> src, List<? super People> dst) {
// true -> quelli con la z (lista)
// false -> quelli senza la z (lista)
Map<Boolean, List<People>> startsWithZPartitioned = src.stream().collect(
// true -> list of people whose names start with Z/z
// false -> list of all other people
final Map<Boolean, List<People>> startsWithZPartitioned = src.stream().collect(
Collectors.groupingBy(p -> p.getName().matches("^[zZ].*"))
);

View File

@ -1,24 +0,0 @@
package ch.usi.inf.ajp22;
class First {
void doSomething() {
System.out.println(" I am a class ");
}
}
interface Second {
default void doSomething() {
System.out.println(" I am an interface ");
}
}
public class Third extends First implements Second {
@Override
public void doSomething() {
super.doSomething();
}
public static void main(String[] args) {
Third third = new Third();
third.doSomething();
}
}