Java Code Examples for com.google.common.collect.ImmutableSetMultimap#of()

The following examples show how to use com.google.common.collect.ImmutableSetMultimap#of() . 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: RoleInferenceIT.java    From grakn with GNU Affero General Public License v3.0 6 votes vote down vote up
@Test
public void testRoleInference_TypedTernaryRelationWithMetaRoles_MetaRolesShouldBeOverwritten(){
    Transaction tx = roleInferenceSetSession.transaction(Transaction.Type.WRITE);
    ReasonerQueryFactory reasonerQueryFactory = ((TestTransactionProvider.TestTransaction)tx).reasonerQueryFactory();

    String patternString = "{ (role: $x, role: $y, role: $z); $x isa entity1; $y isa entity2; $z isa entity3; };";
    String patternString2 = "{ (role: $x, role: $y, role: $z) isa ternary; $x isa entity1; $y isa entity2; $z isa entity3; };";

    ImmutableSetMultimap<Role, Variable> correctRoleMap = ImmutableSetMultimap.of(
            tx.getRole("role1"), new Variable("x"),
            tx.getRole("role2"), new Variable("y"),
            tx.getRole("role3"), new Variable("z"));
    roleInference(patternString, correctRoleMap, reasonerQueryFactory);
    roleInference(patternString2, correctRoleMap, reasonerQueryFactory);
    tx.close();
}
 
Example 2
Source File: RdeStagingMapperTest.java    From nomulus with Apache License 2.0 6 votes vote down vote up
@BeforeEach
void beforeEach() {
  // Two real registrars have been created by AppEngineRule, named "New Registrar" and "The
  // Registrar". Create one included registrar (external_monitoring) and two excluded ones.
  Registrar monitoringRegistrar =
      persistNewRegistrar("monitoring", "monitoring", Registrar.Type.MONITORING, null);
  Registrar testRegistrar = persistNewRegistrar("test", "test", Registrar.Type.TEST, null);
  Registrar externalMonitoringRegistrar =
      persistNewRegistrar(
          "externalmonitor", "external_monitoring", Registrar.Type.EXTERNAL_MONITORING, 9997L);

  // Set Registrar states which are required for reporting.
  tm().transact(
          () ->
              tm().saveNewOrUpdateAll(
                      ImmutableList.of(
                          externalMonitoringRegistrar.asBuilder().setState(State.ACTIVE).build(),
                          testRegistrar.asBuilder().setState(State.ACTIVE).build(),
                          monitoringRegistrar.asBuilder().setState(State.ACTIVE).build())));

  rdeStagingMapper =
      new RdeStagingMapper(ValidationMode.STRICT, ImmutableSetMultimap.of("1", pendingDeposit));
  rdeStagingMapper.setContext(context);
}
 
Example 3
Source File: RoleInferenceIT.java    From grakn with GNU Affero General Public License v3.0 6 votes vote down vote up
@Test
public void testRoleInference_TypedTernaryRelation_TypesPlaySubRoles_SubRolesAreCorrectlyIdentified(){
    Transaction tx = roleInferenceSetSession.transaction(Transaction.Type.WRITE);
    ReasonerQueryFactory reasonerQueryFactory = ((TestTransactionProvider.TestTransaction)tx).reasonerQueryFactory();

    String patternString = "{ (role: $x, role: $y, role: $z); $x isa anotherEntity1; $y isa anotherEntity2; $z isa anotherEntity3; };";
    String patternString2 = "{ (role: $x, role: $y, role: $z) isa ternary; $x isa anotherEntity1; $y isa anotherEntity2; $z isa anotherEntity3; };";

    ImmutableSetMultimap<Role, Variable> correctRoleMap = ImmutableSetMultimap.of(
            tx.getRole("subRole1"), new Variable("x"),
            tx.getRole("subRole2"), new Variable("y"),
            tx.getRole("subRole3"), new Variable("z"));
    roleInference(patternString, correctRoleMap, reasonerQueryFactory);
    roleInference(patternString2, correctRoleMap, reasonerQueryFactory);
    tx.close();
}
 
Example 4
Source File: RoleInferenceIT.java    From grakn with GNU Affero General Public License v3.0 6 votes vote down vote up
@Test
public void testRoleInference_TypedTernaryRelation_TypesCanPlayMultipleRoles_MetaRoleIsChosen(){
    Transaction tx = roleInferenceSetSession.transaction(Transaction.Type.WRITE);
    ReasonerQueryFactory reasonerQueryFactory = ((TestTransactionProvider.TestTransaction)tx).reasonerQueryFactory();

    String patternString = "{ ($x, $y, $z); $x isa genericEntity; $y isa genericEntity; $z isa genericEntity; };";
    String patternString2 = "{ ($x, $y, $z) isa ternary; $x isa genericEntity; $y isa genericEntity; $z isa genericEntity; };";

    ImmutableSetMultimap<Role, Variable> correctRoleMap = ImmutableSetMultimap.of(
            tx.getRole("role"), new Variable("x"),
            tx.getRole("role"), new Variable("y"),
            tx.getRole("role"), new Variable("z"));
    roleInference(patternString, correctRoleMap, reasonerQueryFactory);
    roleInference(patternString2, correctRoleMap, reasonerQueryFactory);
    tx.close();
}
 
Example 5
Source File: RoleInferenceIT.java    From grakn with GNU Affero General Public License v3.0 6 votes vote down vote up
@Test //each type maps to a specific role
public void testRoleInference_TypedTernaryRelationWithKnownRole(){
    Transaction tx = roleInferenceSetSession.transaction(Transaction.Type.WRITE);
    ReasonerQueryFactory reasonerQueryFactory = ((TestTransactionProvider.TestTransaction)tx).reasonerQueryFactory();

    String patternString = "{  ($x, $y, role3: $z);$x isa entity1;$y isa entity2;  };";
    String patternString2 = "{ ($x, $y, role3: $z) isa ternary;$x isa entity1;$y isa entity2; };";

    ImmutableSetMultimap<Role, Variable> correctRoleMap = ImmutableSetMultimap.of(
            tx.getRole("role1"), new Variable("x"),
            tx.getRole("role2"), new Variable("y"),
            tx.getRole("role3"), new Variable("z"));
    roleInference(patternString, correctRoleMap, reasonerQueryFactory);
    roleInference(patternString2, correctRoleMap, reasonerQueryFactory);
    tx.close();
}
 
Example 6
Source File: ZipFilterActionTest.java    From bazel with Apache License 2.0 6 votes vote down vote up
@Test public void testZipEntryFilter_ErrorOnMismatch() throws Exception {
  ZipFilterEntryFilter filter =
      new ZipFilterEntryFilter(
          ".*R.class.*",
          ImmutableSetMultimap.of("foo.class", 1L, "baz.class", 2L),
          ImmutableMap.of("foo.class", 1L, "bar.class", 2L, "baz.class", 3L, "res/R.class", 4L),
          HashMismatchCheckMode.ERROR);
  filter.accept("foo.class", callback);
  callback.assertOp(FilterOperation.SKIP);
  filter.accept("bar.class", callback);
  callback.assertOp(FilterOperation.COPY);
  filter.accept("res/R.class", callback);
  callback.assertOp(FilterOperation.SKIP);
  filter.accept("baz.class", callback);
  assertThat(filter.sawErrors()).isTrue();
}
 
Example 7
Source File: HashGenerationOptimizer.java    From presto with Apache License 2.0 5 votes vote down vote up
public HashComputationSet(Optional<HashComputation> hash)
{
    requireNonNull(hash, "hash is null");
    if (hash.isPresent()) {
        this.hashes = ImmutableSetMultimap.of(hash.get(), hash.get());
    }
    else {
        this.hashes = ImmutableSetMultimap.of();
    }
}
 
Example 8
Source File: FreemarkerTest.java    From cloud-opensource-java with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws IOException {
  Artifact artifact = new DefaultArtifact("com.google:foo:1.0.0")
      .setFile(new File("foo/bar-1.2.3.jar"));
  ClassPathEntry entry = new ClassPathEntry(artifact);
  ImmutableSetMultimap<SymbolProblem, String> dummyProblems =
      ImmutableSetMultimap.of(
          new SymbolProblem(new ClassSymbol("com.foo.Bar"), ErrorType.CLASS_NOT_FOUND, null),
          "abc.def.G");
  symbolProblemTable = ImmutableMap.of(entry, dummyProblems);
}
 
Example 9
Source File: MultimapGwtTest.java    From gwt-jackson with Apache License 2.0 5 votes vote down vote up
public void testSerialization() {
    BeanWithMultimapTypes bean = new BeanWithMultimapTypes();

    // insertion order for both keys and values
    bean.immutableMultimap = ImmutableMultimap.of( "foo", 3, "bar", 4, "foo", 2, "foo", 5 );
    bean.immutableListMultimap = ImmutableListMultimap.of( "foo", 3, "bar", 4, "foo", 2, "foo", 5 );
    bean.multimap = LinkedListMultimap.create( bean.immutableListMultimap );
    bean.setMultimap = LinkedHashMultimap.create( bean.immutableListMultimap );
    bean.linkedHashMultimap = LinkedHashMultimap.create( bean.immutableMultimap );
    bean.linkedListMultimap = LinkedListMultimap.create( bean.immutableListMultimap );
    bean.listMultimap = LinkedListMultimap.create( bean.immutableMultimap );

    // no order
    bean.immutableSetMultimap = ImmutableSetMultimap.of( "foo", 3 );
    bean.hashMultimap = HashMultimap.create( bean.immutableSetMultimap );

    // natural ordering on both keys and values
    bean.sortedSetMultimap = TreeMultimap.create( bean.immutableMultimap );
    bean.treeMultimap = TreeMultimap.create( bean.immutableMultimap );

    // insertion order on values but no order on keys
    bean.arrayListMultimap = ArrayListMultimap.create( ImmutableListMultimap.of( "foo", 3, "foo", 2, "foo", 5 ) );

    String expected = "{" +
            "\"multimap\":{\"foo\":[3,2,5],\"bar\":[4]}," +
            "\"immutableMultimap\":{\"foo\":[3,2,5],\"bar\":[4]}," +
            "\"immutableSetMultimap\":{\"foo\":[3]}," +
            "\"immutableListMultimap\":{\"foo\":[3,2,5],\"bar\":[4]}," +
            "\"setMultimap\":{\"foo\":[3,2,5],\"bar\":[4]}," +
            "\"hashMultimap\":{\"foo\":[3]}," +
            "\"linkedHashMultimap\":{\"foo\":[3,2,5],\"bar\":[4]}," +
            "\"sortedSetMultimap\":{\"bar\":[4],\"foo\":[2,3,5]}," +
            "\"treeMultimap\":{\"bar\":[4],\"foo\":[2,3,5]}," +
            "\"listMultimap\":{\"foo\":[3,2,5],\"bar\":[4]}," +
            "\"arrayListMultimap\":{\"foo\":[3,2,5]}," +
            "\"linkedListMultimap\":{\"foo\":[3,2,5],\"bar\":[4]}" +
            "}";

    assertEquals( expected, BeanWithMultimapTypesMapper.INSTANCE.write( bean ) );
}
 
Example 10
Source File: RoleInferenceIT.java    From grakn with GNU Affero General Public License v3.0 5 votes vote down vote up
@Test //entity1 plays role1 but entity2 plays roles role1, role2 hence ambiguous and metarole has to be assigned, EXPECTED TO CHANGE WITH CARDINALITY CONSTRAINTS
public void testRoleInference_WithMetaType(){
    Transaction tx = ruleApplicabilitySetSession.transaction(Transaction.Type.WRITE);
    ReasonerQueryFactory reasonerQueryFactory = ((TestTransactionProvider.TestTransaction)tx).reasonerQueryFactory();

    String relationString = "{ ($x, $y, $z) isa ternary; $x isa singleRoleEntity; $y isa twoRoleEntity; $z isa entity; };";
    RelationAtom relation = (RelationAtom) reasonerQueryFactory.atomic(conjunction(relationString)).getAtom();
    ImmutableSetMultimap<Role, Variable> roleMap = ImmutableSetMultimap.of(
            tx.getRole("someRole"), new Variable("x"),
            tx.getRole("role"), new Variable("y"),
            tx.getRole("role"), new Variable("z"));
    assertEquals(roleMap, roleSetMap(relation.getRoleVarMap()));
    tx.close();
}
 
Example 11
Source File: MultimapGwtTest.java    From gwt-jackson with Apache License 2.0 5 votes vote down vote up
public void testDeserialization() {
    String input = "{" +
            "\"multimap\":{\"foo\":[3,2,5],\"bar\":[4]}," +
            "\"immutableMultimap\":{\"foo\":[3,2,5],\"bar\":[4]}," +
            "\"immutableSetMultimap\":{\"foo\":[3]}," +
            "\"immutableListMultimap\":{\"foo\":[3,2,5],\"bar\":[4]}," +
            "\"setMultimap\":{\"foo\":[3,2,5],\"bar\":[4]}," +
            "\"hashMultimap\":{\"foo\":[3]}," +
            "\"linkedHashMultimap\":{\"foo\":[3,2,5],\"bar\":[4]}," +
            "\"sortedSetMultimap\":{\"foo\":[3,2,5],\"bar\":[4]}," +
            "\"treeMultimap\":{\"foo\":[3,2,5],\"bar\":[4]}," +
            "\"listMultimap\":{\"foo\":[3,2,5],\"bar\":[4]}," +
            "\"arrayListMultimap\":{\"foo\":[3,2,5]}," +
            "\"linkedListMultimap\":{\"foo\":[3,2,5],\"bar\":[4]}" +
            "}";

    BeanWithMultimapTypes result = BeanWithMultimapTypesMapper.INSTANCE.read( input );
    assertNotNull( result );

    ImmutableListMultimap<String, Integer> expectedOrderedKeysAndValues = ImmutableListMultimap
            .of( "foo", 3, "bar", 4, "foo", 2, "foo", 5 );
    ImmutableSetMultimap<String, Integer> expectedNonOrdered = ImmutableSetMultimap.of( "foo", 3 );

    assertEquals( LinkedHashMultimap.create( expectedOrderedKeysAndValues ), result.multimap );
    assertEquals( ImmutableMultimap.copyOf( expectedOrderedKeysAndValues ), result.immutableMultimap );
    assertEquals( expectedOrderedKeysAndValues, result.immutableListMultimap );
    assertEquals( LinkedHashMultimap.create( expectedOrderedKeysAndValues ), result.setMultimap );
    assertEquals( LinkedHashMultimap.create( expectedOrderedKeysAndValues ), result.linkedHashMultimap );
    assertEquals( LinkedListMultimap.create( expectedOrderedKeysAndValues ), result.listMultimap );
    assertEquals( LinkedListMultimap.create( expectedOrderedKeysAndValues ), result.linkedListMultimap );

    assertEquals( TreeMultimap.create( expectedOrderedKeysAndValues ), result.sortedSetMultimap );
    assertEquals( TreeMultimap.create( expectedOrderedKeysAndValues ), result.treeMultimap );

    assertEquals( expectedNonOrdered, result.immutableSetMultimap );
    assertEquals( HashMultimap.create( expectedNonOrdered ), result.hashMultimap );

    assertEquals( ArrayListMultimap.create( ImmutableListMultimap.of( "foo", 3, "foo", 2, "foo", 5 ) ), result.arrayListMultimap );
}
 
Example 12
Source File: MapStreamTest.java    From Strata with Apache License 2.0 5 votes vote down vote up
@Test
public void toSetMultimap() {
  Map<String, Integer> map = ImmutableMap.<String, Integer>builder()
      .put("a", 1)
      .put("aa", 2)
      .put("aaa", 1)
      .put("b", 10)
      .put("bb", 20)
      .put("c", 1)
      .build();
  SetMultimap<String, Integer> expected = ImmutableSetMultimap.of("a", 1, "a", 2, "b", 10, "b", 20, "c", 1);
  SetMultimap<String, Integer> result = MapStream.of(map).mapKeys(s -> s.substring(0, 1)).toSetMultimap();
  assertThat(result).isEqualTo(expected);
}
 
Example 13
Source File: RuleApplicabilityIT.java    From grakn with GNU Affero General Public License v3.0 5 votes vote down vote up
@Test //should assign (role : $x, role1: $y, role: $z) which is compatible with 3 ternary rules
public void relationWithUnspecifiedRoles_someRoleplayersTyped(){
    try(Transaction tx = ruleApplicabilitySession.transaction(Transaction.Type.WRITE)) {
        ReasonerQueryFactory reasonerQueryFactory = ((TestTransactionProvider.TestTransaction)tx).reasonerQueryFactory();

        String relationString = "{ ($x, $y, $z);$y isa singleRoleEntity; $z isa twoRoleEntity; };";
        RelationAtom relation = (RelationAtom) reasonerQueryFactory.atomic(conjunction(relationString)).getAtom();
        ImmutableSetMultimap<Role, Variable> roleMap = ImmutableSetMultimap.of(
                tx.getRole("role"), new Variable("x"),
                tx.getRole("someRole"), new Variable("y"),
                tx.getRole("role"), new Variable("z"));
        assertEquals(roleMap, roleSetMap(relation.getRoleVarMap()));
        assertEquals(5, relation.getApplicableRules().count());
    }
}
 
Example 14
Source File: OwnersReport.java    From buck with Apache License 2.0 5 votes vote down vote up
@VisibleForTesting
static OwnersReport generateOwnersReport(
    Cell rootCell, TargetNode<?> targetNode, String filePath) {
  Path file = rootCell.getFilesystem().getPathForRelativePath(filePath);
  if (!Files.exists(file)) {
    return new OwnersReport(
        ImmutableSetMultimap.of(),
        ImmutableSet.of(),
        ImmutableSet.of(filePath),
        ImmutableSet.of());
  } else if (!Files.isRegularFile(file)) {
    return new OwnersReport(
        ImmutableSetMultimap.of(),
        ImmutableSet.of(),
        ImmutableSet.of(),
        ImmutableSet.of(filePath));
  } else {
    Path commandInput = rootCell.getFilesystem().getPath(filePath);
    ImmutableSet<ForwardRelativePath> ruleInputs = targetNode.getInputs();
    ImmutableSet<Path> ruleInputPaths =
        ruleInputs.stream()
            .map(p -> p.toPath(commandInput.getFileSystem()))
            .collect(ImmutableSet.toImmutableSet());
    Predicate<Path> startsWith =
        input -> !commandInput.equals(input) && commandInput.startsWith(input);
    if (ruleInputPaths.contains(commandInput) || ruleInputPaths.stream().anyMatch(startsWith)) {
      return new OwnersReport(
          ImmutableSetMultimap.of(targetNode, commandInput),
          ImmutableSet.of(),
          ImmutableSet.of(),
          ImmutableSet.of());
    } else {
      return new OwnersReport(
          ImmutableSetMultimap.of(),
          ImmutableSet.of(commandInput),
          ImmutableSet.of(),
          ImmutableSet.of());
    }
  }
}
 
Example 15
Source File: TestLibraryModels.java    From NullAway with MIT License 4 votes vote down vote up
@Override
public ImmutableSetMultimap<MethodRef, Integer> explicitlyNullableParameters() {
  return ImmutableSetMultimap.of();
}
 
Example 16
Source File: TestLibraryModels.java    From NullAway with MIT License 4 votes vote down vote up
@Override
public ImmutableSetMultimap<MethodRef, Integer> nullImpliesTrueParameters() {
  return ImmutableSetMultimap.of();
}
 
Example 17
Source File: ImmutableTypeMap.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
public static <K, V> ImmutableTypeMap<K, V> of() {
    return new ImmutableTypeMap<>(ImmutableSetMultimap.of());
}
 
Example 18
Source File: SymbolProblemTest.java    From cloud-opensource-java with Apache License 2.0 4 votes vote down vote up
@Test
public void testFormatSymbolProblems() throws IOException {
  Path path = Paths.get("aaa", "bbb-1.2.3.jar");
  SymbolProblem methodSymbolProblem =
      new SymbolProblem(
          new MethodSymbol(
              "io.grpc.protobuf.ProtoUtils.marshaller",
              "marshaller",
              "(Lcom/google/protobuf/Message;)Lio/grpc/MethodDescriptor$Marshaller;",
              false),
          ErrorType.SYMBOL_NOT_FOUND,
          new ClassFile(new ClassPathEntry(path), "java.lang.Object"));

  SymbolProblem classSymbolProblem =
      new SymbolProblem(new ClassSymbol("java.lang.Integer"), ErrorType.CLASS_NOT_FOUND, null);

  Artifact artifact = new DefaultArtifact("com.google:ccc:1.2.3")
      .setFile(new File("ccc-1.2.3.jar"));
  ClassPathEntry entry = new ClassPathEntry(artifact);  

  SymbolProblem fieldSymbolProblem =
      new SymbolProblem(
          new FieldSymbol("java.lang.Integer", "MAX_VALUE", "I"),
          ErrorType.SYMBOL_NOT_FOUND,
          new ClassFile(entry, "java.lang.Integer"));

  Artifact artifact1 = new DefaultArtifact("com.google:foo:0.0.1")
      .setFile(new File("foo/foo.jar"));
  ClassPathEntry entry1 = new ClassPathEntry(artifact1);  
  ClassFile source1 = new ClassFile(entry1, "java.lang.Object");

  Artifact artifact2 = new DefaultArtifact("com.google:bar:0.0.1")
      .setFile(new File("bar/bar.jar"));
  ClassPathEntry entry2 = new ClassPathEntry(artifact2);  
  ClassFile source2 = new ClassFile(entry2, "java.lang.Integer");

  ImmutableSetMultimap<SymbolProblem, ClassFile> symbolProblems =
      ImmutableSetMultimap.of(
          methodSymbolProblem,
          source1,
          classSymbolProblem,
          source1,
          classSymbolProblem,
          source2,
          fieldSymbolProblem,
          source2);
  assertEquals(
      "("
          + path
          + ") "
          + "io.grpc.protobuf.ProtoUtils.marshaller's method "
          + "marshaller(com.google.protobuf.Message arg1) is not found;\n"
          + "  referenced by 1 class file\n"
          + "    java.lang.Object (com.google:foo:0.0.1)\n"
          + "Class java.lang.Integer is not found;\n"
          + "  referenced by 2 class files\n"
          + "    java.lang.Object (com.google:foo:0.0.1)\n"
          + "    java.lang.Integer (com.google:bar:0.0.1)\n"
          + "(com.google:ccc:1.2.3) java.lang.Integer's field MAX_VALUE is not found;\n"
          + "  referenced by 1 class file\n"
          + "    java.lang.Integer (com.google:bar:0.0.1)\n",
      SymbolProblem.formatSymbolProblems(symbolProblems));
}
 
Example 19
Source File: GitHubWriteHook.java    From copybara with Apache License 2.0 4 votes vote down vote up
@Override
public ImmutableSetMultimap<String, String> describe() {
  return prBranchToUpdate == null
      ? ImmutableSetMultimap.of()
      : ImmutableSetMultimap.of("pr_branch_to_update", prBranchToUpdate);
}
 
Example 20
Source File: GerritEndpoint.java    From copybara with Apache License 2.0 4 votes vote down vote up
@Override
public ImmutableSetMultimap<String, String> describe() {
  return ImmutableSetMultimap.of("type", "gerrit_api", "url", url);
}