Search in sources :

Example 86 with ImmutableSet

use of org.apache.beam.vendor.calcite.v1_28_0.com.google.common.collect.ImmutableSet in project grakn by graknlabs.

the class Fragment method vars.

/**
 * Get all variables in the fragment including the start and end (if present)
 */
public final Set<Var> vars() {
    if (vars == null) {
        ImmutableSet.Builder<Var> builder = ImmutableSet.<Var>builder().add(start());
        Var end = end();
        if (end != null)
            builder.add(end);
        builder.addAll(otherVars());
        vars = builder.build();
    }
    return vars;
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) Var(ai.grakn.graql.Var)

Example 87 with ImmutableSet

use of org.apache.beam.vendor.calcite.v1_28_0.com.google.common.collect.ImmutableSet in project grakn by graknlabs.

the class GrpcServerIT method whenDefiningASchema_TheSchemaIsDefined.

@Test
public void whenDefiningASchema_TheSchemaIsDefined() {
    try (GraknTx tx = remoteSession.open(GraknTxType.WRITE)) {
        EntityType animal = tx.putEntityType("animal");
        EntityType dog = tx.putEntityType("dog").sup(animal);
        EntityType cat = tx.putEntityType("cat");
        animal.sub(cat);
        cat.setLabel(Label.of("feline"));
        dog.setAbstract(true).setAbstract(false);
        cat.setAbstract(true);
        RelationshipType chases = tx.putRelationshipType("chases");
        Role chased = tx.putRole("chased");
        Role chaser = tx.putRole("chaser");
        chases.relates(chased).relates(chaser);
        Role pointlessRole = tx.putRole("pointless-role");
        tx.putRelationshipType("pointless").relates(pointlessRole);
        chases.relates(pointlessRole).deleteRelates(pointlessRole);
        dog.plays(chaser);
        cat.plays(chased);
        AttributeType<String> name = tx.putAttributeType("name", DataType.STRING);
        AttributeType<String> id = tx.putAttributeType("id", DataType.STRING).setRegex("(good|bad)-dog");
        AttributeType<Long> age = tx.putAttributeType("age", DataType.LONG);
        animal.attribute(name);
        animal.key(id);
        dog.attribute(age).deleteAttribute(age);
        cat.key(age).deleteKey(age);
        cat.plays(chaser).deletePlays(chaser);
        Entity dunstan = dog.addEntity();
        Attribute<String> dunstanId = id.putAttribute("good-dog");
        assertNotNull(dunstan.attributeRelationship(dunstanId));
        Attribute<String> dunstanName = name.putAttribute("Dunstan");
        dunstan.attribute(dunstanName).deleteAttribute(dunstanName);
        chases.addRelationship().addRolePlayer(chaser, dunstan);
        tx.commit();
    }
    try (GraknTx tx = localSession.open(GraknTxType.READ)) {
        EntityType animal = tx.getEntityType("animal");
        EntityType dog = tx.getEntityType("dog");
        EntityType cat = tx.getEntityType("feline");
        RelationshipType chases = tx.getRelationshipType("chases");
        Role chased = tx.getRole("chased");
        Role chaser = tx.getRole("chaser");
        AttributeType<String> name = tx.getAttributeType("name");
        AttributeType<String> id = tx.getAttributeType("id");
        Entity dunstan = Iterators.getOnlyElement(dog.instances().iterator());
        Relationship aChase = Iterators.getOnlyElement(chases.instances().iterator());
        assertEquals(animal, dog.sup());
        assertEquals(animal, cat.sup());
        assertEquals(ImmutableSet.of(chased, chaser), chases.relates().collect(toSet()));
        assertEquals(ImmutableSet.of(chaser), dog.plays().filter(role -> !role.isImplicit()).collect(toSet()));
        assertEquals(ImmutableSet.of(chased), cat.plays().filter(role -> !role.isImplicit()).collect(toSet()));
        assertEquals(ImmutableSet.of(name, id), animal.attributes().collect(toSet()));
        assertEquals(ImmutableSet.of(id), animal.keys().collect(toSet()));
        assertEquals(ImmutableSet.of(name, id), dog.attributes().collect(toSet()));
        assertEquals(ImmutableSet.of(id), dog.keys().collect(toSet()));
        assertEquals(ImmutableSet.of(name, id), cat.attributes().collect(toSet()));
        assertEquals(ImmutableSet.of(id), cat.keys().collect(toSet()));
        assertEquals("good-dog", Iterables.getOnlyElement(dunstan.keys(id).collect(toSet())).getValue());
        ImmutableMap<Role, ImmutableSet<?>> expectedRolePlayers = ImmutableMap.of(chaser, ImmutableSet.of(dunstan), chased, ImmutableSet.of());
        assertEquals(expectedRolePlayers, aChase.allRolePlayers());
        assertEquals("(good|bad)-dog", id.getRegex());
        assertFalse(dog.isAbstract());
        assertTrue(cat.isAbstract());
    }
}
Also used : Entity(ai.grakn.concept.Entity) RelationshipType(ai.grakn.concept.RelationshipType) EntityType(ai.grakn.concept.EntityType) Role(ai.grakn.concept.Role) GraknTx(ai.grakn.GraknTx) ImmutableSet(com.google.common.collect.ImmutableSet) Relationship(ai.grakn.concept.Relationship) Test(org.junit.Test)

Example 88 with ImmutableSet

use of org.apache.beam.vendor.calcite.v1_28_0.com.google.common.collect.ImmutableSet in project SpongeCommon by SpongePowered.

the class PlaceableDataProcessor method removeFrom.

@Override
public DataTransactionResult removeFrom(ValueContainer<?> container) {
    if (supports(container)) {
        ItemStack stack = (ItemStack) container;
        Optional<Set<BlockType>> old = getVal(stack);
        if (!old.isPresent()) {
            return DataTransactionResult.successNoData();
        }
        if (set(stack, ImmutableSet.<BlockType>of())) {
            return DataTransactionResult.successRemove(constructImmutableValue(old.get()));
        }
        return DataTransactionResult.builder().result(DataTransactionResult.Type.ERROR).build();
    }
    return DataTransactionResult.failNoData();
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) ItemStack(net.minecraft.item.ItemStack)

Example 89 with ImmutableSet

use of org.apache.beam.vendor.calcite.v1_28_0.com.google.common.collect.ImmutableSet in project SpongeCommon by SpongePowered.

the class BreakableDataProcessor method removeFrom.

@Override
public DataTransactionResult removeFrom(ValueContainer<?> container) {
    if (supports(container)) {
        ItemStack stack = (ItemStack) container;
        Optional<Set<BlockType>> old = getVal(stack);
        if (!old.isPresent()) {
            return DataTransactionResult.successNoData();
        }
        if (set((ItemStack) container, ImmutableSet.<BlockType>of())) {
            return DataTransactionResult.successRemove(constructImmutableValue(old.get()));
        }
        return DataTransactionResult.builder().result(DataTransactionResult.Type.ERROR).build();
    }
    return DataTransactionResult.failNoData();
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) ItemStack(net.minecraft.item.ItemStack)

Example 90 with ImmutableSet

use of org.apache.beam.vendor.calcite.v1_28_0.com.google.common.collect.ImmutableSet in project accumulo by apache.

the class LocatorIT method assertContains.

private void assertContains(Locations locations, HashSet<String> tservers, Map<Range, ImmutableSet<TabletId>> expected1, Map<TabletId, ImmutableSet<Range>> expected2) {
    Map<Range, Set<TabletId>> gbr = new HashMap<>();
    for (Entry<Range, List<TabletId>> entry : locations.groupByRange().entrySet()) {
        gbr.put(entry.getKey(), new HashSet<>(entry.getValue()));
    }
    Assert.assertEquals(expected1, gbr);
    Map<TabletId, Set<Range>> gbt = new HashMap<>();
    for (Entry<TabletId, List<Range>> entry : locations.groupByTablet().entrySet()) {
        gbt.put(entry.getKey(), new HashSet<>(entry.getValue()));
        TabletId tid = entry.getKey();
        String location = locations.getTabletLocation(tid);
        Assert.assertNotNull("Location for " + tid + " was null", location);
        Assert.assertTrue("Unknown location " + location, tservers.contains(location));
        Assert.assertTrue("Expected <host>:<port> " + location, location.split(":").length == 2);
    }
    Assert.assertEquals(expected2, gbt);
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List) TabletId(org.apache.accumulo.core.data.TabletId) Range(org.apache.accumulo.core.data.Range)

Aggregations

ImmutableSet (com.google.common.collect.ImmutableSet)348 Set (java.util.Set)86 ImmutableList (com.google.common.collect.ImmutableList)73 Path (java.nio.file.Path)71 ImmutableMap (com.google.common.collect.ImmutableMap)69 IOException (java.io.IOException)67 Optional (java.util.Optional)65 Map (java.util.Map)63 List (java.util.List)60 BuildTarget (com.facebook.buck.model.BuildTarget)58 Test (org.junit.Test)55 HashMap (java.util.HashMap)42 Collection (java.util.Collection)34 HashSet (java.util.HashSet)33 SourcePath (com.facebook.buck.rules.SourcePath)31 ArrayList (java.util.ArrayList)31 TargetNode (com.facebook.buck.rules.TargetNode)28 BuildRule (com.facebook.buck.rules.BuildRule)26 VisibleForTesting (com.google.common.annotations.VisibleForTesting)25 ImmutableSortedSet (com.google.common.collect.ImmutableSortedSet)25