List of usage examples for com.google.common.collect Sets intersection
public static <E> SetView<E> intersection(final Set<E> set1, final Set<?> set2)
From source file:org.nmdp.service.common.domain.ConfigurationModule.java
private void bindObjectConfig(Object value, Annotation... bindAnnos) throws Exception { if (null == value || value instanceof Class || seen.contains(value)) return;/*ww w. ja v a 2s .c o m*/ seen.push(value); log.trace("stack size: " + seen.size()); try { Class clazz = value.getClass(); if (null != bindAnnos && bindAnnos.length > 0) { Set<Class<? extends Annotation>> bindAnnoClasses = FluentIterable.from(Arrays.asList(bindAnnos)) .transform(new Function<Annotation, Class<? extends Annotation>>() { @Override public Class<? extends Annotation> apply(Annotation anno) { return anno.annotationType(); } }).toSet(); SetView<Class<? extends Annotation>> matchedAnnos = Sets.intersection(annos, Sets.newHashSet(bindAnnoClasses)); for (Class<? extends Annotation> anno : matchedAnnos) { log.info("binding property " + anno.getSimpleName() + ": " + value); bind(clazz).annotatedWith(anno).toInstance(clazz.cast(value)); } } if (stopClasses.contains(value.getClass())) return; bindBeanProperties(value); bindJavaFields(value); } finally { seen.pop(); } }
From source file:org.sonar.scanner.source.ZeroCoverageSensor.java
private boolean isCoverageMeasuresAlreadyDefined(InputFile f) { Set<String> metricKeys = StreamSupport.stream(measureCache.byComponentKey(f.key()).spliterator(), false) .map(new MeasureToMetricKey()).collect(MoreCollectors.toSet()); Function<Metric, String> metricToKey = new MetricToKey(); Set<String> allCoverageMetricKeys = CoverageType.UNIT.allMetrics().stream().map(metricToKey) .collect(MoreCollectors.toSet()); return !Sets.intersection(metricKeys, allCoverageMetricKeys).isEmpty(); }
From source file:heros.fieldsens.AccessPath.java
public PrefixTestResult isPrefixOf(AccessPath<T> accessPath) { if (accesses.length > accessPath.accesses.length) return PrefixTestResult.NO_PREFIX; for (int i = 0; i < accesses.length; i++) { if (!accesses[i].equals(accessPath.accesses[i])) return PrefixTestResult.NO_PREFIX; }/*from w w w . j a v a 2 s. c om*/ if (accesses.length < accessPath.accesses.length) { if (exclusions.contains(accessPath.accesses[accesses.length])) return PrefixTestResult.NO_PREFIX; else return PrefixTestResult.GUARANTEED_PREFIX; } if (exclusions.isEmpty()) return PrefixTestResult.GUARANTEED_PREFIX; if (accessPath.exclusions.isEmpty()) return PrefixTestResult.NO_PREFIX; boolean intersection = !Sets.intersection(exclusions, accessPath.exclusions).isEmpty(); boolean containsAll = exclusions.containsAll(accessPath.exclusions); boolean oppositeContainsAll = accessPath.exclusions.containsAll(exclusions); boolean potentialMatch = oppositeContainsAll || !intersection || (!containsAll && !oppositeContainsAll); if (potentialMatch) { if (oppositeContainsAll) return PrefixTestResult.GUARANTEED_PREFIX; else return PrefixTestResult.POTENTIAL_PREFIX; } return PrefixTestResult.NO_PREFIX; }
From source file:com.cloudera.gertrude.space.LayerBuilder.java
void allocateBuckets(int segmentId, DiversionCriterion criteria, SortedSet<Integer> buckets) throws ValidationException { if (buckets.first() < 0) { throw new ValidationException("Negative buckets in segment: " + segmentId); }// w ww . ja v a2 s . co m if (buckets.last() >= criteria.getNumBuckets()) { throw new ValidationException("Buckets in segment " + segmentId + " exceeds max buckets for criteria"); } Map<Integer, Integer> allocatedBuckets = allocatedBucketsByDiversion.get(criteria.getId()); if (allocatedBuckets == null) { allocatedBuckets = Maps.newHashMap(); allocatedBucketsByDiversion.put(criteria.getId(), allocatedBuckets); } Set<Integer> conflict = Sets.intersection(buckets, allocatedBuckets.keySet()); if (!conflict.isEmpty()) { StringBuilder sb = new StringBuilder("Overlapping buckets for segment ").append(segmentId) .append(" and segment(s) "); Set<Integer> conflictSegments = Sets.newHashSet(); for (Integer bucket : conflict) { conflictSegments.add(allocatedBuckets.get(bucket)); } sb.append(conflictSegments).append(" (Buckets: ").append(conflict).append(')'); throw new ValidationException(sb.toString()); } for (Integer bucket : buckets) { allocatedBuckets.put(bucket, segmentId); } }
From source file:edu.brandeis.cs.develops.eptosql.semantic_analysis.SemanticAnalyzer.java
private boolean shareAttributes(String predicate1, String predicate2) { Set<String> columns1 = new HashSet<String>(); Set<String> columns2 = new HashSet<String>(); Pattern p = Pattern.compile("[A-Za-z]+[0-9]*"); Matcher m = p.matcher(predicate1); while (m.find()) { columns1.add(m.group());// w w w.j ava2s. c o m } m = p.matcher(predicate2); while (m.find()) { columns2.add(m.group()); } return Sets.intersection(columns1, columns2).size() != 0; }
From source file:org.opentripplanner.routing.edgetype.RentABikeAbstractEdge.java
/** * @param stationNetworks The station where we want to drop the bike off. * @param rentedNetworks The set of networks of the station we rented the bike from. * @return true if the bike can be dropped off here, false if not. *///from w ww .j av a 2 s. co m private boolean hasCompatibleNetworks(Set<String> stationNetworks, Set<String> rentedNetworks) { /* * Two stations are compatible if they share at least one network. * Special case for "*" networks (no network defined in OSM). */ if (stationNetworks.contains("*") || rentedNetworks.contains("*")) return true; return !Sets.intersection(stationNetworks, rentedNetworks).isEmpty(); }
From source file:at.sti2.spark.rete.beta.JoinNode.java
/** * Activation coming from an alpha memory. *//*w ww . j av a2 s.co m*/ @Override public void rightActivate(WorkingMemoryElement wme) { // If the join node is under dummy root beta node left activation should // fire if (((BetaMemory) parent).isRootNode()) { for (RETENode reteNode : children) reteNode.leftActivate(null, wme); } else { if (tests.size() > 0) { Set<Token> resultSet = null; Set<Token> intermediateSet = new LinkedHashSet<Token>(); for (JoinNodeTest test : tests) { Field arg2Field = test.getArg2Field(); RDFValue testTokenValue = wme.getTriple().getRDFTriple().getValueOfField(test.getArg1Field()); Set<Token> tokensFromIndex = null; if (arg2Field == RDFTriple.Field.SUBJECT) { tokensFromIndex = test.getIndexStructure().getElementsFromSubjectIndex(testTokenValue); } else if (arg2Field == RDFTriple.Field.PREDICATE) { tokensFromIndex = test.getIndexStructure().getElementsFromPredicateIndex(testTokenValue); } else if (arg2Field == RDFTriple.Field.OBJECT) { tokensFromIndex = test.getIndexStructure().getElementsFromObjectIndex(testTokenValue); } // Get Tokens at the level of parent beta memory for (Token token : tokensFromIndex) { Set<Token> childTokensAtBetaMemory = token.getChildTokensAtBetaMemory((BetaMemory) parent); intermediateSet = Sets.union(childTokensAtBetaMemory, intermediateSet); } if (resultSet == null && intermediateSet != null) { resultSet = intermediateSet; } else if (intermediateSet != null) { resultSet = Sets.intersection(resultSet, intermediateSet); } } if (resultSet != null) { for (Token token : resultSet) { // Check if the token and wme are falling into a window if (token.getWme().getTriple().isPermanent() || performTimeWindowTest(token, wme)) { // All tests successful for (RETENode reteNode : children) reteNode.leftActivate(token, wme); } } } } else { ArrayList<Token> elementsFromTokenQueue = ((BetaMemory) parent).getIndexStructure() .getElementsFromTokenQueue(); for (RETENode reteNode : children) for (Token token : elementsFromTokenQueue) reteNode.leftActivate(token, wme); } } }
From source file:org.apache.drill.exec.rpc.user.InboundImpersonationManager.java
/** * Checks if the proxy user is authorized to impersonate the target user based on the policies. * * @param proxyName proxy user name//from w ww.j a v a 2 s. c om * @param targetName target user name * @param policies impersonation policies * @return true iff proxy user is authorized to impersonate the target user */ private static boolean hasImpersonationPrivileges(final String proxyName, final String targetName, final List<ImpersonationPolicy> policies) { final UserGroupInformation proxyUgi = ImpersonationUtil.createProxyUgi(proxyName); final Set<String> proxyGroups = Sets.newHashSet(proxyUgi.getGroupNames()); final UserGroupInformation targetUgi = ImpersonationUtil.createProxyUgi(targetName); final Set<String> targetGroups = Sets.newHashSet(targetUgi.getGroupNames()); for (final ImpersonationPolicy definition : policies) { // check if proxy user qualifies within this policy if (definition.proxy_principals.users.contains(proxyName) || !Sets.intersection(definition.proxy_principals.groups, proxyGroups).isEmpty()) { // check if target qualifies within this policy if (definition.target_principals.users.contains(targetName) || definition.target_principals.users.contains(STAR) || !Sets.intersection(definition.target_principals.groups, targetGroups).isEmpty() || definition.target_principals.groups.contains(STAR)) { return true; } } } return false; }
From source file:org.semanticweb.elk.justifications.BloomSet.java
@Override public Justification<C, A> removeElements(Set<? extends A> removed) { if (Sets.intersection(this, removed).isEmpty()) { return this; }/*from ww w . j av a 2 s .c o m*/ // else return new BloomSet<C, A>(conclusion_, Sets.difference(this, removed)); }
From source file:alluxio.util.JvmPauseMonitor.java
private String formatLogString(long extraSleepTime, Map<String, GarbageCollectorMXBean> gcMXBeanMapBeforeSleep, Map<String, GarbageCollectorMXBean> gcMXBeanMapAfterSleep) { List<String> beanDiffs = Lists.newArrayList(); GarbageCollectorMXBean oldBean; GarbageCollectorMXBean newBean; Set<String> nameSet = Sets.intersection(gcMXBeanMapBeforeSleep.keySet(), gcMXBeanMapAfterSleep.keySet()); for (String name : nameSet) { oldBean = gcMXBeanMapBeforeSleep.get(name); newBean = gcMXBeanMapAfterSleep.get(name); if (oldBean == null) { beanDiffs.add("new GCBean created name= '" + newBean.getName() + " count=" + newBean.getCollectionCount() + " time=" + newBean.getCollectionTime() + "ms"); } else if (newBean == null) { beanDiffs.add("old GCBean canceled name= '" + oldBean.getName() + " count=" + oldBean.getCollectionCount() + " time=" + oldBean.getCollectionTime() + "ms"); } else {/* www . j a v a2 s.c o m*/ if (oldBean.getCollectionTime() != newBean.getCollectionTime() || oldBean.getCollectionCount() != newBean.getCollectionCount()) { beanDiffs.add("GC name= '" + newBean.getName() + " count=" + newBean.getCollectionCount() + " time=" + newBean.getCollectionTime() + "ms"); } } } StringBuilder ret = new StringBuilder().append("JVM paused ").append(extraSleepTime).append("ms\n"); if (beanDiffs.isEmpty()) { ret.append("No GCs detected "); } else { ret.append("GC list:\n" + Joiner.on("\n").join(beanDiffs)); } ret.append("\n").append(getMemoryInfo()); return ret.toString(); }