List of usage examples for java.util List spliterator
@Override
default Spliterator<E> spliterator()
From source file:net.hamnaberg.json.Item.java
public static Item create(Optional<URI> href, Iterable<Property> properties, List<Link> links) { ObjectNode node = JsonNodeFactory.instance.objectNode(); href.ifPresent(uri -> node.put("href", uri.toString())); if (!Iterables.isEmpty(properties)) { node.set("data", StreamSupport.stream(properties.spliterator(), false).map(Extended::asJson) .collect(JsonNodeFactory.instance::arrayNode, ArrayNode::add, ArrayNode::addAll)); }//from ww w .java 2 s.c o m if (!Iterables.isEmpty(links)) { node.set("links", StreamSupport.stream(links.spliterator(), false).map(Extended::asJson) .collect(JsonNodeFactory.instance::arrayNode, ArrayNode::add, ArrayNode::addAll)); } return new Item(node); }
From source file:org.eclipse.hawkbit.repository.jpa.TargetManagementTest.java
@Test @WithUser(allSpPermissions = true)/*w w w . j a v a 2s .c o m*/ @Description("Create multiple targets as bulk operation and delete them in bulk.") @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 101), @Expect(type = TargetUpdatedEvent.class, count = 100), @Expect(type = TargetDeletedEvent.class, count = 51) }) public void bulkTargetCreationAndDelete() throws Exception { final String myCtrlID = "myCtrlID"; List<Target> firstList = testdataFactory.createTargets(100, myCtrlID, "first description"); final Target extra = testdataFactory.createTarget("myCtrlID-00081XX"); final Iterable<JpaTarget> allFound = targetRepository.findAll(); assertThat(Long.valueOf(firstList.size())).as("List size of targets") .isEqualTo(firstList.spliterator().getExactSizeIfKnown()); assertThat(Long.valueOf(firstList.size() + 1)).as("LastModifiedAt compared with saved lastModifiedAt") .isEqualTo(allFound.spliterator().getExactSizeIfKnown()); // change the objects and save to again to trigger a change on // lastModifiedAt firstList = firstList.stream() .map(t -> targetManagement.update( entityFactory.target().update(t.getControllerId()).name(t.getName().concat("\tchanged")))) .collect(Collectors.toList()); // verify that all entries are found _founds: for (final Target foundTarget : allFound) { for (final Target changedTarget : firstList) { if (changedTarget.getControllerId().equals(foundTarget.getControllerId())) { assertThat(changedTarget.getDescription()) .as("Description of changed target compared with description saved target") .isEqualTo(foundTarget.getDescription()); assertThat(changedTarget.getName()) .as("Name of changed target starts with name of saved target") .startsWith(foundTarget.getName()); assertThat(changedTarget.getName()).as("Name of changed target ends with 'changed'") .endsWith("changed"); assertThat(changedTarget.getCreatedAt()).as("CreatedAt compared with saved createdAt") .isEqualTo(foundTarget.getCreatedAt()); assertThat(changedTarget.getLastModifiedAt()).as("LastModifiedAt compared with saved createdAt") .isNotEqualTo(changedTarget.getCreatedAt()); continue _founds; } } if (!foundTarget.getControllerId().equals(extra.getControllerId())) { fail("The controllerId of the found target is not equal to the controllerId of the saved target"); } } targetManagement.deleteByControllerID(extra.getControllerId()); final int numberToDelete = 50; final Collection<Target> targetsToDelete = firstList.subList(0, numberToDelete); final Target[] deletedTargets = Iterables.toArray(targetsToDelete, Target.class); final List<Long> targetsIdsToDelete = targetsToDelete.stream().map(Target::getId) .collect(Collectors.toList()); targetManagement.delete(targetsIdsToDelete); final List<Target> targetsLeft = targetManagement.findAll(PageRequest.of(0, 200)).getContent(); assertThat(firstList.spliterator().getExactSizeIfKnown() - numberToDelete).as("Size of split list") .isEqualTo(targetsLeft.spliterator().getExactSizeIfKnown()); assertThat(targetsLeft).as("Not all undeleted found").doesNotContain(deletedTargets); }