hw3: prototype completed
This commit is contained in:
14
hw3/src/strategy/SortByDate.java
Normal file
14
hw3/src/strategy/SortByDate.java
Normal file
@@ -0,0 +1,14 @@
|
||||
package strategy;
|
||||
|
||||
import model.Photo;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
public class SortByDate implements SortingStrategy<Photo> {
|
||||
@Override
|
||||
public List<Photo> sort(List<Photo> photos) {
|
||||
photos.sort(Comparator.comparing(Photo::getDateAdded));
|
||||
return photos;
|
||||
}
|
||||
}
|
||||
14
hw3/src/strategy/SortByName.java
Normal file
14
hw3/src/strategy/SortByName.java
Normal file
@@ -0,0 +1,14 @@
|
||||
package strategy;
|
||||
|
||||
import model.Photo;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
public class SortByName implements SortingStrategy<Photo> {
|
||||
@Override
|
||||
public List<Photo> sort(List<Photo> photos) {
|
||||
photos.sort(Comparator.comparing(Photo::getName));
|
||||
return photos;
|
||||
}
|
||||
}
|
||||
14
hw3/src/strategy/SortBySize.java
Normal file
14
hw3/src/strategy/SortBySize.java
Normal file
@@ -0,0 +1,14 @@
|
||||
package strategy;
|
||||
|
||||
import model.Photo;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
public class SortBySize implements SortingStrategy<Photo> {
|
||||
@Override
|
||||
public List<Photo> sort(List<Photo> photos) {
|
||||
photos.sort(Comparator.comparing(Photo::getFileSize));
|
||||
return photos;
|
||||
}
|
||||
}
|
||||
7
hw3/src/strategy/SortingStrategy.java
Normal file
7
hw3/src/strategy/SortingStrategy.java
Normal file
@@ -0,0 +1,7 @@
|
||||
package strategy;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface SortingStrategy<T> {
|
||||
List<T> sort(List<T> photos);
|
||||
}
|
||||
Reference in New Issue
Block a user