use of java.util.function.Function in project intellij-community by JetBrains.
the class UnusedPropertyInspection method buildPropertyGroupVisitor.
@NotNull
@Override
public Function<IProperty[], ResourceBundleEditorProblemDescriptor[]> buildPropertyGroupVisitor(@NotNull ResourceBundle resourceBundle) {
final Module module = ModuleUtilCore.findModuleForPsiElement(resourceBundle.getDefaultPropertiesFile().getContainingFile());
if (module == null)
return x -> null;
final UnusedPropertiesSearchHelper helper = new UnusedPropertiesSearchHelper(module);
return properties -> !isPropertyUsed((Property) properties[0], helper, true) ? new ResourceBundleEditorProblemDescriptor[] { new ResourceBundleEditorProblemDescriptor(ProblemHighlightType.LIKE_UNUSED_SYMBOL, PropertiesBundle.message("unused.property.problem.descriptor.name"), new RemovePropertiesFromAllLocalesFix((Property) properties[0])) } : null;
}
use of java.util.function.Function in project enhydrator by AdamBien.
the class Pump method applyRowTransformations.
static Row applyRowTransformations(List<Function<Row, Row>> trafos, Row convertedColumns) {
if (trafos == null || trafos.isEmpty()) {
return convertedColumns;
}
final Function<Row, Row> composition = trafos.stream().reduce((i, j) -> i.andThen(j)).get();
Row result = composition.apply(convertedColumns);
if (result == null) {
return null;
} else {
return result;
}
}
use of java.util.function.Function in project aic-expresso by aic-sri-international.
the class Compilation method compile.
/**
* Compiles an expression to a normalized (decision-tree-like) expression.
* @param inputExpression
* @param mapFromVariableNameToTypeName
* @param mapFromCategoricalTypeNameToSizeString
* @param additionalTypes
* @param solverListener if not null, invoked on solver used for compilation, before and after compilation starts; returned solver on 'before' invocation is used (it may be the same one used as argument, of course).
* @return
*/
public static Expression compile(Expression inputExpression, Theory theory, Map<String, String> mapFromVariableNameToTypeName, Map<String, String> mapFromUniquelyNamedConstantToTypeName, Map<String, String> mapFromCategoricalTypeNameToSizeString, Collection<Type> additionalTypes, Function<MultiIndexQuantifierEliminator, MultiIndexQuantifierEliminator> solverListener) {
// the group actually does not matter, because we are not going to have any indices.
AssociativeCommutativeGroup group = new Max();
// The solver for the parameters above.
MultiIndexQuantifierEliminator solver = new SGDPLLT();
if (solverListener != null) {
solver = solverListener.apply(solver);
}
// We use the Prolog convention of small-letter initials for constants, but we need an exception for the random variables.
Predicate<Expression> isPrologConstant = new PrologConstantPredicate();
Predicate<Expression> isUniquelyNamedConstantPredicate = e -> isPrologConstant.apply(e) && !mapFromVariableNameToTypeName.containsKey(e);
Map<String, String> mapFromSymbolNameToTypeName = new LinkedHashMap<>(mapFromVariableNameToTypeName);
mapFromSymbolNameToTypeName.putAll(mapFromUniquelyNamedConstantToTypeName);
// Solve the problem.
// no indices; we want to keep all variables
List<Expression> indices = Util.list();
Expression result = solver.solve(group, inputExpression, indices, mapFromSymbolNameToTypeName, mapFromCategoricalTypeNameToSizeString, additionalTypes, isUniquelyNamedConstantPredicate, theory);
if (solverListener != null) {
solverListener.apply(null);
}
return result;
}
use of java.util.function.Function in project aima-java by aimacode.
the class SimulatedAnnealingMaximumFinderApp method simulate.
/** Starts the experiment. */
@SuppressWarnings("unchecked")
public void simulate() {
List<Action> actions = new ArrayList<>(1);
actions.add(new DynamicAction("Move"));
Problem<Double, Action> problem = new GeneralProblem<>(getRandomState(), s -> actions, (s, a) -> getSuccessor(s), s -> false);
Function<Double, Double> func = (Function<Double, Double>) simPaneCtrl.getParamValue(PARAM_FUNC_SELECT);
Scheduler scheduler = new Scheduler(simPaneCtrl.getParamAsInt(PARAM_K), simPaneCtrl.getParamAsDouble(PARAM_LAMBDA), simPaneCtrl.getParamAsInt(PARAM_MAX_ITER));
search = new SimulatedAnnealingSearch<>(n -> 1 - func.apply(n.getState()), scheduler);
search.addNodeListener(n -> updateStateView(n.getState()));
search.findActions(problem);
updateStateView(search.getLastSearchState());
}
use of java.util.function.Function in project Alpha by alpha-asp.
the class AbstractSolverTests method factories.
@Parameters(name = "{0}")
public static Collection<Object[]> factories() {
boolean enableAdditionalInternalChecks = false;
Collection<Object[]> factories = new ArrayList<>();
factories.add(new Object[] { "NaiveSolver", (Function<Grounder, Solver>) NaiveSolver::new });
for (Heuristic heuristic : Heuristic.values()) {
String name = "DefaultSolver (random " + heuristic + ")";
Function<Grounder, Solver> instantiator = g -> {
return new DefaultSolver(g, new Random(), heuristic, enableAdditionalInternalChecks);
};
factories.add(new Object[] { name, instantiator });
name = "DefaultSolver (deterministic " + heuristic + ")";
instantiator = g -> {
return new DefaultSolver(g, new Random(0), heuristic, enableAdditionalInternalChecks);
};
factories.add(new Object[] { name, instantiator });
}
return factories;
}
Aggregations