Java Code Examples for com.google.common.collect.ImmutableSet.contains()

The following are Jave code examples for showing how to use contains() of the com.google.common.collect.ImmutableSet class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: n4js   File: TokenTypeRewriter.java   Source Code and License Vote up 6 votes
private static void rewriteIdentifiers(N4JSGrammarAccess ga,
		ImmutableMap.Builder<AbstractElement, Integer> builder) {
	ImmutableSet<AbstractRule> identifierRules = ImmutableSet.of(
			ga.getBindingIdentifierRule(),
			ga.getIdentifierNameRule(),
			ga.getIDENTIFIERRule());
	for (ParserRule rule : GrammarUtil.allParserRules(ga.getGrammar())) {
		for (EObject obj : EcoreUtil2.eAllContents(rule.getAlternatives())) {
			if (obj instanceof Assignment) {
				Assignment assignment = (Assignment) obj;
				AbstractElement terminal = assignment.getTerminal();
				int type = InternalN4JSParser.RULE_IDENTIFIER;
				if (terminal instanceof CrossReference) {
					terminal = ((CrossReference) terminal).getTerminal();
					type = IDENTIFIER_REF_TOKEN;
				}
				if (terminal instanceof RuleCall) {
					AbstractRule calledRule = ((RuleCall) terminal).getRule();
					if (identifierRules.contains(calledRule)) {
						builder.put(assignment, type);
					}
				}
			}
		}
	}
}
 
Example 2
Project: Elasticsearch   File: GatewayMetaState.java   Source Code and License Vote up 6 votes
/**
 * Loads the current meta state for each index in the new cluster state and checks if it has to be persisted.
 * Each index state that should be written to disk will be returned. This is only run for data only nodes.
 * It will return only the states for indices that actually have a shard allocated on the current node.
 *
 * @param previouslyWrittenIndices    A list of indices for which the state was already written before
 * @param potentiallyUnwrittenIndices The list of indices for which state should potentially be written
 * @param previousMetaData            The last meta data we know of. meta data for all indices in previouslyWrittenIndices list is persisted now
 * @param newMetaData                 The new metadata
 * @return iterable over all indices states that should be written to disk
 */
public static Iterable<GatewayMetaState.IndexMetaWriteInfo> resolveStatesToBeWritten(ImmutableSet<String> previouslyWrittenIndices, Set<String> potentiallyUnwrittenIndices, MetaData previousMetaData, MetaData newMetaData) {
    List<GatewayMetaState.IndexMetaWriteInfo> indicesToWrite = new ArrayList<>();
    for (String index : potentiallyUnwrittenIndices) {
        IndexMetaData newIndexMetaData = newMetaData.index(index);
        IndexMetaData previousIndexMetaData = previousMetaData == null ? null : previousMetaData.index(index);
        String writeReason = null;
        if (previouslyWrittenIndices.contains(index) == false || previousIndexMetaData == null) {
            writeReason = "freshly created";
        } else if (previousIndexMetaData.getVersion() != newIndexMetaData.getVersion()) {
            writeReason = "version changed from [" + previousIndexMetaData.getVersion() + "] to [" + newIndexMetaData.getVersion() + "]";
        }
        if (writeReason != null) {
            indicesToWrite.add(new GatewayMetaState.IndexMetaWriteInfo(newIndexMetaData, previousIndexMetaData, writeReason));
        }
    }
    return indicesToWrite;
}
 
Example 3
Project: Elasticsearch   File: GatewayMetaState.java   Source Code and License Vote up 6 votes
public static Set<String> getRelevantIndicesOnDataOnlyNode(ClusterState state, ClusterState previousState, ImmutableSet<String> previouslyWrittenIndices) {
    RoutingNode newRoutingNode = state.getRoutingNodes().node(state.nodes().localNodeId());
    if (newRoutingNode == null) {
        throw new IllegalStateException("cluster state does not contain this node - cannot write index meta state");
    }
    Set<String> indices = new HashSet<>();
    for (ShardRouting routing : newRoutingNode) {
        indices.add(routing.index());
    }
    // we have to check the meta data also: closed indices will not appear in the routing table, but we must still write the state if we have it written on disk previously
    for (IndexMetaData indexMetaData : state.metaData()) {
        boolean isOrWasClosed = indexMetaData.getState().equals(IndexMetaData.State.CLOSE);
        // if the index is open we might still have to write the state if it just transitioned from closed to open
        // so we have to check for that as well.
        IndexMetaData previousMetaData = previousState.metaData().getIndices().get(indexMetaData.getIndex());
        if (previousMetaData != null) {
            isOrWasClosed = isOrWasClosed || previousMetaData.getState().equals(IndexMetaData.State.CLOSE);
        }
        if (previouslyWrittenIndices.contains(indexMetaData.getIndex()) && isOrWasClosed) {
            indices.add(indexMetaData.getIndex());
        }
    }
    return indices;
}
 
Example 4
Project: de.flapdoodle.solid   File: Tree.java   Source Code and License Vote up 6 votes
private static ImmutableList<Node> filter(ImmutableList<Node> nodeTree, ImmutableSet<String> knownNames, ImmutableSet<String> src, int level) {
	ImmutableList.Builder<Node> builder = ImmutableList.builder();

	for (String current : src) {
		if (!knownNames.contains(current)) {
			if (level==0) {
				builder.add(Node.builder().name(current).build());
			}
		} else {
			Optional<Node> matchingNode = nodeTree.stream()
				.filter(n -> n.name().equals(current))
				.findAny();
			matchingNode.ifPresent(node -> {
				builder.add(Node.builder()
						.name(current)
						.addAllChildren(filter(node.children(), knownNames, src, level+1))
						.build());
			});
		}
	}
	return builder.build();
}
 
Example 5
Project: GitHub   File: BeanFriendlyTest.java   Source Code and License Vote up 5 votes
@Test
public void modifiableAsJavaBean() throws Exception {
  ImmutableSet<String> rwProperties =
      ImmutableSet.of("primary", "id", "description", "names", "options", "extra");

  FluentIterable<PropertyDescriptor> propertyDescriptors =
      FluentIterable.of(
          Introspector.getBeanInfo(ModifiableBeanFriendly.class)
              .getPropertyDescriptors());

  check(propertyDescriptors.transform(p -> p.getName()).toSet().containsAll(rwProperties));

  for (PropertyDescriptor pd : propertyDescriptors) {
    check(pd.getReadMethod()).notNull();
    if (rwProperties.contains(pd.getName())) {
      check(pd.getWriteMethod()).notNull();
    }
  }

  ModifiableBeanFriendly bean = new ModifiableBeanFriendly();
  bean.setPrimary(true);
  bean.setDescription("description");
  bean.setId(1000);
  bean.setNames(ImmutableList.of("name"));
  bean.addNames("name2");
  bean.putOptions("foo", "bar");

  // This bean can become immutable.
  BeanFriendly immutableBean = bean.toImmutable();
  check(immutableBean.isPrimary());
  check(immutableBean.getDescription()).is("description");
  check(immutableBean.getId()).is(1000);
  check(immutableBean.getNames()).isOf("name", "name2");
  check(immutableBean.getOptions()).is(ImmutableMap.of("foo", "bar"));
}
 
Example 6
Project: n4js   File: TokenTypeRewriter.java   Source Code and License Vote up 5 votes
private Integer getTokenType(String text, ImmutableSet<String> set, int type, Integer refinedType) {
	if (refinedType != null) {
		if (set.contains(text)) {
			throw new RuntimeException("duplicate keyword declaration: " + text);
		}
		return refinedType;
	}
	if (set.contains(text)) {
		return type;
	}
	return null;
}
 
Example 7
Project: tac-kbp-eal   File: OnlyMostSpecificTemporal.java   Source Code and License Vote up 5 votes
@Override
public ResponseMapping computeResponseTransformation(final AnswerKey answerKey) {
  final ImmutableSet<TypeRoleFillerRealis> bannedResponseSignatures =
      computeBannedResponseSignatures(answerKey);

  final ImmutableSet.Builder<Response> toDelete = ImmutableSet.builder();
  for (final Response response : answerKey.allResponses()) {
    if (bannedResponseSignatures.contains(responseSignature(response))) {
      toDelete.add(response);
    }
  }

  return ResponseMapping.create(ImmutableMap.<Response, Response>of(), toDelete.build());
}
 
Example 8
Project: guava-mock   File: HttpHeadersTest.java   Source Code and License Vote up 5 votes
private static String upperToHttpHeaderName(String constantName,
    ImmutableBiMap<String, String> specialCases, ImmutableSet<String> uppercaseAcronyms) {
  if (specialCases.containsKey(constantName)) {
    return specialCases.get(constantName);
  }
  List<String> parts = Lists.newArrayList();
  for (String part : SPLITTER.split(constantName)) {
    if (!uppercaseAcronyms.contains(part)) {
      part = part.charAt(0) + Ascii.toLowerCase(part.substring(1));
    }
    parts.add(part);
  }
  return JOINER.join(parts);
}
 
Example 9
Project: javaide   File: ImportOrderer.java   Source Code and License Vote up 5 votes
/**
 * Returns the index of the first place where one of the given identifiers occurs, or {@code
 * Optional.absent()} if there is none.
 *
 * @param start       the index to start looking at
 * @param identifiers the identifiers to look for
 */
private Optional<Integer> findIdentifier(int start, ImmutableSet<String> identifiers) {
    for (int i = start; i < toks.size(); i++) {
        if (isIdentifierToken(i)) {
            String id = tokenAt(i);
            if (identifiers.contains(id)) {
                return Optional.of(i);
            }
        }
    }
    return Optional.absent();
}
 
Example 10
Project: googles-monorepo-demo   File: BloomFilterTest.java   Source Code and License Vote up 5 votes
public void testCreateAndCheckMitz32BloomFilterWithKnownFalsePositives() {
  int numInsertions = 1000000;
  BloomFilter<String> bf = BloomFilter.create(
      Funnels.unencodedCharsFunnel(), numInsertions, 0.03,
      BloomFilterStrategies.MURMUR128_MITZ_32);

  // Insert "numInsertions" even numbers into the BF.
  for (int i = 0; i < numInsertions * 2; i += 2) {
    bf.put(Integer.toString(i));
  }

  // Assert that the BF "might" have all of the even numbers.
  for (int i = 0; i < numInsertions * 2; i += 2) {
    assertTrue(bf.mightContain(Integer.toString(i)));
  }

  // Now we check for known false positives using a set of known false positives.
  // (These are all of the false positives under 900.)
  ImmutableSet<Integer> falsePositives = ImmutableSet.of(
      49, 51, 59, 163, 199, 321, 325, 363, 367, 469, 545, 561, 727, 769, 773, 781);
  for (int i = 1; i < 900; i += 2) {
    if (!falsePositives.contains(i)) {
      assertFalse("BF should not contain " + i, bf.mightContain(Integer.toString(i)));
    }
  }

  // Check that there are exactly 29824 false positives for this BF.
  int knownNumberOfFalsePositives = 29824;
  int numFpp = 0;
  for (int i = 1; i < numInsertions * 2; i += 2) {
    if (bf.mightContain(Integer.toString(i))) {
      numFpp++;
    }
  }
  assertEquals(knownNumberOfFalsePositives, numFpp);
  double actualFpp = (double) knownNumberOfFalsePositives / numInsertions;
  double expectedFpp = bf.expectedFpp();
  // The normal order of (expected, actual) is reversed here on purpose.
  assertEquals(actualFpp, expectedFpp, 0.00015);
}
 
Example 11
Project: googles-monorepo-demo   File: BloomFilterTest.java   Source Code and License Vote up 5 votes
public void testCreateAndCheckBloomFilterWithKnownFalsePositives64() {
  int numInsertions = 1000000;
  BloomFilter<String> bf = BloomFilter.create(
      Funnels.unencodedCharsFunnel(), numInsertions, 0.03,
      BloomFilterStrategies.MURMUR128_MITZ_64);

  // Insert "numInsertions" even numbers into the BF.
  for (int i = 0; i < numInsertions * 2; i += 2) {
    bf.put(Integer.toString(i));
  }

  // Assert that the BF "might" have all of the even numbers.
  for (int i = 0; i < numInsertions * 2; i += 2) {
    assertTrue(bf.mightContain(Integer.toString(i)));
  }

  // Now we check for known false positives using a set of known false positives.
  // (These are all of the false positives under 900.)
  ImmutableSet<Integer> falsePositives = ImmutableSet.of(
      15, 25, 287, 319, 381, 399, 421, 465, 529, 697, 767, 857);
  for (int i = 1; i < 900; i += 2) {
    if (!falsePositives.contains(i)) {
      assertFalse("BF should not contain " + i, bf.mightContain(Integer.toString(i)));
    }
  }

  // Check that there are exactly 30104 false positives for this BF.
  int knownNumberOfFalsePositives = 30104;
  int numFpp = 0;
  for (int i = 1; i < numInsertions * 2; i += 2) {
    if (bf.mightContain(Integer.toString(i))) {
      numFpp++;
    }
  }
  assertEquals(knownNumberOfFalsePositives, numFpp);
  double actualFpp = (double) knownNumberOfFalsePositives / numInsertions;
  double expectedFpp = bf.expectedFpp();
  // The normal order of (expected, actual) is reversed here on purpose.
  assertEquals(actualFpp, expectedFpp, 0.00033);
}
 
Example 12
Project: googles-monorepo-demo   File: BloomFilterTest.java   Source Code and License Vote up 5 votes
public void testCreateAndCheckBloomFilterWithKnownUtf8FalsePositives64() {
  int numInsertions = 1000000;
  BloomFilter<String> bf = BloomFilter.create(
      Funnels.stringFunnel(UTF_8), numInsertions, 0.03,
      BloomFilterStrategies.MURMUR128_MITZ_64);

  // Insert "numInsertions" even numbers into the BF.
  for (int i = 0; i < numInsertions * 2; i += 2) {
    bf.put(Integer.toString(i));
  }

  // Assert that the BF "might" have all of the even numbers.
  for (int i = 0; i < numInsertions * 2; i += 2) {
    assertTrue(bf.mightContain(Integer.toString(i)));
  }

  // Now we check for known false positives using a set of known false positives.
  // (These are all of the false positives under 900.)
  ImmutableSet<Integer> falsePositives =
      ImmutableSet.of(129, 471, 723, 89, 751, 835, 871);
  for (int i = 1; i < 900; i += 2) {
    if (!falsePositives.contains(i)) {
      assertFalse("BF should not contain " + i, bf.mightContain(Integer.toString(i)));
    }
  }

  // Check that there are exactly 29763 false positives for this BF.
  int knownNumberOfFalsePositives = 29763;
  int numFpp = 0;
  for (int i = 1; i < numInsertions * 2; i += 2) {
    if (bf.mightContain(Integer.toString(i))) {
      numFpp++;
    }
  }
  assertEquals(knownNumberOfFalsePositives, numFpp);
  double actualFpp = (double) knownNumberOfFalsePositives / numInsertions;
  double expectedFpp = bf.expectedFpp();
  // The normal order of (expected, actual) is reversed here on purpose.
  assertEquals(actualFpp, expectedFpp, 0.00033);
}
 
Example 13
Project: googles-monorepo-demo   File: HttpHeadersTest.java   Source Code and License Vote up 5 votes
private static String upperToHttpHeaderName(String constantName,
    ImmutableBiMap<String, String> specialCases, ImmutableSet<String> uppercaseAcronyms) {
  if (specialCases.containsKey(constantName)) {
    return specialCases.get(constantName);
  }
  List<String> parts = Lists.newArrayList();
  for (String part : SPLITTER.split(constantName)) {
    if (!uppercaseAcronyms.contains(part)) {
      part = part.charAt(0) + Ascii.toLowerCase(part.substring(1));
    }
    parts.add(part);
  }
  return JOINER.join(parts);
}
 
Example 14
Project: r8   File: InterfaceMethodRewriter.java   Source Code and License Vote up 4 votes
private boolean isInMainDexList(DexType iface) {
  ImmutableSet<DexType> list = converter.application.mainDexList;
  return list.contains(iface);
}
 
Example 15
Project: tac-kbp-eal   File: AbstractLinkingStrategy.java   Source Code and License Vote up 4 votes
@Override
public LinkingStore wrap(final Iterable<Symbol> docIDs) {
  final ImmutableSet<Symbol> docIdSet = ImmutableSet.copyOf(docIDs);

  return new LinkingStore() {
    @Override
    public ImmutableSet<Symbol> docIDs() throws IOException {
      return docIdSet;
    }

    @Override
    public Optional<ResponseLinking> read(final ArgumentOutput argumentOutput) throws IOException {
      if (docIdSet.contains(argumentOutput.docId())) {
        return Optional.of(linkResponses(argumentOutput));
      } else {
        return Optional.absent();
      }
    }

    @Override
    public Optional<ResponseLinking> read(final AnswerKey answerKey) throws IOException {

      if (docIdSet.contains(answerKey.docId())) {
        return Optional.of(linkResponses(answerKey));
      } else {
        return Optional.absent();
      }
    }

    @Override
    public void write(final ResponseLinking toWrite) throws IOException {
      throw new UnsupportedOperationException();
    }

    @Override
    public void close() throws IOException {
      // do nothing, assume underlying argumentStore will be closed separately
    }

    @Override
    public Optional<ResponseLinking> readTransformingIDs(final Symbol docID,
        final Set<Response> responses,
        final Optional<ImmutableMap<String, String>> foreignResponseIDToLocal,
        final Optional<ImmutableMap.Builder<String, String>> foreignLinkingIDToLocal)
        throws IOException {
      throw new UnsupportedOperationException();
    }
  };
}
 
Example 16
Project: guava-mock   File: BloomFilterTest.java   Source Code and License Vote up 4 votes
public void testCreateAndCheckMitz32BloomFilterWithKnownFalsePositives() {
  int numInsertions = 1000000;
  BloomFilter<String> bf = BloomFilter.create(
      Funnels.unencodedCharsFunnel(), numInsertions, 0.03,
      BloomFilterStrategies.MURMUR128_MITZ_32);

  // Insert "numInsertions" even numbers into the BF.
  for (int i = 0; i < numInsertions * 2; i += 2) {
    bf.put(Integer.toString(i));
  }
  assertApproximateElementCountGuess(bf, numInsertions);

  // Assert that the BF "might" have all of the even numbers.
  for (int i = 0; i < numInsertions * 2; i += 2) {
    assertTrue(bf.mightContain(Integer.toString(i)));
  }

  // Now we check for known false positives using a set of known false positives.
  // (These are all of the false positives under 900.)
  ImmutableSet<Integer> falsePositives = ImmutableSet.of(
      49, 51, 59, 163, 199, 321, 325, 363, 367, 469, 545, 561, 727, 769, 773, 781);
  for (int i = 1; i < 900; i += 2) {
    if (!falsePositives.contains(i)) {
      assertFalse("BF should not contain " + i, bf.mightContain(Integer.toString(i)));
    }
  }

  // Check that there are exactly 29824 false positives for this BF.
  int knownNumberOfFalsePositives = 29824;
  int numFpp = 0;
  for (int i = 1; i < numInsertions * 2; i += 2) {
    if (bf.mightContain(Integer.toString(i))) {
      numFpp++;
    }
  }
  assertEquals(knownNumberOfFalsePositives, numFpp);
  double actualFpp = (double) knownNumberOfFalsePositives / numInsertions;
  double expectedFpp = bf.expectedFpp();
  // The normal order of (expected, actual) is reversed here on purpose.
  assertEquals(actualFpp, expectedFpp, 0.00015);
}
 
Example 17
Project: guava-mock   File: BloomFilterTest.java   Source Code and License Vote up 4 votes
public void testCreateAndCheckBloomFilterWithKnownFalsePositives64() {
  int numInsertions = 1000000;
  BloomFilter<String> bf = BloomFilter.create(
      Funnels.unencodedCharsFunnel(), numInsertions, 0.03,
      BloomFilterStrategies.MURMUR128_MITZ_64);

  // Insert "numInsertions" even numbers into the BF.
  for (int i = 0; i < numInsertions * 2; i += 2) {
    bf.put(Integer.toString(i));
  }
  assertApproximateElementCountGuess(bf, numInsertions);

  // Assert that the BF "might" have all of the even numbers.
  for (int i = 0; i < numInsertions * 2; i += 2) {
    assertTrue(bf.mightContain(Integer.toString(i)));
  }

  // Now we check for known false positives using a set of known false positives.
  // (These are all of the false positives under 900.)
  ImmutableSet<Integer> falsePositives = ImmutableSet.of(
      15, 25, 287, 319, 381, 399, 421, 465, 529, 697, 767, 857);
  for (int i = 1; i < 900; i += 2) {
    if (!falsePositives.contains(i)) {
      assertFalse("BF should not contain " + i, bf.mightContain(Integer.toString(i)));
    }
  }

  // Check that there are exactly 30104 false positives for this BF.
  int knownNumberOfFalsePositives = 30104;
  int numFpp = 0;
  for (int i = 1; i < numInsertions * 2; i += 2) {
    if (bf.mightContain(Integer.toString(i))) {
      numFpp++;
    }
  }
  assertEquals(knownNumberOfFalsePositives, numFpp);
  double actualFpp = (double) knownNumberOfFalsePositives / numInsertions;
  double expectedFpp = bf.expectedFpp();
  // The normal order of (expected, actual) is reversed here on purpose.
  assertEquals(actualFpp, expectedFpp, 0.00033);
}
 
Example 18
Project: guava-mock   File: BloomFilterTest.java   Source Code and License Vote up 4 votes
public void testCreateAndCheckBloomFilterWithKnownUtf8FalsePositives64() {
  int numInsertions = 1000000;
  BloomFilter<String> bf = BloomFilter.create(
      Funnels.stringFunnel(UTF_8), numInsertions, 0.03,
      BloomFilterStrategies.MURMUR128_MITZ_64);

  // Insert "numInsertions" even numbers into the BF.
  for (int i = 0; i < numInsertions * 2; i += 2) {
    bf.put(Integer.toString(i));
  }
  assertApproximateElementCountGuess(bf, numInsertions);

  // Assert that the BF "might" have all of the even numbers.
  for (int i = 0; i < numInsertions * 2; i += 2) {
    assertTrue(bf.mightContain(Integer.toString(i)));
  }

  // Now we check for known false positives using a set of known false positives.
  // (These are all of the false positives under 900.)
  ImmutableSet<Integer> falsePositives =
      ImmutableSet.of(129, 471, 723, 89, 751, 835, 871);
  for (int i = 1; i < 900; i += 2) {
    if (!falsePositives.contains(i)) {
      assertFalse("BF should not contain " + i, bf.mightContain(Integer.toString(i)));
    }
  }

  // Check that there are exactly 29763 false positives for this BF.
  int knownNumberOfFalsePositives = 29763;
  int numFpp = 0;
  for (int i = 1; i < numInsertions * 2; i += 2) {
    if (bf.mightContain(Integer.toString(i))) {
      numFpp++;
    }
  }
  assertEquals(knownNumberOfFalsePositives, numFpp);
  double actualFpp = (double) knownNumberOfFalsePositives / numInsertions;
  double expectedFpp = bf.expectedFpp();
  // The normal order of (expected, actual) is reversed here on purpose.
  assertEquals(actualFpp, expectedFpp, 0.00033);
}