Java Code Examples for com.google.common.collect.Sets#filter()

The following examples show how to use com.google.common.collect.Sets#filter() . 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: Graphs.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Copies all edges from {@code original} into {@code copy} that satisfy {@code edgePredicate}.
 * Also copies all nodes incident to these edges.
 */
public static <N, E> void mergeEdgesFrom(
    Network<N, E> original, MutableNetwork<N, E> copy, Predicate<? super E> edgePredicate) {
  checkNotNull(original, "original");
  checkNotNull(copy, "copy");
  checkNotNull(edgePredicate, "edgePredicate");
  for (E edge : Sets.filter(original.edges(), edgePredicate)) {
    addEdge(copy, edge, original.incidentNodes(edge));
  }
}
 
Example 2
Source File: HBaseTransactionPruningPlugin.java    From phoenix-tephra with Apache License 2.0 5 votes vote down vote up
private SortedSet<byte[]> filterDeletedTableRegions(final Set<TableName> existingTables,
                                                    SortedSet<byte[]> transactionalRegions) {
  return Sets.filter(transactionalRegions,
                     new Predicate<byte[]>() {
                       @Override
                       public boolean apply(byte[] region) {
                         return existingTables.contains(HRegionInfo.getTable(region));
                       }
                     });
}
 
Example 3
Source File: Graphs.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Copies all nodes from {@code original} into {@code copy} that satisfy {@code nodePredicate}.
 */


public static <N, E> void mergeNodesFrom(Graph<N> original, MutableGraph<N> copy, Predicate<? super N> nodePredicate) {
  checkNotNull(original, "original");
  checkNotNull(copy, "copy");
  checkNotNull(nodePredicate, "nodePredicate");
  for (N node : Sets.filter(original.nodes(), nodePredicate)) {
    copy.addNode(node);
  }
}
 
Example 4
Source File: JedisSegmentScoredQueueStore.java    From vscrawler with Apache License 2.0 5 votes vote down vote up
@Override
public void addBatch(String queueID, Set<ResourceItem> resourceItems) {
    if (!lockQueue(queueID)) {
        return;
    }
    @Cleanup Jedis jedis = jedisPool.getResource();
    final String dataKey = makeDataKey(queueID);
    try {
        final Set<String> hkeys = jedis.hkeys(dataKey);
        Set<ResourceItem> filterSet = Sets.filter(resourceItems, new Predicate<ResourceItem>() {
            @Override
            public boolean apply(ResourceItem input) {
                return !hkeys.contains(input.getKey());
            }
        });
        List<String> sliceQueue = sliceQueue(queueID);
        Set<String> newSlices = Sets.newHashSet();
        long index = size(queueID) + 1;
        String tailSlice = null;
        for (ResourceItem resourceItem : filterSet) {
            jedis.hset(dataKey, resourceItem.getKey(), JSONObject.toJSONString(resourceItem));
            String sliceID = String.valueOf(blockID(index));
            if (sliceID.equals(tailSlice) || sliceQueue.contains(sliceID)) {
                sliceID = sliceQueue.get(sliceQueue.size() - 1);
                tailSlice = sliceID;
            } else if (!newSlices.contains(sliceID)) {
                jedis.rpush(makeSliceQueueKey(queueID), sliceID);
                newSlices.add(sliceID);
            }
            jedis.rpush(makePoolQueueKey(queueID, sliceID), resourceItem.getKey());
            index++;
        }
    } finally {
        unLockQueue(queueID);
    }
}
 
Example 5
Source File: Graphs.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Copies all edges from {@code original} into {@code copy} that satisfy {@code edgePredicate}.
 * Also copies all nodes incident to these edges.
 */


public static <N, E> void mergeEdgesFrom(Network<N, E> original, MutableNetwork<N, E> copy, Predicate<? super E> edgePredicate) {
  checkNotNull(original, "original");
  checkNotNull(copy, "copy");
  checkNotNull(edgePredicate, "edgePredicate");
  for (E edge : Sets.filter(original.edges(), edgePredicate)) {
    addEdge(copy, edge, original.incidentNodes(edge));
  }
}
 
Example 6
Source File: RamScoredQueueStore.java    From vscrawler with Apache License 2.0 5 votes vote down vote up
@Override
public Set<String> notExisted(String queueID, Set<String> resourceItemKeys) {
    final Map<String, ResourceItem> maps = createOrGet(queueID).maps;
    return Sets.filter(resourceItemKeys, new Predicate<String>() {
        @Override
        public boolean apply(String input) {
            return !maps.containsKey(input);
        }
    });
}
 
Example 7
Source File: HdfsFileStorage.java    From registry with Apache License 2.0 5 votes vote down vote up
@Override
public void init(Map<String, String> config) throws IOException {
    String fsUrl = config.get(CONFIG_FSURL);
    String kerberosPrincipal = config.get(CONFIG_KERBEROS_PRINCIPAL);
    String keytabLocation = config.get(CONFIG_KERBEROS_KEYTAB);
    directory = config.getOrDefault(CONFIG_DIRECTORY, DEFAULT_DIR);

    hdfsConfig = new Configuration();

    for(Map.Entry<String, String> entry:
            Sets.filter(config.entrySet(), e -> !OWN_CONFIGS.contains(e.getKey()))) {
        hdfsConfig.set(entry.getKey(), entry.getValue());
    }

    // make sure fsUrl is set
    Preconditions.checkArgument(fsUrl != null, "fsUrl must be specified for HdfsFileStorage.");

    Preconditions.checkArgument(keytabLocation != null || kerberosPrincipal == null,
        "%s is needed when %s (== %s) is specified.",
        CONFIG_KERBEROS_KEYTAB, CONFIG_KERBEROS_PRINCIPAL, kerberosPrincipal);

    Preconditions.checkArgument(kerberosPrincipal != null || keytabLocation == null,
        "%s is needed when %s (== %s) is specified.",
        CONFIG_KERBEROS_PRINCIPAL, CONFIG_KERBEROS_KEYTAB, keytabLocation);

    if (kerberosPrincipal != null) {
        LOG.info("Logging in as kerberos principal {}", kerberosPrincipal);
        UserGroupInformation.loginUserFromKeytab(kerberosPrincipal, keytabLocation);
        kerberosEnabled = true;
    }

    directory = adjustDirectory(fsUrl, directory);
    fsUri = URI.create(fsUrl);

    LOG.info("Initialized with fsUrl={}, directory={}, kerberos principal={}", fsUrl, directory, kerberosPrincipal);
}
 
Example 8
Source File: HBaseTransactionPruningPlugin.java    From phoenix-tephra with Apache License 2.0 5 votes vote down vote up
private SortedSet<byte[]> filterDeletedTableRegions(final Set<TableName> existingTables,
                                                    SortedSet<byte[]> transactionalRegions) {
  return Sets.filter(transactionalRegions,
                     new Predicate<byte[]>() {
                       @Override
                       public boolean apply(byte[] region) {
                         return existingTables.contains(HRegionInfo.getTable(region));
                       }
                     });
}
 
Example 9
Source File: HBaseTransactionPruningPlugin.java    From phoenix-tephra with Apache License 2.0 5 votes vote down vote up
private SortedSet<byte[]> filterDeletedTableRegions(final Set<TableName> existingTables,
                                                    SortedSet<byte[]> transactionalRegions) {
  return Sets.filter(transactionalRegions,
                     new Predicate<byte[]>() {
                       @Override
                       public boolean apply(byte[] region) {
                         return existingTables.contains(HRegionInfo.getTable(region));
                       }
                     });
}
 
Example 10
Source File: Graphs.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Copies all nodes from {@code original} into {@code copy} that satisfy {@code nodePredicate}.
 */


public static <N, E> void mergeNodesFrom(Graph<N> original, MutableGraph<N> copy, Predicate<? super N> nodePredicate) {
  checkNotNull(original, "original");
  checkNotNull(copy, "copy");
  checkNotNull(nodePredicate, "nodePredicate");
  for (N node : Sets.filter(original.nodes(), nodePredicate)) {
    copy.addNode(node);
  }
}
 
Example 11
Source File: HBaseTransactionPruningPlugin.java    From phoenix-tephra with Apache License 2.0 5 votes vote down vote up
private SortedSet<byte[]> filterDeletedTableRegions(final Set<TableName> existingTables,
                                                    SortedSet<byte[]> transactionalRegions) {
  return Sets.filter(transactionalRegions,
                     new Predicate<byte[]>() {
                       @Override
                       public boolean apply(byte[] region) {
                         return existingTables.contains(HRegionInfo.getTable(region));
                       }
                     });
}
 
Example 12
Source File: Graphs.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Copies all edges from {@code original} into {@code copy} that satisfy {@code edgePredicate}.
 * Also copies all nodes incident to these edges.
 */


public static <N, E> void mergeEdgesFrom(Network<N, E> original, MutableNetwork<N, E> copy, Predicate<? super E> edgePredicate) {
  checkNotNull(original, "original");
  checkNotNull(copy, "copy");
  checkNotNull(edgePredicate, "edgePredicate");
  for (E edge : Sets.filter(original.edges(), edgePredicate)) {
    addEdge(copy, edge, original.incidentNodes(edge));
  }
}
 
Example 13
Source File: Graphs.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Copies all nodes from {@code original} into {@code copy} that satisfy {@code nodePredicate}.
 */


public static <N, E> void mergeNodesFrom(Graph<N> original, MutableGraph<N> copy, Predicate<? super N> nodePredicate) {
  checkNotNull(original, "original");
  checkNotNull(copy, "copy");
  checkNotNull(nodePredicate, "nodePredicate");
  for (N node : Sets.filter(original.nodes(), nodePredicate)) {
    copy.addNode(node);
  }
}
 
Example 14
Source File: Graphs.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Copies all edges from {@code original} into {@code copy} that satisfy {@code edgePredicate}.
 * Also copies all nodes incident to these edges.
 */


public static <N, E> void mergeEdgesFrom(Network<N, E> original, MutableNetwork<N, E> copy, Predicate<? super E> edgePredicate) {
  checkNotNull(original, "original");
  checkNotNull(copy, "copy");
  checkNotNull(edgePredicate, "edgePredicate");
  for (E edge : Sets.filter(original.edges(), edgePredicate)) {
    addEdge(copy, edge, original.incidentNodes(edge));
  }
}
 
Example 15
Source File: ImportCollector.java    From bistoury with GNU General Public License v3.0 5 votes vote down vote up
private List<String> packImports() {

        /*return mapSimpleNames.entrySet().stream()
                .filter(ent ->
                        // exclude the current class or one of the nested ones
                        // empty, java.lang and the current packages
                        !setNotImportedNames.contains(ent.getKey()) &&
                                !ent.getValue().isEmpty() &&
                                !JAVA_LANG_PACKAGE.equals(ent.getValue()) &&
                                !ent.getValue().equals(currentPackagePoint)
                )
                .sorted(Map.Entry.<String, String>comparingByValue().thenComparing(Map.Entry.comparingByKey()))
                .map(ent -> ent.getValue() + "." + ent.getKey())
                .collect(Collectors.toList());*/
        HashSet<Map.Entry<String, String>> set = Sets.newHashSet(mapSimpleNames.entrySet());
        Sets.filter(set, new Predicate<Map.Entry<String, String>>() {
            @Override
            public boolean apply(Map.Entry<String, String> ent) {
                return !setNotImportedNames.contains(ent.getKey()) &&
                        !ent.getValue().isEmpty() &&
                        !JAVA_LANG_PACKAGE.equals(ent.getValue()) &&
                        !ent.getValue().equals(currentPackagePoint);
            }
        });
        ArrayList<Map.Entry<String, String>> list = Lists.newArrayList(set);
        Collections.sort(list, new Comparator<Map.Entry<String, String>>() {
            @Override
            public int compare(Map.Entry<String, String> c1, Map.Entry<String, String> c2) {
                int res = c1.getValue().compareTo(c2.getValue());
                return (res != 0) ? res : c1.getKey().compareTo(c2.getKey());
            }
        });
        List<String> result = Lists.newArrayList();
        for (Map.Entry<String, String> entry : list) {
            result.add(entry.getValue() + "." + entry.getKey());
        }
        return result;
    }
 
Example 16
Source File: Activatables.java    From arctic-sea with Apache License 2.0 4 votes vote down vote up
public static <K, T> Set<K> activatedKeys(Map<K, T> map, ActivationProvider<? super K> provider) {
    return Sets.filter(map.keySet(), provider::isActive);
}
 
Example 17
Source File: CacheGenerator.java    From caffeine with Apache License 2.0 4 votes vote down vote up
/** Returns the Cartesian set of the possible cache configurations. */
@SuppressWarnings("unchecked")
private Set<List<Object>> combinations() {
  Set<Boolean> asyncLoading = ImmutableSet.of(true, false);
  Set<Stats> statistics = filterTypes(options.stats(), cacheSpec.stats());
  Set<ReferenceType> keys = filterTypes(options.keys(), cacheSpec.keys());
  Set<ReferenceType> values = filterTypes(options.values(), cacheSpec.values());
  Set<Compute> computations = filterTypes(options.compute(), cacheSpec.compute());
  Set<Implementation> implementations = filterTypes(
      options.implementation(), cacheSpec.implementation());

  if (isAsyncOnly) {
    values = values.contains(ReferenceType.STRONG)
        ? ImmutableSet.of(ReferenceType.STRONG)
        : ImmutableSet.of();
    computations = Sets.filter(computations, Compute.ASYNC::equals);
  }
  if (isAsyncOnly || computations.equals(ImmutableSet.of(Compute.ASYNC))) {
    implementations = implementations.contains(Implementation.Caffeine)
        ? ImmutableSet.of(Implementation.Caffeine)
        : ImmutableSet.of();
  }
  if (computations.equals(ImmutableSet.of(Compute.SYNC))) {
    asyncLoading = ImmutableSet.of(false);
  }

  if (computations.isEmpty() || implementations.isEmpty() || keys.isEmpty() || values.isEmpty()) {
    return ImmutableSet.of();
  }
  return Sets.cartesianProduct(
      ImmutableSet.copyOf(cacheSpec.initialCapacity()),
      ImmutableSet.copyOf(statistics),
      ImmutableSet.copyOf(cacheSpec.weigher()),
      ImmutableSet.copyOf(cacheSpec.maximumSize()),
      ImmutableSet.copyOf(cacheSpec.expiry()),
      ImmutableSet.copyOf(cacheSpec.expireAfterAccess()),
      ImmutableSet.copyOf(cacheSpec.expireAfterWrite()),
      ImmutableSet.copyOf(cacheSpec.refreshAfterWrite()),
      ImmutableSet.copyOf(cacheSpec.advanceOnPopulation()),
      ImmutableSet.copyOf(keys),
      ImmutableSet.copyOf(values),
      ImmutableSet.copyOf(cacheSpec.executor()),
      ImmutableSet.copyOf(cacheSpec.scheduler()),
      ImmutableSet.copyOf(cacheSpec.removalListener()),
      ImmutableSet.copyOf(cacheSpec.population()),
      ImmutableSet.of(true, isLoadingOnly),
      ImmutableSet.copyOf(asyncLoading),
      ImmutableSet.copyOf(computations),
      ImmutableSet.copyOf(cacheSpec.loader()),
      ImmutableSet.copyOf(cacheSpec.writer()),
      ImmutableSet.copyOf(implementations));
}
 
Example 18
Source File: TypeMap.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * Return all keys that bound the given type
 */
public Set<TypeToken<? extends K>> keysAssignableFrom(TypeToken<? extends K> type) {
    return Sets.filter(keySet(), bounds -> bounds.isAssignableFrom(type));
}
 
Example 19
Source File: TypeMap.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * Return all keys within the given bounds
 */
public Set<TypeToken<? extends K>> keysAssignableTo(TypeToken<? extends K> bounds) {
    return Sets.filter(keySet(), bounds::isAssignableFrom);
}
 
Example 20
Source File: RoundEnvironments.java    From FreeBuilder with Apache License 2.0 2 votes vote down vote up
/**
 * Sanitizes the result of {@link RoundEnvironment#getElementsAnnotatedWith}, which otherwise
 * can contain elements annotated with annotations of ERROR type.
 *
 * <p>The canonical example is forgetting to import &#64;Nullable.
 */
public static Set<? extends Element> annotatedElementsIn(
    RoundEnvironment roundEnv, Class<? extends Annotation> a) {
  return Sets.filter(roundEnv.getElementsAnnotatedWith(a),
      element -> element.getAnnotation(a) != null);
}