Example usage for java.util List forEach

List of usage examples for java.util List forEach

Introduction

In this page you can find the example usage for java.util List forEach.

Prototype

default void forEach(Consumer<? super T> action) 

Source Link

Document

Performs the given action for each element of the Iterable until all elements have been processed or the action throws an exception.

Usage

From source file:io.kamax.mxisd.notification.NotificationManager.java

@Autowired
public NotificationManager(NotificationConfig cfg, List<INotificationHandler> handlers) {
    this.handlers = new HashMap<>();
    handlers.forEach(h -> {
        log.info("Found handler {} for medium {}", h.getId(), h.getMedium());
        String handlerId = cfg.getHandler().getOrDefault(h.getMedium(), "raw");
        if (StringUtils.equals(handlerId, h.getId())) {
            this.handlers.put(h.getMedium(), h);
        }//from  www  .j a  va 2s . c o  m
    });

    log.info("--- Notification handler ---");
    this.handlers.forEach((k, v) -> log.info("\tHandler for {}: {}", k, v.getId()));
}

From source file:cop.raml.processor.Resource.java

public void removeUriParameters(List<String> names) {
    names.forEach(uriParameters::remove);
}

From source file:edu.usu.sdl.opencatalog.web.action.TestAction.java

@HandlesEvent("TestList")
public Resolution testList() {
    List<LookupModel> lookups = new ArrayList<>();

    List<Test> test = service.findLookup(Test.class);
    test.forEach(t -> {
        LookupModel lookup = new LookupModel();
        lookup.setCode(t.getCode());//  w w  w.  java 2  s.c o m
        lookup.setDescription(t.getDescription());
        lookups.add(lookup);
    });
    return streamResults(lookups);
}

From source file:com.github.achatain.catalog.servlet.ItemServlet.java

@Override
protected void doGet(final HttpServletRequest req, final HttpServletResponse resp)
        throws ServletException, IOException {
    final String userId = getUserId(req);
    final String colId = extractCollectionIdFromRequest(req);

    LOG.info(format("List all items in the collection [%s]", colId));

    final List<ItemDto> items = itemService.listItems(userId, colId);

    items.forEach(item -> {
        final String href = format("%s%s", appendIfMissing(req.getRequestURL().toString(), "/"), item.getId());
        item.addLink(Link.create().withRel("self").withMethod(Link.Method.GET).withHref(href).build());
        item.addLink(Link.create().withRel("edit").withMethod(Link.Method.PUT).withHref(href).build());
        item.addLink(Link.create().withRel("delete").withMethod(Link.Method.DELETE).withHref(href).build());
    });/* www.  j  a  v a2s . c o  m*/

    sendResponse(resp, items);
}

From source file:com.intuit.quickbase.MergeStatService.java

public void retrieveCountryPopulationList() {

    DBStatService dbStatService = new DBStatService();
    List<Pair<String, Integer>> dbList = dbStatService.GetCountryPopulations();

    ConcreteStatService conStatService = new ConcreteStatService();
    List<Pair<String, Integer>> apiList = conStatService.GetCountryPopulations();

    //Use of Predicate Interface
    Predicate<Pair<String, Integer>> pred = (pair) -> pair != null;

    if (apiList != null) {
        // Converting the keys of each element in the API list to lowercase
        List<Pair<String, Integer>> modifiedAPIList = apiList.stream().filter(pred)
                .map(p -> new ImmutablePair<String, Integer>(p.getKey().toLowerCase(), p.getValue()))
                .collect(Collectors.toList());
        //modifiedAPIList.forEach(pair -> System.out.println("key: " + pair.getLeft() + ": value: " + pair.getRight()));                      

        if (dbList != null) {
            // Merge two list and remove duplicates
            Collection<Pair<String, Integer>> result = Stream.concat(dbList.stream(), modifiedAPIList.stream())
                    .filter(pred)/*from   w  w w  .  j a v a2s  . co  m*/
                    .collect(Collectors.toMap(Pair::getLeft, p -> p, (p, q) -> p, LinkedHashMap::new)).values();

            // Need to Convert collection to List
            List<Pair<String, Integer>> merge = new ArrayList<>(result);
            merge.forEach(pair -> System.out.println("key: " + pair.getKey() + ": value: " + pair.getValue()));

        } else {
            System.out.println("Country list retrieved form database is empty");
        }
    } else {
        System.out.println("Country list retrieved form API is empty");
    }

    //            if(apiList != null) {
    //                Iterator itr = apiList.iterator();
    //                for(Pair<String, Integer> pair : apiList){                    
    //                    //System.out.println("key: " + pair.getLeft() + ": value: " + pair.getRight());
    //                }                
    //            }    

}

From source file:org.artifactory.ui.rest.service.admin.configuration.repositories.replication.ReplicationConfigService.java

/**
 * Cleans up properties left over from a local replication in the relevant repo.
 * Use only when deleting repos and when a url changes in a replication config.
 *//*  w  w w . j  a v  a  2 s  .c o m*/
public void cleanupLocalReplications(List<LocalReplicationDescriptor> toRemove) {
    toRemove.forEach(addonsManager.addonByType(ReplicationAddon.class)::cleanupLocalReplicationProperties);
}

From source file:net.minecraftforge.registries.GameData.java

@SuppressWarnings({ "unchecked", "rawtypes" })
public static Multimap<ResourceLocation, ResourceLocation> injectSnapshot(
        Map<ResourceLocation, ForgeRegistry.Snapshot> snapshot, boolean injectFrozenData,
        boolean isLocalWorld) {
    FMLLog.log.info("Injecting existing registry data into this {} instance",
            FMLCommonHandler.instance().getEffectiveSide().isServer() ? "server" : "client");
    RegistryManager.ACTIVE.registries.forEach((name, reg) -> reg.validateContent(name));
    RegistryManager.ACTIVE.registries.forEach((name, reg) -> reg.dump(name));
    RegistryManager.ACTIVE.registries.forEach((name, reg) -> reg.resetDelegates());

    List<ResourceLocation> missingRegs = snapshot.keySet().stream()
            .filter(name -> !RegistryManager.ACTIVE.registries.containsKey(name)).collect(Collectors.toList());
    if (missingRegs.size() > 0) {
        String text = "Forge Mod Loader detected missing/unknown registrie(s).\n\n" + "There are "
                + missingRegs.size() + " missing registries in this save.\n"
                + "If you continue the missing registries will get removed.\n"
                + "This may cause issues, it is advised that you create a world backup before continuing.\n\n"
                + "Missing Registries:\n";

        for (ResourceLocation s : missingRegs)
            text += s.toString() + "\n";

        if (!StartupQuery.confirm(text))
            StartupQuery.abort();//from w  w  w .j av  a2 s .  c o m
    }

    RegistryManager STAGING = new RegistryManager("STAGING");

    final Map<ResourceLocation, Map<ResourceLocation, Integer[]>> remaps = Maps.newHashMap();
    final LinkedHashMap<ResourceLocation, Map<ResourceLocation, Integer>> missing = Maps.newLinkedHashMap();
    // Load the snapshot into the "STAGING" registry
    snapshot.forEach((key, value) -> {
        final Class<? extends IForgeRegistryEntry> clazz = RegistryManager.ACTIVE.getSuperType(key);
        remaps.put(key, Maps.newLinkedHashMap());
        missing.put(key, Maps.newHashMap());
        loadPersistentDataToStagingRegistry(RegistryManager.ACTIVE, STAGING, remaps.get(key), missing.get(key),
                key, value, clazz);
    });

    snapshot.forEach((key, value) -> {
        value.dummied.forEach(dummy -> {
            Map<ResourceLocation, Integer> m = missing.get(key);
            ForgeRegistry<?> reg = STAGING.getRegistry(key);

            // Currently missing locally, we just inject and carry on
            if (m.containsKey(dummy)) {
                if (reg.markDummy(dummy, m.get(dummy)))
                    m.remove(dummy);
            } else if (isLocalWorld) {
                if (ForgeRegistry.DEBUG)
                    FMLLog.log.debug("Registry {}: Resuscitating dummy entry {}", key, dummy);
            } else {
                // The server believes this is a dummy block identity, but we seem to have one locally. This is likely a conflict
                // in mod setup - Mark this entry as a dummy
                int id = reg.getID(dummy);
                FMLLog.log.warn(
                        "Registry {}: The ID {} is currently locally mapped - it will be replaced with a dummy for this session",
                        key, id);
                reg.markDummy(dummy, id);
            }
        });
    });

    int count = missing.values().stream().mapToInt(Map::size).sum();
    if (count > 0) {
        FMLLog.log.debug("There are {} mappings missing - attempting a mod remap", count);
        Multimap<ResourceLocation, ResourceLocation> defaulted = ArrayListMultimap.create();
        Multimap<ResourceLocation, ResourceLocation> failed = ArrayListMultimap.create();

        missing.entrySet().stream().filter(e -> e.getValue().size() > 0).forEach(m -> {
            ResourceLocation name = m.getKey();
            ForgeRegistry<?> reg = STAGING.getRegistry(name);
            RegistryEvent.MissingMappings<?> event = reg.getMissingEvent(name, m.getValue());
            MinecraftForge.EVENT_BUS.post(event);

            List<MissingMappings.Mapping<?>> lst = event.getAllMappings().stream()
                    .filter(e -> e.getAction() == MissingMappings.Action.DEFAULT).collect(Collectors.toList());
            if (!lst.isEmpty()) {
                FMLLog.log.error("Unidentified mapping from registry {}", name);
                lst.forEach(map -> {
                    FMLLog.log.error("    {}: {}", map.key, map.id);
                    if (!isLocalWorld)
                        defaulted.put(name, map.key);
                });
            }
            event.getAllMappings().stream().filter(e -> e.getAction() == MissingMappings.Action.FAIL)
                    .forEach(fail -> failed.put(name, fail.key));

            final Class<? extends IForgeRegistryEntry> clazz = RegistryManager.ACTIVE.getSuperType(name);
            processMissing(clazz, name, STAGING, event, m.getValue(), remaps.get(name), defaulted.get(name),
                    failed.get(name));
        });

        if (!defaulted.isEmpty() && !isLocalWorld)
            return defaulted;

        if (!defaulted.isEmpty()) {
            StringBuilder buf = new StringBuilder();
            buf.append("Forge Mod Loader detected missing registry entries.\n\n").append("There are ")
                    .append(defaulted.size()).append(" missing entries in this save.\n")
                    .append("If you continue the missing entries will get removed.\n")
                    .append("A world backup will be automatically created in your saves directory.\n\n");

            defaulted.asMap().forEach((name, entries) -> {
                buf.append("Missing ").append(name).append(":\n");
                entries.forEach(rl -> buf.append("    ").append(rl).append("\n"));
            });

            boolean confirmed = StartupQuery.confirm(buf.toString());
            if (!confirmed)
                StartupQuery.abort();

            try {
                String skip = System.getProperty("fml.doNotBackup");
                if (skip == null || !"true".equals(skip)) {
                    ZipperUtil.backupWorld();
                } else {
                    for (int x = 0; x < 10; x++)
                        FMLLog.log.error("!!!!!!!!!! UPDATING WORLD WITHOUT DOING BACKUP !!!!!!!!!!!!!!!!");
                }
            } catch (IOException e) {
                StartupQuery.notify("The world backup couldn't be created.\n\n" + e);
                StartupQuery.abort();
            }
        }

        if (!defaulted.isEmpty()) {
            if (isLocalWorld)
                FMLLog.log.error(
                        "There are unidentified mappings in this world - we are going to attempt to process anyway");
        }

    }

    if (injectFrozenData) {
        // If we're loading from disk, we can actually substitute air in the block map for anything that is otherwise "missing". This keeps the reference in the map, in case
        // the block comes back later
        missing.forEach((name, m) -> {
            ForgeRegistry<?> reg = STAGING.getRegistry(name);
            m.forEach((rl, id) -> reg.markDummy(rl, id));
        });

        // If we're loading up the world from disk, we want to add in the new data that might have been provisioned by mods
        // So we load it from the frozen persistent registry
        RegistryManager.ACTIVE.registries.forEach((name, reg) -> {
            final Class<? extends IForgeRegistryEntry> clazz = RegistryManager.ACTIVE.getSuperType(name);
            loadFrozenDataToStagingRegistry(STAGING, name, remaps.get(name), clazz);
        });
    }

    // Validate that all the STAGING data is good
    STAGING.registries.forEach((name, reg) -> reg.validateContent(name));

    // Load the STAGING registry into the ACTIVE registry
    for (Map.Entry<ResourceLocation, ForgeRegistry<? extends IForgeRegistryEntry<?>>> r : RegistryManager.ACTIVE.registries
            .entrySet()) {
        final Class<? extends IForgeRegistryEntry> registrySuperType = RegistryManager.ACTIVE
                .getSuperType(r.getKey());
        loadRegistry(r.getKey(), STAGING, RegistryManager.ACTIVE, registrySuperType, true);
    }

    // Dump the active registry
    RegistryManager.ACTIVE.registries.forEach((name, reg) -> reg.dump(name));

    // Tell mods that the ids have changed
    Loader.instance().fireRemapEvent(remaps, false);

    // The id map changed, ensure we apply object holders
    ObjectHolderRegistry.INSTANCE.applyObjectHolders();

    // Return an empty list, because we're good
    return ArrayListMultimap.create();
}

From source file:org.ng200.openolympus.controller.admin.DeleteUserController.java

@PreAuthorize(SecurityExpressionConstants.IS_ADMIN)
@RequestMapping(value = "/api/admin/users/deleteUsers", method = RequestMethod.POST)
@ResponseStatus(value = HttpStatus.OK)/*from   www .  j av  a  2 s.co m*/
@Transactional
public void deleteUser(@RequestBody List<Long> userIds) {
    final List<User> users = userIds.stream().map(this.userService::getUserById).collect(Collectors.toList());
    users.forEach(Assertions::resourceExists);
    users.forEach(this.userService::deleteUser);
}

From source file:net.sf.jabref.logic.journals.JournalAbbreviationRepository.java

public void addEntries(List<Abbreviation> abbreviationsToAdd) {
    abbreviationsToAdd.forEach(this::addEntry);
}

From source file:ru.mera.samples.application.service.AbstractServiceImpl.java

@Override
public List<T> readAll() {
    List<E> entityList = getRepository().findAll();
    List<T> dtoList = new ArrayList<>();
    entityList.forEach(e -> dtoList.add(modelMapper.map(e, dtoClass)));
    return dtoList;
}