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;
}
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());
}
}
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();
}
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();
}
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);
}
Aggregations