Java Code Examples for com.google.common.collect.Iterables#removeIf()

The following examples show how to use com.google.common.collect.Iterables#removeIf() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EncodedQualifiersColumnProjectionFilter.java    From phoenix with Apache License 2.0 6 votes vote down vote up
@Override
public void filterRowCells(List<Cell> kvs) throws IOException {
    if (kvs.isEmpty()) return;
    Cell firstKV = kvs.get(0);
    Iterables.removeIf(kvs, new Predicate<Cell>() {
        @Override
        public boolean apply(Cell kv) {
            int qualifier = encodingScheme.decode(kv.getQualifierArray(), kv.getQualifierOffset(), kv.getQualifierLength());
            return !trackedColumns.get(qualifier);
        }
    });
    if (kvs.isEmpty()) {
        kvs.add(new KeyValue(firstKV.getRowArray(), firstKV.getRowOffset(), firstKV.getRowLength(),
                this.emptyCFName, 0, this.emptyCFName.length, ENCODED_EMPTY_COLUMN_BYTES, 0,
                ENCODED_EMPTY_COLUMN_BYTES.length, HConstants.LATEST_TIMESTAMP, Type.Maximum, null, 0, 0));
    }
}
 
Example 2
Source File: DefaultClaimSet.java    From emodb with Apache License 2.0 6 votes vote down vote up
private void removeEmptyExpirationQueues() {
    // Periodically go through and remove empty expiration queues so they don't accumulate forever.
    // This cleans up queues with really long TTLs where every member was explicitly removed.
    Iterables.removeIf(_expirationQueues.values(), new Predicate<LinkedHashSet<Claim>>() {
        @Override
        public boolean apply(LinkedHashSet<Claim> queue) {
            return queue.isEmpty();
        }
    });
    Iterables.removeIf(_schedule, new Predicate<ProcessAt>() {
        @Override
        public boolean apply(ProcessAt processAt) {
            return processAt.getQueue().isEmpty();
        }
    });
    checkState(_schedule.size() == _expirationQueues.size());
}
 
Example 3
Source File: InMemoryDiscoveryServer.java    From Ratel with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops")
@Scheduled(fixedRate = MINUTE)
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());
}
 
Example 4
Source File: JavaTransformTest.java    From java_in_examples with Apache License 2.0 5 votes vote down vote up
private static void retainTest() {
    Collection<String> jdk = Lists.newArrayList("a1", "a2", "a3", "a1");
    Iterable<String> guava = Lists.newArrayList(jdk);
    Iterable<String> apache = Lists.newArrayList(jdk);
    MutableCollection<String> gs = FastList.newList(jdk);

    // remove if not
    jdk.removeIf((s) -> !s.contains("1")); // using jdk
    Iterables.removeIf(guava, (s) -> !s.contains("1")); // using guava
    CollectionUtils.filter(apache, (s) -> s.contains("1")); // using apache
    gs.removeIf((Predicate<String>) (s) -> !s.contains("1"));  //using gs

    System.out.println("retainIf = " + jdk + ":" + guava + ":" + apache + ":" + gs); // print retainIf = [a1, a1]:[a1, a1]:[a1, a1]:[a1, a1]
}
 
Example 5
Source File: ColumnProjectionFilter.java    From phoenix with Apache License 2.0 5 votes vote down vote up
@Override
public void filterRowCells(List<Cell> kvs) throws IOException {
    if (kvs.isEmpty()) return;
    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));
    }
}
 
Example 6
Source File: LanguageProfileValidator.java    From language-detector with Apache License 2.0 5 votes vote down vote up
/**
 * Remove potential LanguageProfiles, e.g. in combination with {@link #loadAllBuiltInLanguageProfiles()}.
 * @param isoString the ISO string of the LanguageProfile to be removed.
 */
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;
}
 
Example 7
Source File: ProjectInstance.java    From Kylin with Apache License 2.0 5 votes vote down vote up
public void removeRealization(final RealizationType type, final String realization) {
    Iterables.removeIf(this.realizationEntries, new Predicate<RealizationEntry>() {
        @Override
        public boolean apply(RealizationEntry input) {
            return input.getType() == type && input.getRealization().equalsIgnoreCase(realization);
        }
    });
}
 
Example 8
Source File: JavaTransformTest.java    From java_in_examples with Apache License 2.0 5 votes vote down vote up
private static void retainTest() {
    Collection<String> jdk = Lists.newArrayList("a1", "a2", "a3", "a1");
    Iterable<String> guava = Lists.newArrayList(jdk);
    Iterable<String> apache = Lists.newArrayList(jdk);
    MutableCollection<String> gs = FastList.newList(jdk);

    // удаление всех не равных условию
    jdk.removeIf((s) -> !s.contains("1")); // с помощью jdk
    Iterables.removeIf(guava, (s) -> !s.contains("1")); // с помощью guava
    CollectionUtils.filter(apache, (s) -> s.contains("1")); // с помощью apache
    gs.removeIf((Predicate<String>) (s) -> !s.contains("1"));  //с помощью gs

    System.out.println("retainIf = " + jdk + ":" + guava + ":" + apache + ":" + gs); // напечатает retainIf = [a1, a1]:[a1, a1]:[a1, a1]:[a1, a1]
}
 
Example 9
Source File: JavaTransformTest.java    From java_in_examples with Apache License 2.0 5 votes vote down vote up
private static void removeTest() {
    Collection<String> jdk = Lists.newArrayList("a1", "a2", "a3", "a1");
    Iterable<String> guava = Lists.newArrayList(jdk);
    Iterable<String> apache = Lists.newArrayList(jdk);
    MutableCollection<String> gs = FastList.newList(jdk);

    // удаление по условию
    jdk.removeIf((s) -> s.contains("1")); // с помощью jdk
    Iterables.removeIf(guava, (s) -> s.contains("1")); // с помощью guava
    CollectionUtils.filter(apache, (s) -> !s.contains("1")); // с помощью apache
    gs.removeIf((Predicate<String>) (s) -> s.contains("1"));  // с помощью gs

    System.out.println("removeIf = " + jdk + ":" + guava + ":" + apache + ":" + gs); // напечатает removeIf = [a2, a3]:[a2, a3]:[a2, a3]:[a2, a3]
}
 
Example 10
Source File: LanguageProfileValidator.java    From jstarcraft-nlp with Apache License 2.0 5 votes vote down vote up
/**
 * Remove potential LanguageProfiles, e.g. in combination with {@link #loadAllBuiltInLanguageProfiles()}.
 * 
 * @param isoString the ISO string of the LanguageProfile to be removed.
 */
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;
}
 
Example 11
Source File: JavaTransformTest.java    From java_in_examples with Apache License 2.0 5 votes vote down vote up
private static void removeTest() {
    Collection<String> jdk = Lists.newArrayList("a1", "a2", "a3", "a1");
    Iterable<String> guava = Lists.newArrayList(jdk);
    Iterable<String> apache = Lists.newArrayList(jdk);
    MutableCollection<String> gs = FastList.newList(jdk);

    // remove if
    jdk.removeIf((s) -> s.contains("1")); // using jdk
    Iterables.removeIf(guava, (s) -> s.contains("1")); // using guava
    CollectionUtils.filter(apache, (s) -> !s.contains("1")); // using apache
    gs.removeIf((Predicate<String>) (s) -> s.contains("1"));  // using gs

    System.out.println("removeIf = " + jdk + ":" + guava + ":" + apache + ":" + gs); // print removeIf = [a2, a3]:[a2, a3]:[a2, a3]:[a2, a3]
}
 
Example 12
Source File: DefaultClaimStore.java    From emodb with Apache License 2.0 5 votes vote down vote up
/**
 * Cleans up old claim sets for subscriptions that have become inactive.  Ensures the map of claim sets doesn't
 * grow forever.
 */
private synchronized void removeEmptyClaimSets() {
    Iterables.removeIf(_map.values(), new Predicate<Handle>() {
        @Override
        public boolean apply(Handle handle) {
            handle.getClaimSet().pump();
            return handle.getRefCount().get() == 0 && handle.getClaimSet().size() == 0;
        }
    });
}
 
Example 13
Source File: Iterables2Test.java    From attic-aurora with Apache License 2.0 5 votes vote down vote up
@Test
@SuppressWarnings("unchecked") // Needed because type information lost in vargs.
public void testZipRemove() {
  final int DEFAULT = 10;
  Iterable<List<Integer>> meta = Iterables2.zip(DEFAULT,
      list(1, 2, 3, 4),
      list(5, 6, 7, 8),
      list(9));

  // Attempt to trim all rows that have the default value.
  Iterables.removeIf(meta, input -> Iterables.contains(input, DEFAULT));

  assertValues(meta, list(1, 5, 9));
}
 
Example 14
Source File: UserBulkMigrationActor.java    From sunbird-lms-service with MIT License 5 votes vote down vote up
private Map<String, String> getContextMap(String processId, Request request) {
  Map<String, String> contextMap = (Map) request.getContext();
  ProjectLogger.log(
      "UserBulkMigrationActor:getContextMap:started preparing record for processId:"
          + processId
          + "with request context:"
          + contextMap,
      LoggerEnum.INFO.name());
  contextMap.put(JsonKey.ACTOR_TYPE, StringUtils.capitalize(JsonKey.SYSTEM));
  contextMap.put(JsonKey.ACTOR_ID, ProjectUtil.getUniqueIdFromTimestamp(0));
  Iterables.removeIf(contextMap.values(), value -> StringUtils.isBlank(value));
  return contextMap;
}
 
Example 15
Source File: JavaCollectionCleanupUnitTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public final void givenListContainsNulls_whenRemovingNullsWithGuavaV1_thenCorrect() {
    final List<Integer> list = Lists.newArrayList(null, 1, null);
    Iterables.removeIf(list, Predicates.isNull());

    assertThat(list, hasSize(1));
}
 
Example 16
Source File: PatternExpressionCompletionProcessor.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
private void filterProposals(List<ICompletionProposal> proposals) {
    Iterables.removeIf(proposals, not(validProposal()));
}
 
Example 17
Source File: GenericProposalFilter.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
private void filterProposals(List<IGroovyProposal> proposals) {
    Iterables.removeIf(proposals, not(validProposal()));
}
 
Example 18
Source File: Output.java    From immutables with Apache License 2.0 4 votes vote down vote up
private void removeBlankLinesIn(Iterable<String> services) {
  Iterables.removeIf(services, Predicates.equalTo(""));
}
 
Example 19
Source File: JsInteropRestrictionsChecker.java    From j2cl with Apache License 2.0 4 votes vote down vote up
private static void addMember(
    Multimap<String, MemberDescriptor> memberByMemberName, MemberDescriptor member) {
  String name = member.getSimpleJsName();
  Iterables.removeIf(memberByMemberName.get(name), m -> overrides(member, m));
  memberByMemberName.put(name, member);
}
 
Example 20
Source File: JobListeners.java    From incubator-gobblin with Apache License 2.0 2 votes vote down vote up
/**
 * Chains a given {@link List} of {@link JobListener}s into a single {@link JobListener}. The specified {@link JobListener}s
 * will all be executed in parallel.
 *
 * @param jobListeners is a {@link List} of {@link JobListener}s that need to be executed
 *
 * @return a {@link CloseableJobListener}, which is similar to {@link JobListener}, except
 * {@link CloseableJobListener#close()} will block until all {@link JobListener}s have finished their executions.
 */
public static CloseableJobListener parallelJobListener(List<JobListener> jobListeners) {
  Iterables.removeIf(jobListeners, Predicates.isNull());
  return new ParallelJobListener(jobListeners);
}