Java Code Examples for com.google.common.base.Predicates#equalTo()

The following examples show how to use com.google.common.base.Predicates#equalTo() . 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: TestThresholdTrigger.java    From arcusplatform with Apache License 2.0 6 votes vote down vote up
@Test
public void testMultiples() {
 Model model2 = context.createModel("test", UUID.randomUUID());
 attributeName = "test:test";
 thresholdValue = 85.0;
 sensitivityValue = 5.0;
 Predicate<Address> source =  Predicates.equalTo(model.getAddress());
 trigger = new ThresholdTrigger(attributeName, thresholdValue, sensitivityValue, TriggerOn.GREATER_THAN, source);
	 
   trigger.activate(context);
   
   //valueChangeEvent = AttributeValueChangedEvent.create(model.getAddress(), attributeName, new Double(86.0), new Double(84.0));
   assertTrue(trigger.shouldFire(context, createValueChange(attributeName, new Double(80), new Double(86))));      
   assertFalse(trigger.shouldFire(context, createValueChange(model2, attributeName, new Double(80), new Double(86))));
   
   assertFalse(trigger.shouldFire(context, createValueChange(attributeName, new Double(86), new Double(90))));  
   assertFalse(trigger.shouldFire(context, createValueChange(model2, attributeName, new Double(86), new Double(90))));
   
   assertFalse(trigger.shouldFire(context, createValueChange(attributeName, new Double(90), new Double(70))));
   assertFalse(trigger.shouldFire(context, createValueChange(model2, attributeName, new Double(90), new Double(70))));
   
   assertFalse(trigger.shouldFire(context, createValueChange(model2, attributeName, new Double(70), new Double(88))));
   assertTrue(trigger.shouldFire(context, createValueChange(attributeName, new Double(70), new Double(88))));
}
 
Example 2
Source File: TestThresholdTrigger.java    From arcusplatform with Apache License 2.0 6 votes vote down vote up
@Test
public void testGreaterThan() {
 attributeName = "test:test";
 thresholdValue = 85.0;
 sensitivityValue = 5.0;
 Predicate<Address> source =  Predicates.equalTo(model.getAddress());
 trigger = new ThresholdTrigger(attributeName, thresholdValue, sensitivityValue, TriggerOn.GREATER_THAN, source);	 
    trigger.activate(context);
    
    assertFalse(trigger.shouldFire(context, createValueChange(attributeName, 65, 80)));  
    assertTrue(trigger.shouldFire(context, createValueChange(attributeName, 80, 86)));   
    assertFalse(trigger.shouldFire(context, createValueChange(attributeName, 88, 86))); 
    assertFalse(trigger.shouldFire(context, createValueChange(attributeName, 90, 88)));
    assertFalse(trigger.shouldFire(context, createValueChange(attributeName, 88, 85)));
    assertFalse(trigger.shouldFire(context, createValueChange(attributeName, 85, 84)));
    assertFalse(trigger.shouldFire(context, createValueChange(attributeName, 84, 80)));
    assertFalse(trigger.shouldFire(context, createValueChange(attributeName, 80, 79)));
    assertFalse(trigger.shouldFire(context, createValueChange(attributeName, 79, 60)));
    
}
 
Example 3
Source File: TestThresholdTrigger.java    From arcusplatform with Apache License 2.0 6 votes vote down vote up
@Test
public void testLessThan() {
 attributeName = "test:test";
 thresholdValue = 10.0;
 sensitivityValue = 1.8;
 Predicate<Address> source =  Predicates.equalTo(model.getAddress());
 trigger = new ThresholdTrigger(attributeName, thresholdValue, sensitivityValue, TriggerOn.LESS_THAN, source);	 
   trigger.activate(context);
   
   assertFalse(trigger.shouldFire(context, createValueChange(attributeName, 15, 11)));   
   assertTrue(trigger.shouldFire(context, createValueChange(attributeName, 11, 9.9))); 
   assertFalse(trigger.shouldFire(context, createValueChange(attributeName, 9.9, 8.0)));
   assertFalse(trigger.shouldFire(context, createValueChange(attributeName, 8.0, 10)));
   assertFalse(trigger.shouldFire(context, createValueChange(attributeName, 10, 11.7)));
   assertFalse(trigger.shouldFire(context, createValueChange(attributeName, 11.7, 15)));
   
}
 
Example 4
Source File: TestThresholdTrigger.java    From arcusplatform with Apache License 2.0 6 votes vote down vote up
@Test
public void testSatisfiable() {
 Model model2 = context.createModel("test", UUID.randomUUID());
 attributeName = "test:test";
 thresholdValue = 85.0;
 sensitivityValue = 5.0;
 Predicate<Address> source =  Predicates.equalTo(model.getAddress());
 trigger = new ThresholdTrigger(attributeName, thresholdValue, sensitivityValue, TriggerOn.GREATER_THAN, source);
	 
   trigger.activate(context);
   assertFalse(trigger.isSatisfiable(context));            
   
   model.setAttribute(attributeName, new Double(80));
   assertTrue(trigger.isSatisfiable(context));
   
   //valueChangeEvent = AttributeValueChangedEvent.create(model.getAddress(), attributeName, new Double(86.0), new Double(84.0));
   assertTrue(trigger.shouldFire(context, createValueChange(attributeName, new Double(80), new Double(86))));      
   assertFalse(trigger.shouldFire(context, createValueChange("test:bad", new Double(80), new Double(86))));  
   //source does not match
   assertFalse(trigger.shouldFire(context, createValueChange(model2, attributeName, new Double(80), new Double(86))));
}
 
Example 5
Source File: TestForEachModelAction.java    From arcusplatform with Apache License 2.0 6 votes vote down vote up
@Test
public void testOneMatchingModel() {
   final RuleContext namespacedContext = new NamespaceContext(model1.getId(), context);
   mockAction.execute(namespacedContext);
   EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() {
      @Override
      public Object answer() throws Throwable {
         // verify that the address has been changed
         assertEquals(model1.getAddress(), namespacedContext.getVariable(targetVariable));
         return ActionState.FIRING;
      }
   });
   
   EasyMock.replay(mockAction);
   
   ForEachModelAction selector = new ForEachModelAction(mockAction, Predicates.<Model>alwaysTrue(), Predicates.<Model>equalTo(model1), "address");
   selector.execute(context);
   assertNull(context.getVariable(targetVariable));
   assertEquals(ImmutableList.<Address>of(model1.getAddress()),context.getVariable(ForEachModelAction.VAR_STILL_FIRING));
   EasyMock.verify(mockAction);
}
 
Example 6
Source File: JobSpecFilter.java    From incubator-gobblin with Apache License 2.0 5 votes vote down vote up
public Builder eqURI(String uri) {
  try {
    this.uriPredicate = Predicates.equalTo(new URI(uri));
  } catch (URISyntaxException e) {
    throw new RuntimeException("invalid URI: " + uri, e);
  }
  return this;
}
 
Example 7
Source File: ReceivedMessageConfig.java    From arcusplatform with Apache License 2.0 5 votes vote down vote up
@Override
public Condition generate(Map<String, Object> values) {
   Preconditions.checkState(messageType != null, "must specify a message type");
   
   Predicate<Address> fromPred = this.source == null ?
      Predicates.alwaysTrue() :
      Predicates.equalTo( FunctionFactory.toAddress(this.source.toTemplate(), values) );
   Predicate<String> messageTypePred = Predicates.equalTo( FunctionFactory.toString(this.messageType.toTemplate(), values) );
   Predicate<Map<String,Object>> attributesPred;
   if(this.attributes.isEmpty()) {
      attributesPred = Predicates.alwaysTrue();
   }
   else {
      Map<String, Predicate<? super Object>> matches = new HashMap<>();
      for(Map.Entry<String, TemplatedExpression> attributeAndExpression: this.attributes.entrySet()) {
         String attribute = attributeAndExpression.getKey();
         TemplatedExpression expression = attributeAndExpression.getValue();
         matches.put(
               attribute,
               // TODO more options than equalTo?
               Predicates.equalTo( expression.toTemplate().apply(values) )
         );
      }
      attributesPred = FunctionFactory.containsAll(matches);
   }
   
   ReceivedMessageCondition condition = new ReceivedMessageCondition(messageTypePred,fromPred,attributesPred);
   return condition;
}
 
Example 8
Source File: CheckPathsBetweenNodesTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public void testSomePathRevisiting() {
  DiGraph<String, String> g = LinkedDirectedGraph.create();
  g.createDirectedGraphNode("1");
  g.createDirectedGraphNode("2a");
  g.createDirectedGraphNode("2b");
  g.createDirectedGraphNode("3");
  g.createDirectedGraphNode("4a");
  g.createDirectedGraphNode("4b");
  g.createDirectedGraphNode("5");
  g.connect("1", "-", "2a");
  g.connect("1", "-", "2b");
  g.connect("2a", "-", "3");
  g.connect("2b", "-", "3");
  g.connect("3", "-", "4a");
  g.connect("3", "-", "4b");
  g.connect("4a", "-", "5");
  g.connect("4b", "-", "5");

  CountingPredicate<String> p =
    new CountingPredicate<String>(Predicates.equalTo("4a"));

  assertTrue(createTest(g, "1", "5", p, ALL_EDGE)
      .somePathsSatisfyPredicate());

  // Make sure we are not doing more traversals than we have to.
  assertEquals(4, p.count);
}
 
Example 9
Source File: AddressSelectorWrapper.java    From azure-cosmosdb-java with MIT License 5 votes vote down vote up
VerifierBuilder resolveAllUriAsync_ForceRefresh(boolean forceRefresh) {
    methodName(resolveAllUriAsync);

    Condition alwaysTrue = new Condition(Predicates.alwaysTrue(), "no condition");
    Condition forceRefreshCond = new Condition(Predicates.equalTo(forceRefresh), String.format("%b (forceRefresh)", forceRefresh));

    resolveAllUriAsync(alwaysTrue, alwaysTrue, forceRefreshCond);
    return this;
}
 
Example 10
Source File: ContentFolderScopes.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
public static Predicate<ContentFolderTypeProvider> onlyProduction() {
  return Predicates.<ContentFolderTypeProvider>equalTo(ProductionContentFolderTypeProvider.getInstance());
}
 
Example 11
Source File: JobSpecFilter.java    From incubator-gobblin with Apache License 2.0 4 votes vote down vote up
public Builder eqVersion(String version) {
  this.versionPredicate = Predicates.equalTo(version);
  return this;
}
 
Example 12
Source File: Closure_89_CollapseProperties_s.java    From coming with MIT License 4 votes vote down vote up
private boolean inlineAliasIfPossible(Ref alias, GlobalNamespace namespace) {
  // Ensure that the alias is assigned to a local variable at that
  // variable's declaration. If the alias's parent is a NAME,
  // then the NAME must be the child of a VAR node, and we must
  // be in a VAR assignment.
  Node aliasParent = alias.node.getParent();
  if (aliasParent.getType() == Token.NAME) {
    // Ensure that the local variable is well defined and never reassigned.
    Scope scope = alias.scope;
    Var aliasVar = scope.getVar(aliasParent.getString());
    ReferenceCollectingCallback collector =
        new ReferenceCollectingCallback(compiler,
            ReferenceCollectingCallback.DO_NOTHING_BEHAVIOR,
            Predicates.<Var>equalTo(aliasVar));
    (new NodeTraversal(compiler, collector)).traverseAtScope(scope);

    ReferenceCollection aliasRefs =
        collector.getReferenceCollection(aliasVar);
    if (aliasRefs.isWellDefined()
        && aliasRefs.firstReferenceIsAssigningDeclaration()
        && aliasRefs.isAssignedOnceInLifetime()) {
      // The alias is well-formed, so do the inlining now.
      int size = aliasRefs.references.size();
      Set<Node> newNodes = Sets.newHashSetWithExpectedSize(size - 1);
      for (int i = 1; i < size; i++) {
        ReferenceCollectingCallback.Reference aliasRef =
            aliasRefs.references.get(i);

        Node newNode = alias.node.cloneTree();
        aliasRef.getParent().replaceChild(aliasRef.getNameNode(), newNode);
        newNodes.add(newNode);
      }

      // just set the original alias to null.
      aliasParent.replaceChild(alias.node, new Node(Token.NULL));
      compiler.reportCodeChange();

      // Inlining the variable may have introduced new references
      // to descendents of {@code name}. So those need to be collected now.
      namespace.scanNewNodes(alias.scope, newNodes);
      return true;
    }
  }

  return false;
}
 
Example 13
Source File: Closure_130_CollapseProperties_t.java    From coming with MIT License 4 votes vote down vote up
private boolean inlineAliasIfPossible(Ref alias, GlobalNamespace namespace) {
  // Ensure that the alias is assigned to a local variable at that
  // variable's declaration. If the alias's parent is a NAME,
  // then the NAME must be the child of a VAR node, and we must
  // be in a VAR assignment.
  Node aliasParent = alias.node.getParent();
  if (aliasParent.isName()) {
    // Ensure that the local variable is well defined and never reassigned.
    Scope scope = alias.scope;
    Var aliasVar = scope.getVar(aliasParent.getString());
    ReferenceCollectingCallback collector =
        new ReferenceCollectingCallback(compiler,
            ReferenceCollectingCallback.DO_NOTHING_BEHAVIOR,
            Predicates.<Var>equalTo(aliasVar));
    (new NodeTraversal(compiler, collector)).traverseAtScope(scope);

    ReferenceCollection aliasRefs = collector.getReferences(aliasVar);
    if (aliasRefs.isWellDefined()
        && aliasRefs.firstReferenceIsAssigningDeclaration()
        && aliasRefs.isAssignedOnceInLifetime()) {
      // The alias is well-formed, so do the inlining now.
      int size = aliasRefs.references.size();
      Set<Node> newNodes = Sets.newHashSetWithExpectedSize(size - 1);
      for (int i = 1; i < size; i++) {
        ReferenceCollectingCallback.Reference aliasRef =
            aliasRefs.references.get(i);

        Node newNode = alias.node.cloneTree();
        aliasRef.getParent().replaceChild(aliasRef.getNode(), newNode);
        newNodes.add(newNode);
      }

      // just set the original alias to null.
      aliasParent.replaceChild(alias.node, IR.nullNode());
      compiler.reportCodeChange();

      // Inlining the variable may have introduced new references
      // to descendants of {@code name}. So those need to be collected now.
      namespace.scanNewNodes(alias.scope, newNodes);
      return true;
    }
  }

  return false;
}
 
Example 14
Source File: Closure_130_CollapseProperties_s.java    From coming with MIT License 4 votes vote down vote up
private boolean inlineAliasIfPossible(Ref alias, GlobalNamespace namespace) {
  // Ensure that the alias is assigned to a local variable at that
  // variable's declaration. If the alias's parent is a NAME,
  // then the NAME must be the child of a VAR node, and we must
  // be in a VAR assignment.
  Node aliasParent = alias.node.getParent();
  if (aliasParent.isName()) {
    // Ensure that the local variable is well defined and never reassigned.
    Scope scope = alias.scope;
    Var aliasVar = scope.getVar(aliasParent.getString());
    ReferenceCollectingCallback collector =
        new ReferenceCollectingCallback(compiler,
            ReferenceCollectingCallback.DO_NOTHING_BEHAVIOR,
            Predicates.<Var>equalTo(aliasVar));
    (new NodeTraversal(compiler, collector)).traverseAtScope(scope);

    ReferenceCollection aliasRefs = collector.getReferences(aliasVar);
    if (aliasRefs.isWellDefined()
        && aliasRefs.firstReferenceIsAssigningDeclaration()
        && aliasRefs.isAssignedOnceInLifetime()) {
      // The alias is well-formed, so do the inlining now.
      int size = aliasRefs.references.size();
      Set<Node> newNodes = Sets.newHashSetWithExpectedSize(size - 1);
      for (int i = 1; i < size; i++) {
        ReferenceCollectingCallback.Reference aliasRef =
            aliasRefs.references.get(i);

        Node newNode = alias.node.cloneTree();
        aliasRef.getParent().replaceChild(aliasRef.getNode(), newNode);
        newNodes.add(newNode);
      }

      // just set the original alias to null.
      aliasParent.replaceChild(alias.node, IR.nullNode());
      compiler.reportCodeChange();

      // Inlining the variable may have introduced new references
      // to descendants of {@code name}. So those need to be collected now.
      namespace.scanNewNodes(alias.scope, newNodes);
      return true;
    }
  }

  return false;
}
 
Example 15
Source File: EmoTableAllTablesReportDAO.java    From emodb with Apache License 2.0 4 votes vote down vote up
/**
 * Returns the matching table report entries for a report ID and query parameters.
 */
@Override
public Iterable<TableReportEntry> getReportEntries(String reportId, final AllTablesReportQuery query) {
    checkNotNull(reportId, "reportId");

    final String reportTable = getTableName(reportId);

    // Set up several filters based on the query attributes

    final Predicate<String> placementFilter = query.getPlacements().isEmpty()
            ? Predicates.<String>alwaysTrue()
            : Predicates.in(query.getPlacements());

    final Predicate<Boolean> droppedFilter = query.isIncludeDropped()
            ? Predicates.<Boolean>alwaysTrue()
            : Predicates.equalTo(false);

    final Predicate<Boolean> facadeFilter = query.isIncludeFacades()
            ? Predicates.<Boolean>alwaysTrue()
            : Predicates.equalTo(false);

    return new Iterable<TableReportEntry>() {
        @Override
        public Iterator<TableReportEntry> iterator() {
            return Iterators.limit(
                    Iterators.filter(
                            Iterators.transform(
                                    queryDataStoreForTableReportResults(reportTable, query),
                                    new Function<Map<String, Object>, TableReportEntry>() {
                                        @Nullable
                                        @Override
                                        public TableReportEntry apply(Map<String, Object> map) {
                                            if (Intrinsic.getId(map).startsWith("~")) {
                                                // Skip this row, it's the metadata
                                                return null;
                                            }
                                            return convertToTableReportEntry(
                                                    map, placementFilter, droppedFilter, facadeFilter);
                                        }
                                    }),
                            Predicates.notNull()
                    ),
                    query.getLimit()
            );
        }
    };
}
 
Example 16
Source File: AssertWithBackoff.java    From incubator-gobblin with Apache License 2.0 4 votes vote down vote up
public EqualsCheck(Function<Void, T> actual, T expected, String message) {
  this.eqToExpected = Predicates.equalTo(expected);
  this.message = message;
  this.actual = actual;
}
 
Example 17
Source File: CreateStringPredicateFunction.java    From arcusplatform with Apache License 2.0 4 votes vote down vote up
@Override
public Predicate<String> apply(String value) {
   return Predicates.equalTo(value);
}
 
Example 18
Source File: CreateAddressPredicateFunction.java    From arcusplatform with Apache License 2.0 4 votes vote down vote up
@Override
public Predicate<Address> apply(String value) {
   Address address = Address.fromString(value);
   return Predicates.equalTo(address);
}
 
Example 19
Source File: JobSpecFilter.java    From incubator-gobblin with Apache License 2.0 4 votes vote down vote up
public Builder eqURI(URI uri) {
  this.uriPredicate = Predicates.equalTo(uri);
  return this;
}
 
Example 20
Source File: ContentFolderScopes.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
public static Predicate<ContentFolderTypeProvider> of(@Nonnull ContentFolderTypeProvider provider) {
  return Predicates.equalTo(provider);
}