use of hr.fer.oop.recap2.task3.PointComparator in project Lectures by FER-OOP.
the class MainList method main.
public static void main(String[] args) {
List<Point> list = new ArrayList<>();
list.add(new Point(-5, 12));
list.add(new Point(3, -4));
list.add(new Point(12, 9));
list.add(new Point(3, 4));
list.add(new Point(4, 3));
list.add(new Point(-9, 12));
list.add(new Point(-5, -12));
System.out.println("Original list:\n" + list);
Comparator<Point> comp = new PointComparator();
list.sort(comp);
System.out.println("Sorted by distance:\n" + list);
list.sort(Comparator.naturalOrder());
System.out.println("Sorted by natural order:\n" + list);
}
use of hr.fer.oop.recap2.task3.PointComparator in project Lectures by FER-OOP.
the class Main method main.
public static void main(String[] args) {
List<Point> list = new ArrayList<>();
list.add(new Point(-5, 12));
list.add(new Point(3, -4));
list.add(new Point(12, 9));
list.add(new Point(3, 4));
list.add(new Point(4, 3));
list.add(new Point(-9, 12));
list.add(new Point(-5, -12));
DistanceFromOrigin dist = new DistanceFromOrigin();
List<String> newlist = list.stream().filter(new QuadrantPredicate(true, true, false, true)).sorted(new PointComparator().reversed()).map(p -> String.format("dist(%s) = %.2f", p, dist.apply(p))).collect(Collectors.toList());
System.out.println(newlist);
}
use of hr.fer.oop.recap2.task3.PointComparator in project Lectures by FER-OOP.
the class Main method main.
public static void main(String[] args) {
List<Point> list = new ArrayList<>();
addPoints(list);
Map<Integer, Set<Point>> map = new TreeMap<>();
Comparator<Point> comp = new PointComparator();
comp = comp.thenComparing(Comparator.naturalOrder());
map.put(1, new TreeSet<>(comp));
map.put(2, new TreeSet<>(comp));
map.put(3, new TreeSet<>(comp));
map.put(4, new TreeSet<>(comp));
Function<Point, Integer> quadrantFunction = QuadrantCalculator::quadrant;
for (var point : list) {
int quadrant = quadrantFunction.apply(point);
if (quadrant != 0)
map.get(quadrant).add(point);
}
System.out.println(map);
}
Aggregations