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

The following examples show how to use org.apache.commons.collections4.IteratorUtils#filteredIterator() . 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: SystemTestHtmlWriter.java    From tcases with MIT License 6 votes vote down vote up
/**
 * Writes the input value definitions for all variables of the given type.
 */
protected void writeInputs( TestCase testCase, String type)
  {
  Iterator<VarBinding> varBindings =
    IteratorUtils.filteredIterator
      ( testCase.getVarBindings( type),
        binding -> !binding.isValueNA());

  if( varBindings.hasNext())
    {
    xmlWriter_
      .element( "DIV")
      .attribute( "class", "input " + type)
      .content( () ->
        {
        if( !IVarDef.ARG.equals( type))
          {
          xmlWriter_.element( "H3").content( type).write();
          }
  
        writeVarSets( 0, varBindings);
        })
      .write();
    }
  }
 
Example 2
Source File: AssemblyResolvedConstructor.java    From ghidra with Apache License 2.0 5 votes vote down vote up
/**
 * Get an iterable over all the possible fillings of the instruction pattern given a context
 * 
 * This is meant to be used idiomatically, as in an enhanced for loop:
 * 
 * <pre>
 * {@code
 * for (byte[] ins : rcon.possibleInsVals(ctx)) {
 *     System.out.println(format(ins));
 * }
 * }
 * </pre>
 * 
 * This is similar to calling
 * {@link #getInstruction()}.{@link AssemblyPatternBlock#possibleVals()}, <em>but</em> with
 * forbidden patterns removed. A context is required so that only those forbidden patterns
 * matching the given context are actually removed. This method should always be preferred to
 * the sequence mentioned above, since {@link AssemblyPatternBlock#possibleVals()} on its own
 * may yield bytes that do not produce the desired instruction. 
 * 
 * NOTE: The implementation is based on {@link AssemblyPatternBlock#possibleVals()}, so be
 * aware that a single array is reused for each iterate. You should not retain a pointer to the
 * array, but rather make a copy.
 * 
 * @param forCtx the context at the assembly address
 * @return the iterable
 */
public Iterable<byte[]> possibleInsVals(AssemblyPatternBlock forCtx) {
	Predicate<byte[]> removeForbidden = (byte[] val) -> {
		for (AssemblyResolvedConstructor f : forbids) {
			// If the forbidden length is larger than us, we can ignore it
			if (f.getDefinedInstructionLength() > val.length) {
				continue;
			}
			// Check if the context matches, if not, we can let it pass
			if (null == f.getContext().combine(forCtx)) {
				continue;
			}
			// If the context matches, now check the instruction
			AssemblyPatternBlock i = f.getInstruction();
			AssemblyPatternBlock vi =
				AssemblyPatternBlock.fromBytes(ins.length() - val.length, val);
			if (null == i.combine(vi)) {
				continue;
			}
			return false;
		}
		return true;
	};
	return new Iterable<byte[]>() {
		@Override
		public Iterator<byte[]> iterator() {
			return IteratorUtils.filteredIterator(ins.possibleVals().iterator(),
				removeForbidden);
		}
	};
}
 
Example 3
Source File: VarTupleSet.java    From tcases with MIT License 5 votes vote down vote up
/**
 * Returns input tuples that bind the given variable.
 */
private Iterator<Tuple> getBinds( Iterator<Tuple> tuples, final VarDef var)
  {
  return
    IteratorUtils.filteredIterator(
      tuples,
      tuple -> tuple.getBinding( var) != null);
  }
 
Example 4
Source File: TupleGenerator.java    From tcases with MIT License 5 votes vote down vote up
/**
 * Returns a set of valid {@link TestCaseDef test case definitions} that extend the given base test cases.
 */
private List<TestCaseDef> getBaseValidCases( FunctionInputDef inputDef, VarTupleSet validTuples, List<TestCaseDef> baseCases)
  {
  logger_.debug( "{}: Extending valid base test cases", inputDef);

  Iterator<TestCaseDef> validBaseCases =
    IteratorUtils.filteredIterator(
      baseCases.iterator(),
      testCase -> testCase.getInvalidVar() == null);

  List<TestCaseDef> testCases = extendBaseCases( inputDef, validTuples, validBaseCases);

  logger_.info( "{}: Extended {} valid base test cases", inputDef, testCases.size());
  return testCases;
 }
 
Example 5
Source File: TestCase.java    From tcases with MIT License 5 votes vote down vote up
/**
 * Returns the bindings for variables of the given type for this function.
 */
public Iterator<VarBinding> getVarBindings( final String type)
  {
  return
    IteratorUtils.filteredIterator(
      varBindings_.iterator(),
      binding -> Objects.equals( binding.getType(), type));
  }
 
Example 6
Source File: VarDef.java    From tcases with MIT License 5 votes vote down vote up
/**
 * Returns an iterator for the set of valid values.
 */
public Iterator<VarValueDef> getValidValues()
  {
  return
    IteratorUtils.filteredIterator(
      getValues(),
      VarValueDef::isValid);
  }
 
Example 7
Source File: VarDef.java    From tcases with MIT License 5 votes vote down vote up
/**
 * Returns an iterator for the set of failure values.
 */
public Iterator<VarValueDef> getFailureValues()
  {
  return
    IteratorUtils.filteredIterator(
      getValues(),
      valueDef -> !valueDef.isValid());
  }
 
Example 8
Source File: ToolActions.java    From ghidra with Apache License 2.0 4 votes vote down vote up
private Iterator<DockingActionIf> getKeyBindingActionsIterator() {
	Predicate<DockingActionIf> filter = a -> a.getKeyBindingType() == KeyBindingType.INDIVIDUAL;
	return IteratorUtils.filteredIterator(getAllActionsIterator(), filter);
}