@Override public Command getCommand() { // edit command final ArrayList<Command> changes = new ArrayList<>(); super.addEditCommands.accept(changes); if (productOwnerProperty().get() != modelWrapper.get().getProductOwner()) { changes.add( new EditCommand<>(modelWrapper.get(), "productOwner", productOwnerProperty().get())); } if (scrumMasterProperty().get() != modelWrapper.get().getScrumMaster()) { changes.add( new EditCommand<>(modelWrapper.get(), "scrumMaster", scrumMasterProperty().get())); } if (!(teamMembersProperty().get().containsAll(modelWrapper.get().getTeamMembers()) && modelWrapper.get().getTeamMembers().containsAll(teamMembersProperty().get()))) { // BEWARE: magic ArrayList<Person> teamMembers = new ArrayList<>(); teamMembers.addAll(teamMembersProperty().get()); changes.add(new EditCommand<>(modelWrapper.get(), "teamMembers", teamMembers)); } if (!(devTeamProperty().get().containsAll(modelWrapper.get().getDevTeam()) && modelWrapper.get().getDevTeam().containsAll(devTeamProperty().get()))) { // BEWARE: magic ArrayList<Person> devTeam = new ArrayList<>(); devTeam.addAll(devTeamProperty().get()); changes.add(new EditCommand<>(modelWrapper.get(), "devTeam", devTeam)); } final ArrayList<Person> newMembers = new ArrayList<>(teamMembersProperty().get()); newMembers.removeAll(modelWrapper.get().observableTeamMembers()); final ArrayList<Person> oldMembers = new ArrayList<>(modelWrapper.get().observableTeamMembers()); oldMembers.removeAll(teamMembersProperty().get()); // Loop through all the new members and add a command to set their team // Set the person's team field to this team changes.addAll( newMembers .stream() .map(person -> new EditCommand<>(person, "team", modelWrapper.get())) .collect(Collectors.toList())); // Loop through all the old members and add a command to remove their team // Set the person's team field to null, since they're no longer in the team changes.addAll( oldMembers .stream() .map(person -> new EditCommand<>(person, "team", null)) .collect(Collectors.toList())); return new CompoundCommand("Edit Team", changes); }
private Segment createSegmentFromEdges(long edgeId, long segmentId, boolean isEdgeOrigin) { double length = 0.0; Segment seg = null; try { List<Edge> subset = null; seg = db.ReadSegment(segmentId); ArrayList<Edge> edges = db.ReadEdges(segmentId); Edge edge = null; if (!edges.isEmpty()) { if (isEdgeOrigin) { edge = edges .stream() .filter( (Edge e) -> { return e.mOrigin == edgeId; }) .findFirst() .get(); } else { edge = edges .stream() .filter( (Edge e) -> { return e.mDestination == edgeId; }) .findFirst() .get(); } int index = edges.indexOf(edge); subset = edges.subList(index, edges.size()); for (Edge ed : subset) { length = +ed.mLength; } } long origin, destination; origin = (isEdgeOrigin ? edgeId : seg.mOrigin); destination = (isEdgeOrigin ? seg.mDestination : edgeId); Segment s = new Segment(nextSegId++, length, seg.mWayId, origin, destination); return s; } catch (SQLException e) { System.err.println("Error getting segmentid from method modelNodeToSegment"); e.printStackTrace(); } return null; }
public static void main(String[] args) { Scanner input = new Scanner(System.in); ArrayList<String> list = new ArrayList<>(Arrays.asList(input.nextLine().split(" "))); ArrayList<String> filter = new ArrayList<>(list.stream().filter(p -> p.length() > 3).collect(Collectors.toList())); if (filter.size() != 0) { for (String str : filter) { System.out.print(str + " "); } } else { System.out.println("(empty)"); } }
private ArrayList<FakeNode> getNeighbours(long id) { ArrayList<FakeNode> retNodes = new ArrayList<>(); ArrayList<Segment> neighbours = this.segments .stream() .filter( (Segment s) -> { return s.mOrigin == id; }) .collect(Collectors.toCollection(ArrayList<Segment>::new)); neighbours.addAll( this.fakeSegments .stream() .filter( (Segment s) -> { return s.mOrigin == id; }) .collect(Collectors.toCollection(ArrayList<Segment>::new))); FakeNode node; for (Segment s : neighbours) { if (fakeNodes.containsKey(s.mDestination)) { node = fakeNodes.get(s.mDestination); } else { node = new FakeNode(nodes.get(s.mDestination)); fakeNodes.put(s.mDestination, node); } ArrayList<CostFunction> functions = costs .stream() .filter( (CostFunction c) -> { return c.getSegmentId() == s.mId; }) .collect(Collectors.toCollection(ArrayList<CostFunction>::new)); functions.addAll( fakeCosts .stream() .filter( (CostFunction c) -> { return c.getSegmentId() == s.mId; }) .collect(Collectors.toCollection(ArrayList<CostFunction>::new))); node.node.cost = functions.get(0); retNodes.add(fakeNodes.get(s.mDestination)); } return retNodes; }
@Test public void testCollectors() { ArrayList<Person> people = new ArrayList<>(); ArrayList<Integer> things = new ArrayList<>(); ArrayList<Employee> employees = new ArrayList<>(); ArrayList<Student> students = new ArrayList<>(); // Accumulate names into a List List<String> list = people.stream().map(Person::getName).collect(Collectors.toList()); // Accumulate names into a TreeSet Set<String> list2 = people.stream().map(Person::getName).collect(Collectors.toCollection(TreeSet::new)); // Convert elements to strings and concatenate them, separated by commas String joined = things.stream().map(Object::toString).collect(Collectors.joining(", ")); // Find highest-paid employee Optional<Employee> highestPaid = employees.stream().collect(Collectors.maxBy(Comparator.comparingInt(Employee::getSalary))); // Group employees by department Map<Department, List<Employee>> byDept = employees.stream().collect(Collectors.groupingBy(Employee::getDepartment)); // Find highest-paid employee by department Map<Department, Optional<Employee>> highestPaidByDept = employees .stream() .collect( Collectors.groupingBy( Employee::getDepartment, Collectors.maxBy(Comparator.comparingInt(Employee::getSalary)))); // Partition students into passing and failing Map<Boolean, List<Student>> passingFailing = students.stream().collect(Collectors.partitioningBy(s -> s.getGrade() >= PASS_THRESHOLD)); }