List of usage examples for com.google.common.collect Iterables removeIf
public static <T> boolean removeIf(Iterable<T> removeFrom, Predicate<? super T> predicate)
From source file:com.google.caliper.runner.config.CaliperConfigModule.java
private static CaliperConfig merge(ImmutableMap<String, String>... maps) { Map<String, String> result = Maps.newHashMap(); for (Map<String, String> map : maps) { result.putAll(map);//w w w. ja v a 2s . c o m } Iterables.removeIf(result.values(), Predicates.equalTo("")); return new CaliperConfig(ImmutableMap.copyOf(result)); }
From source file:se.crafted.chrisb.ecoCreature.events.mappers.EntityKilledEventMapper.java
private Collection<DropEvent> createDropEvents(final EntityKilledEvent event) { final Player killer = event.getKiller(); final DropConfig dropConfig = getDropConfig(killer.getWorld()); event.setSpawnerMobTracker(dropConfig); Collection<AbstractDrop> drops = Collections2.transform(dropConfig.collectDrops(event), new Function<AbstractDrop, AbstractDrop>() { @Override/* w w w . jav a 2 s. co m*/ public AbstractDrop apply(AbstractDrop drop) { if (drop instanceof CoinDrop) { CoinDrop coinDrop = (CoinDrop) drop; coinDrop.setGain(dropConfig.getGainMultiplier(killer)); coinDrop.setParty(dropConfig.getPartyMembers(killer)); coinDrop.addParameter(MessageToken.CREATURE, coinDrop.getName()) .addParameter(MessageToken.ITEM, event.getWeaponName()); } if (drop instanceof ItemDrop) { ItemDrop itemDrop = (ItemDrop) drop; if (dropConfig.isOverrideDrops() && !itemDrop.getItems().isEmpty() || dropConfig.isClearOnNoDrops() && itemDrop.getItems().isEmpty()) { event.getDrops().clear(); } if (dropConfig.isClearEnchantedDrops()) { Iterables.removeIf(event.getDrops(), new Predicate<ItemStack>() { @Override public boolean apply(ItemStack stack) { boolean notEmpty = !stack.getEnchantments().isEmpty(); LoggerUtil.getInstance() .debugTrue("Cleared enchanted item: " + stack.getType(), notEmpty); return notEmpty; } }); } } if (drop instanceof EntityDrop) { EntityDrop entityDrop = (EntityDrop) drop; if (entityDrop.getEntityTypes().contains(EntityType.EXPERIENCE_ORB)) { event.resetDroppedExp(); } } return drop; } }); return drops.isEmpty() ? EMPTY_COLLECTION : Lists.newArrayList(new DropEvent(killer, drops, event.getClass())); }
From source file:com.payu.ratel.server.InMemoryDiscoveryServer.java
@SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops") @Scheduled(fixedRate = MINUTE)//w ww. j a v a 2 s . c o m public void checkActiveServices() { for (final Map.Entry<ServiceDescriptor, Long> entry : pingedServers.entrySet()) { if (isActive(entry.getValue())) { LOGGER.info("Removing services with address {}", entry.getKey()); Iterables.removeIf(services, new Predicate<ServiceDescriptor>() { @Override public boolean apply(ServiceDescriptor service) { return service.equals(entry.getKey()); } }); pingedServers.remove(entry.getKey()); } } gaugeService.submit("registered.services.count", services.size()); gaugeService.submit("registered.servers.count", pingedServers.size()); }
From source file:org.solovyev.android.messenger.notifications.DefaultNotificationService.java
@Override public void remove(int notificationId) { final List<Message> removedNotifications = new ArrayList<Message>(); final String messageCode = String.valueOf(notificationId); synchronized (notifications) { Iterables.removeIf(notifications, PredicateSpy.spyOn(new Predicate<Message>() { @Override// ww w . j a va 2 s. c o m public boolean apply(@Nullable Message notification) { return notification != null && notification.getMessageCode().equals(messageCode); } }, removedNotifications)); } if (!removedNotifications.isEmpty()) { for (Message removedNotification : removedNotifications) { messengerListeners.fireEvent(MessengerEventType.notification_removed.newEvent(removedNotification)); } } }
From source file:oncue.scheduler.ScheduledJobs.java
/** * Remove a job associated with an agent * //w w w . j a v a2 s. com * @param job * is the {@linkplain Job} to remove * * @throws RemoveScheduleJobException */ public void removeJobById(final long jobId, String agent) throws RemoveScheduleJobException { if (!scheduledJobs.containsKey(agent)) throw new RemoveScheduleJobException("There is no registered agent " + agent + ". It is possible the scheduler was restarted and this agent has not re-registered yet."); Iterables.removeIf(scheduledJobs.get(agent), new Predicate<Job>() { @Override public boolean apply(Job input) { return input.getId() == jobId; } }); backingStore.removeScheduledJobById(jobId); }
From source file:org.apache.maven.repository.internal.DefaultModelResolver.java
private static void removeMatchingRepository(Iterable<RemoteRepository> repositories, final String id) { Iterables.removeIf(repositories, new Predicate<RemoteRepository>() { @Override//from w w w . ja v a 2 s. c o m public boolean apply(RemoteRepository remoteRepository) { return remoteRepository.getId().equals(id); } }); }
From source file:oncue.scheduler.UnscheduledJobs.java
/** * Remove a list of jobs from anywhere in the queue * /*from w ww .j a va2 s. co m*/ * @return a boolean, indicating if the removal was successful */ public boolean removeJobs(List<Job> jobs) { final Set<Long> jobIds = Sets.newHashSet(Iterators.transform(jobs.iterator(), new Function<Job, Long>() { @Override public Long apply(Job input) { return input.getId(); } })); boolean removed = Iterables.removeIf(unscheduledJobs, new Predicate<Job>() { @Override public boolean apply(Job input) { return jobIds.contains(input.getId()); } }); if (backingStore != null && removed) for (Job job : jobs) { backingStore.removeUnscheduledJobById(job.getId()); } return removed; }
From source file:org.bonitasoft.connectors.rest.AbstractRESTConnectorImpl.java
protected final java.util.List getUrlCookies() { final java.util.List cookies = (java.util.List) getInputParameter(URLCOOKIES_INPUT_PARAMETER); Iterables.removeIf(cookies, emptyLines()); return cookies; }
From source file:org.eclipse.sirius.diagram.ui.tools.internal.editor.tabbar.LayersContribution.java
private Collection<Layer> getLayers() { DiagramDescription diagramDesc = diagram.getDescription(); Collection<Layer> allLayers = new ArrayList<Layer>(new DiagramComponentizationManager() .getAllLayers(session.getSelectedViewpoints(false), diagramDesc)); allLayers.remove(diagramDesc.getDefaultLayer()); Iterables.removeIf(allLayers, new Predicate<Layer>() { @Override/* w w w . j av a 2 s .com*/ public boolean apply(Layer layer) { if (layer instanceof AdditionalLayer) { return !((AdditionalLayer) layer).isOptional(); } return false; } }); return allLayers; }
From source file:com.optimaize.langdetect.profiles.util.LanguageProfileValidator.java
/** * Remove potential LanguageProfiles, e.g. in combination with {@link #loadAllBuiltInLanguageProfiles()}. * @param isoString the ISO string of the LanguageProfile to be removed. *//*from ww w . j a v a 2s. c om*/ public LanguageProfileValidator removeLanguageProfile(final String isoString) { Iterables.removeIf(this.languageProfiles, new Predicate<LanguageProfile>() { @Override public boolean apply(LanguageProfile languageProfile) { return languageProfile.getLocale().getLanguage().equals(isoString); } }); return this; }