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:org.obiba.onyx.quartz.editor.locale.LocaleProperties.java
public void removeValue(IQuestionnaireElement element, Locale locale, final String key) { ListMultimap<Locale, KeyValue> labels = getElementLabels(element); if (labels != null) { List<KeyValue> keyValueList = labels.get(locale); if (keyValueList != null && !keyValueList.isEmpty()) { Iterables.removeIf(keyValueList, new Predicate<KeyValue>() { @Override//from w w w . ja v a 2 s .c o m public boolean apply(@Nullable KeyValue keyValue) { return keyValue != null && StringUtils.equals(keyValue.getKey(), key); } }); } } }
From source file:it.anyplace.sync.discovery.DiscoveryHandler.java
private void processDeviceAddressBg(final Iterable<DeviceAddress> deviceAddresses) { if (isClosed) { logger.debug("discarding device addresses, discovery handler already closed"); } else {//from w ww . ja v a 2 s.c om executorService.submit(new Runnable() { @Override public void run() { try { logger.info("processing device address list"); List<DeviceAddress> list = Lists.newArrayList(deviceAddresses); final Set<String> peers = Sets.newHashSet(configuration.getPeerIds()); Iterables.removeIf(list, new Predicate<DeviceAddress>() { //do not process address already processed @Override public boolean apply(DeviceAddress deviceAddress) { return !peers.contains(deviceAddress.getDeviceId()) || deviceAddressMap.containsKey( Pair.of(deviceAddress.getDeviceId(), deviceAddress.getAddress())); } }); list = AddressRanker.testAndRank(list); for (DeviceAddress deviceAddress : list) { putDeviceAddress(deviceAddress); } } catch (Exception ex) { logger.error("error processing device addresses", ex); } } }); } }
From source file:org.dcache.srm.request.HashtableRequestCredentialStorage.java
@Override public boolean deleteRequestCredential(String name, String role) { return Iterables.removeIf(store.values(), isMatching(name, role)); }
From source file:org.apache.kylin.metadata.project.ProjectInstance.java
public void removeRealization(final RealizationType type, final String realization) { Iterables.removeIf(this.realizationEntries, new Predicate<RealizationEntry>() { @Override/*from ww w . ja v a 2 s .c o m*/ public boolean apply(RealizationEntry input) { return input.getType() == type && input.getRealization().equalsIgnoreCase(realization); } }); }
From source file:com.eucalyptus.reporting.modules.backend.DescribeSensorsListener.java
@Override public void fireEvent(final Hertz event) { if (!Bootstrap.isOperational() || !BootstrapArgs.isCloudController() || !event.isAsserted(DEFAULT_POLL_INTERVAL_MINS)) { return;/* w ww .j ava 2 s .com*/ } else { if (DEFAULT_POLL_INTERVAL_MINS >= 1) { COLLECTION_INTERVAL_TIME_MS = ((int) TimeUnit.MINUTES.toMillis(DEFAULT_POLL_INTERVAL_MINS) / 2); } else { COLLECTION_INTERVAL_TIME_MS = 0; } if (COLLECTION_INTERVAL_TIME_MS == 0 || HISTORY_SIZE > 15 || HISTORY_SIZE < 1) { LOG.debug("The instance usage report is disabled"); } else if (COLLECTION_INTERVAL_TIME_MS <= MAX_WRITE_INTERVAL_MS) { try { if (event.isAsserted(TimeUnit.MINUTES.toSeconds(DEFAULT_POLL_INTERVAL_MINS))) { if (Bootstrap.isFinished() && Hosts.isCoordinator()) { if (busy.compareAndSet(false, true)) { Threads.lookup(Reporting.class).limitTo(REPORTING_NUM_THREADS) .submit(new Callable<Object>() { @Override public Object call() throws Exception { try { List<VmInstance> instList = VmInstances.list(VmState.RUNNING); List<String> instIdList = Lists.newArrayList(); for (final VmInstance inst : instList) { instIdList.add(inst.getInstanceId()); } Iterable<List<String>> processInts = Iterables .paddedPartition(instIdList, SENSOR_QUERY_BATCH_SIZE); for (final ServiceConfiguration ccConfig : Topology .enabledServices(ClusterController.class)) { for (List<String> instIds : processInts) { ArrayList<String> instanceIds = Lists .newArrayList(instIds); Iterables.removeIf(instanceIds, Predicates.isNull()); // LOG.info("DecribeSensorCallback about to be sent"); /** * Here this is hijacking the sensor callback in order to control the thread of execution used when invoking the */ final DescribeSensorCallback msgCallback = new DescribeSensorCallback( HISTORY_SIZE, COLLECTION_INTERVAL_TIME_MS, instanceIds) { @Override public void fireException(Throwable e) { } @Override public void fire(DescribeSensorsResponse msg) { } }; /** * Here we actually get the future reference to the result and, from this thread, invoke .fire(). */ Future<DescribeSensorsResponse> ret = AsyncRequests .newRequest(msgCallback).dispatch(ccConfig); try { new DescribeSensorCallback(HISTORY_SIZE, COLLECTION_INTERVAL_TIME_MS, instanceIds) .fire(ret.get()); // LOG.info("DecribeSensorCallback has been successfully executed"); } catch (Exception e) { Exceptions.maybeInterrupted(e); } } } } finally { /** * Only and finally set the busy bit back to false. */ busy.set(false); } return null; } }); } } } } catch (Exception ex) { LOG.error("Unable to listen for describe sensors events", ex); } } else { LOG.error("DEFAULT_POLL_INTERVAL_MINS : " + DEFAULT_POLL_INTERVAL_MINS + " must be less than 1440 minutes"); } } }
From source file:com.thinkbiganalytics.nifi.rest.support.NifiProcessUtil.java
/** * Return a set of processors in a template, optionally allowing the framework to traverse into a templates input ports to get the connecting process groups * * @param template a template to parse * @param excludeInputs {@code true} will traverse down into the input ports and gather processors in the conencting groups, {@code false} will traverse input ports and their respective process * groups/* ww w . ja v a 2 s. c o m*/ * @return return a set of processors */ public static Set<ProcessorDTO> getProcessors(TemplateDTO template, boolean excludeInputs) { Set<ProcessorDTO> processors = new HashSet<>(); for (ProcessorDTO processorDTO : template.getSnippet().getProcessors()) { processors.add(processorDTO); } if (template.getSnippet().getProcessGroups() != null) { for (ProcessGroupDTO groupDTO : template.getSnippet().getProcessGroups()) { processors.addAll(getProcessors(groupDTO)); } } if (excludeInputs) { final List<ProcessorDTO> inputs = NifiTemplateUtil.getInputProcessorsForTemplate(template); Iterables.removeIf(processors, new Predicate<ProcessorDTO>() { @Override public boolean apply(ProcessorDTO processorDTO) { return (inputs.contains(processorDTO)); } }); } return processors; }
From source file:org.apache.phoenix.filter.ColumnProjectionFilter.java
@Override public void filterRowCells(List<Cell> kvs) throws IOException { if (kvs.isEmpty()) return;/*from w w w .j av a 2s. c om*/ Cell firstKV = kvs.get(0); Iterables.removeIf(kvs, new Predicate<Cell>() { @Override public boolean apply(Cell kv) { ptr.set(kv.getFamilyArray(), kv.getFamilyOffset(), kv.getFamilyLength()); if (columnsTracker.containsKey(ptr)) { Set<ImmutableBytesPtr> cols = columnsTracker.get(ptr); ptr.set(kv.getQualifierArray(), kv.getQualifierOffset(), kv.getQualifierLength()); if (cols != null && !(cols.contains(ptr))) { return true; } } else { return true; } return false; } }); // make sure we're not holding to any of the byte[]'s ptr.set(HConstants.EMPTY_BYTE_ARRAY); if (kvs.isEmpty()) { kvs.add(new KeyValue(firstKV.getRowArray(), firstKV.getRowOffset(), firstKV.getRowLength(), this.emptyCFName, 0, this.emptyCFName.length, emptyKVQualifier, 0, emptyKVQualifier.length, HConstants.LATEST_TIMESTAMP, Type.Maximum, null, 0, 0)); } }
From source file:com.twitter.common.net.monitoring.TrafficMonitor.java
@VisibleForTesting synchronized void gc() { Iterables.removeIf(trafficInfos.asMap().entrySet(), new Predicate<Map.Entry<K, TrafficInfo>>() { @Override/* w w w . java 2 s . com*/ public boolean apply(Map.Entry<K, TrafficInfo> clientInfo) { if (clientInfo.getValue().connections.get() > 0) return false; long idlePeriod = clock.nowNanos() - clientInfo.getValue().getLastActiveTimestamp(); return idlePeriod > gcInterval.as(Time.NANOSECONDS); } }); }
From source file:com.analog.lyric.dimple.schedulers.CustomScheduler.java
@Override public void addBlockWithReplacement(IBlockUpdater blockUpdater, final VariableBlock block) { Iterables.removeIf(_entries, new Predicate<IScheduleEntry>() { @NonNullByDefault(false)/* w w w . j a va 2 s . c o m*/ @Override public boolean apply(IScheduleEntry entry) { switch (entry.type()) { case NODE: return block.contains(((NodeScheduleEntry) entry).getNode()); case EDGE: return block.contains(((EdgeScheduleEntry) entry).getNode()); default: return false; } } }); addBlock(blockUpdater, block); }
From source file:com.ben12.reta.view.buffering.BufferingManager.java
public <T> boolean remove(final Buffering<T> p, boolean rebuild) { boolean changed = Iterables.removeIf(buffers, br -> { Buffering<?> b = br.get(); if (b != null) { return b == p; } else {//from ww w .j a v a 2s . c om return true; } }); if (changed && rebuild) { rebuildBufferingExpression(); rebuildValidExpression(); } return changed; }