Java Code Examples for org.apache.commons.collections4.IteratorUtils#toArray()

The following examples show how to use org.apache.commons.collections4.IteratorUtils#toArray() . 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: Cnf.java    From tcases with MIT License 6 votes vote down vote up
/**
 * Returns true if the given disjunction is universally true.
 */
public static boolean isTautology( IDisjunct disjunct)
  {
  boolean tautology = false;
  if( disjunct != null)
    {
    IAssertion[] assertions = IteratorUtils.toArray( disjunct.getAssertions(), IAssertion.class);
    int max = assertions.length;
    int maxCompared = max - 1;
    
    for( int compared = 0;
         !tautology && compared < maxCompared;
         compared++)
      {
      IAssertion assertCompared = assertions[ compared];
      
      for( int other = compared + 1;
           !tautology && other < max;
           tautology = assertCompared.negates( assertions[ other++]));
      }
    }
  
  return tautology;
  }
 
Example 2
Source File: SystemInputJson.java    From tcases with MIT License 6 votes vote down vote up
public void visit( Not condition)
{
ICondition[] conditions = IteratorUtils.toArray( condition.getConditions(), ICondition.class);

JsonObjectBuilder builder = Json.createObjectBuilder();
if( conditions.length > 1)
  {
  builder.add( NOT_KEY, toJson( new AnyOf( conditions)));
  }
else if( conditions[0].getClass().equals( ContainsAny.class))
  {
  // Special case: abbreviate "not:{hasAny:[...]}" as "hasNone:[...]".
  JsonArrayBuilder properties = Json.createArrayBuilder();
  toStream( ((ContainsAny) conditions[0]).getProperties()).forEach( property -> properties.add( property));
  builder.add( HAS_NONE_KEY, properties);
  }
else
  {
  builder.add( NOT_KEY, toJson( conditions[0]));
  }

json_ = builder.build();
}
 
Example 3
Source File: TupleCombiner.java    From tcases with MIT License 5 votes vote down vote up
/**
 * Returns the set of input variables to be included in this combination.
 */
public String[] getIncluded()
  {
  return
    IteratorUtils.toArray(
      IteratorUtils.transformedIterator(
        includedVars_.iterator(),
        VarNamePattern::toString),
      String.class);
  }
 
Example 4
Source File: TupleCombiner.java    From tcases with MIT License 5 votes vote down vote up
/**
 * Returns the set of input variables to be excluded from this combination.
 */
public String[] getExcluded()
  {
  return
    IteratorUtils.toArray(
      IteratorUtils.transformedIterator(
        excludedVars_.iterator(),
        VarNamePattern::toString),
      String.class);
  }
 
Example 5
Source File: TestVarDefIterator.java    From tcases with MIT License 5 votes vote down vote up
/**
 * Test when traversing a list of various {@link IVarDef} types.
 */
@Test
public void testListTraversal()
  {
  // Given...
  FunctionInputDef inputDef = new FunctionInputDef( "testListTraversal");
  VarSet varSet;

  inputDef.addVarDef( new VarDef( "1"));

  varSet = new VarSet( "2");
  varSet.addMember( new VarDef( "1"));
  varSet.addMember( new VarDef( "2"));
  varSet.addMember( new VarDef( "3"));
  inputDef.addVarDef( varSet);

  varSet = new VarSet( "empty-1");
  inputDef.addVarDef( varSet);

  varSet = new VarSet( "empty-2");
  inputDef.addVarDef( varSet);

  inputDef.addVarDef( new VarDef( "3"));

  // When...
  String[] varDefNames =
    IteratorUtils.toArray(
      IteratorUtils.transformedIterator(
        new VarDefIterator( inputDef),
        VarDef::getPathName),
      String.class);
  
  // Then...
  assertThat
    ( "VarDef sequence",
      varDefNames,
      listsElements( "1", "2.1", "2.2", "2.3", "3"));
  }
 
Example 6
Source File: CollectionTools.java    From o2oa with GNU Affero General Public License v3.0 4 votes vote down vote up
public static <T> T[] toArray(Collection<T> col, Class<T> cls) {
    return IteratorUtils.toArray(col.iterator(), cls);
}
 
Example 7
Source File: TestCnf.java    From tcases with MIT License 4 votes vote down vote up
@Test
public void convertAnyOf()
  {
  // Given...
  ICondition condition =
    new AnyOf()
    .add( new AllOf().add( new ContainsAll( "A")).add( new ContainsAll( "B")))
    .add( new ContainsAll( "C"));
    
  // When...
  IConjunct conjunct = Cnf.convert( condition);
  
  // Then...
  IDisjunct[] disjuncts = IteratorUtils.toArray( conjunct.getDisjuncts(), IDisjunct.class);
  assertThat( "Disjuncts", disjuncts.length, is( 2));
  assertThat( "Satisfied:  A,  B,  C", conjunct.satisfied( new PropertySet( "A", "B", "C")), is( true));
  assertThat( "Satisfied:  A,  B, !C", conjunct.satisfied( new PropertySet( "A", "B")), is( true));
  assertThat( "Satisfied:  A, !B,  C", conjunct.satisfied( new PropertySet( "A", "C")), is( true));
  assertThat( "Satisfied:  A, !B, !C", conjunct.satisfied( new PropertySet( "A")), is( false));
  assertThat( "Satisfied: !A,  B,  C", conjunct.satisfied( new PropertySet( "B", "C")), is( true));
  assertThat( "Satisfied: !A, !B,  C", conjunct.satisfied( new PropertySet( "C")), is( true));
  assertThat( "Satisfied: !A,  B, !C", conjunct.satisfied( new PropertySet( "B")), is( false));
  assertThat( "Satisfied: !A, !B, !C", conjunct.satisfied( new PropertySet()), is( false));

  // Given...
  condition = new Not( condition);
    
  // When...
  conjunct = Cnf.convert( condition);
  
  // Then...
  disjuncts = IteratorUtils.toArray( conjunct.getDisjuncts(), IDisjunct.class);
  assertThat( "Disjuncts", disjuncts.length, is( 2));
  assertThat( "Satisfied:  A,  B,  C", conjunct.satisfied( new PropertySet( "A", "B", "C")), is( false));
  assertThat( "Satisfied:  A,  B, !C", conjunct.satisfied( new PropertySet( "A", "B")), is( false));
  assertThat( "Satisfied:  A, !B,  C", conjunct.satisfied( new PropertySet( "A", "C")), is( false));
  assertThat( "Satisfied:  A, !B, !C", conjunct.satisfied( new PropertySet( "A")), is( true));
  assertThat( "Satisfied: !A,  B,  C", conjunct.satisfied( new PropertySet( "B", "C")), is( false));
  assertThat( "Satisfied: !A, !B,  C", conjunct.satisfied( new PropertySet( "C")), is( false));
  assertThat( "Satisfied: !A,  B, !C", conjunct.satisfied( new PropertySet( "B")), is( true));
  assertThat( "Satisfied: !A, !B, !C", conjunct.satisfied( new PropertySet()), is( true));
  }
 
Example 8
Source File: TestCnf.java    From tcases with MIT License 4 votes vote down vote up
@Test
public void convertNot()
  {
  // Given...
  ICondition condition =
    new Not()
    .add( new AnyOf().add( new ContainsAny( "A", "B")).add( new ContainsAny( "C")));
    
  // When...
  IConjunct conjunct = Cnf.convert( condition);
  
  // Then...
  IDisjunct[] disjuncts = IteratorUtils.toArray( conjunct.getDisjuncts(), IDisjunct.class);
  assertThat( "Disjuncts", disjuncts.length, is( 3));
  assertThat( "Satisfied:  A,  B,  C", conjunct.satisfied( new PropertySet( "A", "B", "C")), is( false));
  assertThat( "Satisfied:  A,  B, !C", conjunct.satisfied( new PropertySet( "A", "B")), is( false));
  assertThat( "Satisfied:  A, !B,  C", conjunct.satisfied( new PropertySet( "A", "C")), is( false));
  assertThat( "Satisfied:  A, !B, !C", conjunct.satisfied( new PropertySet( "A")), is( false));
  assertThat( "Satisfied: !A,  B,  C", conjunct.satisfied( new PropertySet( "B", "C")), is( false));
  assertThat( "Satisfied: !A, !B,  C", conjunct.satisfied( new PropertySet( "C")), is( false));
  assertThat( "Satisfied: !A,  B, !C", conjunct.satisfied( new PropertySet( "B")), is( false));
  assertThat( "Satisfied: !A, !B, !C", conjunct.satisfied( new PropertySet()), is( true));

  // Given...
  condition = new Not( condition);
    
  // When...
  conjunct = Cnf.convert( condition);
  
  // Then...
  disjuncts = IteratorUtils.toArray( conjunct.getDisjuncts(), IDisjunct.class);
  assertThat( "Disjuncts", disjuncts.length, is( 1));
  assertThat( "Satisfied:  A,  B,  C", conjunct.satisfied( new PropertySet( "A", "B", "C")), is( true));
  assertThat( "Satisfied:  A,  B, !C", conjunct.satisfied( new PropertySet( "A", "B")), is( true));
  assertThat( "Satisfied:  A, !B,  C", conjunct.satisfied( new PropertySet( "A", "C")), is( true));
  assertThat( "Satisfied:  A, !B, !C", conjunct.satisfied( new PropertySet( "A")), is( true));
  assertThat( "Satisfied: !A,  B,  C", conjunct.satisfied( new PropertySet( "B", "C")), is( true));
  assertThat( "Satisfied: !A, !B,  C", conjunct.satisfied( new PropertySet( "C")), is( true));
  assertThat( "Satisfied: !A,  B, !C", conjunct.satisfied( new PropertySet( "B")), is( true));
  assertThat( "Satisfied: !A, !B, !C", conjunct.satisfied( new PropertySet()), is( false));
  }
 
Example 9
Source File: TestVarDefIterator.java    From tcases with MIT License 4 votes vote down vote up
/**
 * Test when traversing a tree of  {@link VarSet variable sets}.
 */
@Test
public void testTreeTraversal()
  {
  // Given...
  FunctionInputDef inputDef = new FunctionInputDef( "testTreeTraversal");
  VarSet varSet;
  VarSet member;

  varSet = new VarSet( "1");
  varSet.addMember( new VarSet( "1"));
  varSet.addMember( new VarSet( "2"));
  inputDef.addVarDef( varSet);

  member = (VarSet) varSet.getMember( "1");
  member.addMember( new VarSet( "1"));
  member.addMember( new VarDef( "2"));

  member = (VarSet) member.getMember( "1");
  member.addMember( new VarDef( "1"));
  member.addMember( new VarDef( "2"));
  
  member = (VarSet) varSet.getMember( "2");
  member.addMember( new VarDef( "1"));
  
  varSet = new VarSet( "2");
  varSet.addMember( new VarDef( "1"));
  varSet.addMember( new VarSet( "2"));
  inputDef.addVarDef( varSet);
  
  member = (VarSet) varSet.getMember( "2");
  member.addMember( new VarDef( "1"));
  member.addMember( new VarDef( "2"));

  // When...
  String[] varDefNames =
    IteratorUtils.toArray(
      IteratorUtils.transformedIterator(
        new VarDefIterator( inputDef),
        VarDef::getPathName),
      String.class);
  
  // Then...
  assertThat
    ( "VarDef sequence",
      varDefNames,
      listsElements( "1.1.1.1", "1.1.1.2", "1.1.2", "1.2.1", "2.1", "2.2.1", "2.2.2"));
  }