Search in sources :

Example 1 with DistanceFromOrigin

use of hr.fer.oop.recap2.task2.DistanceFromOrigin 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);
}
Also used : List(java.util.List) PointComparator(hr.fer.oop.recap2.task3.PointComparator) QuadrantPredicate(hr.fer.oop.recap2.task2.QuadrantPredicate) Point(hr.fer.oop.recap2.task2.Point) DistanceFromOrigin(hr.fer.oop.recap2.task2.DistanceFromOrigin) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) DistanceFromOrigin(hr.fer.oop.recap2.task2.DistanceFromOrigin) QuadrantPredicate(hr.fer.oop.recap2.task2.QuadrantPredicate) ArrayList(java.util.ArrayList) Point(hr.fer.oop.recap2.task2.Point) PointComparator(hr.fer.oop.recap2.task3.PointComparator)

Example 2 with DistanceFromOrigin

use of hr.fer.oop.recap2.task2.DistanceFromOrigin 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();
    OptionalDouble avg = list.stream().filter(new QuadrantPredicate(true, false, false, false)).mapToDouble(p -> dist.apply(p)).average();
    avg.ifPresentOrElse(val -> System.out.println("Avg = " + val), () -> System.out.println("No data for selected quadrants"));
}
Also used : List(java.util.List) QuadrantPredicate(hr.fer.oop.recap2.task2.QuadrantPredicate) OptionalDouble(java.util.OptionalDouble) Point(hr.fer.oop.recap2.task2.Point) DistanceFromOrigin(hr.fer.oop.recap2.task2.DistanceFromOrigin) ArrayList(java.util.ArrayList) DistanceFromOrigin(hr.fer.oop.recap2.task2.DistanceFromOrigin) QuadrantPredicate(hr.fer.oop.recap2.task2.QuadrantPredicate) ArrayList(java.util.ArrayList) Point(hr.fer.oop.recap2.task2.Point) OptionalDouble(java.util.OptionalDouble)

Aggregations

DistanceFromOrigin (hr.fer.oop.recap2.task2.DistanceFromOrigin)2 Point (hr.fer.oop.recap2.task2.Point)2 QuadrantPredicate (hr.fer.oop.recap2.task2.QuadrantPredicate)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 PointComparator (hr.fer.oop.recap2.task3.PointComparator)1 OptionalDouble (java.util.OptionalDouble)1 Collectors (java.util.stream.Collectors)1