List of usage examples for com.google.common.primitives Booleans contains
public static boolean contains(boolean[] array, boolean target)
From source file:hydrograph.engine.cascading.assembly.JoinAssembly.java
/** * Filter actual join result if FULL OUTER JOIN is performed. Apply output * scheme and set OUT Port//from ww w .j a va 2 s . c om * * @param joinResult * @param outSocket */ private void setOutLink(Pipe joinResult, OutSocket outSocket) { Pipe joinFiltered; // OUT Link : if full outer join is specified no need to apply filter if (!Booleans.contains(getAllJoinTypes(), true)) { setOutLink(outSocket.getSocketType(), outSocket.getSocketId(), joinEntity.getComponentId(), applyOutPutSchema(joinResult, outSocket), joinHelper.getMapTargetFields(outSocket)); } else if (isUnusedSocketPresent) { // Apply filter for join result as full outer join is performed for // getting results for UNUSED Links out of joined file joinFiltered = new Each(joinResult, getOuterJoinFilesFlagFields(), new JoinOutLinkFilter()); setOutLink(outSocket.getSocketType(), outSocket.getSocketId(), joinEntity.getComponentId(), applyOutPutSchema(joinFiltered, outSocket), joinHelper.getMapTargetFields(outSocket)); } else { setOutLink(outSocket.getSocketType(), outSocket.getSocketId(), joinEntity.getComponentId(), applyOutPutSchema(joinResult, outSocket), joinHelper.getMapTargetFields(outSocket)); } }
From source file:hydrograph.engine.cascading.assembly.JoinAssembly.java
/** * Filter unmatched records from join result if FULL OUTER JOIN is * performed. Set UNUSED PORT respective to each file where unmatched * records are required.// w ww . ja v a 2s . c o m * * @param joinResult */ private void setUnusedLinks(Pipe joinResult, List<OutSocket> unusedOutSocket) { Pipe unUsedLink; Pipe allUnMatched; Pipe unMatched; // Records will be available at UNUSED PORT only if FULL OUTER join is // not applied if (Booleans.contains(getAllJoinTypes(), true)) { // get unUsed records from join result allUnMatched = new Each(joinResult, getOuterJoinFilesFlagFields(), new JoinGetUnmatchedRecordsFilter()); } else { allUnMatched = joinResult; } for (int i = 0; i < componentParameters.getinSocketId().size(); i++) { for (OutSocket unusedSocket : unusedOutSocket) { if (unusedSocket.getCopyOfInSocketId() .equalsIgnoreCase(componentParameters.getinSocketId().get(i))) { // renaming pipes to avoid pipe name conflict with OUT // PORT at tail LOG.trace("Creating join assembly for '" + joinEntity.getComponentId() + "' for socket: '" + unusedSocket.getSocketId() + "' of type: '" + unusedSocket.getSocketType() + "'"); unMatched = new Pipe(ComponentHelper.getComponentName("join", joinEntity.getComponentId(), unusedSocket.getSocketId()), allUnMatched); if (Booleans.contains(getAllJoinTypes(), true)) { unMatched = new Each(unMatched, new Fields(RECORD_PRESENT_INDICATOR + i), new JoinUnusedLinkFilter()); } else { unMatched = new Each(unMatched, new Fields(RECORD_PRESENT_INDICATOR + i), new BlockAllFilter()); } unMatched = new Retain(unMatched, uniqInputFields[i]); unMatched = new Rename(unMatched, uniqInputFields[i], componentParameters.getCopyOfInSocket(unusedSocket.getCopyOfInSocketId())); unUsedLink = unMatched; // must register all assembly tails setOutLink("unused", unusedSocket.getSocketId(), joinEntity.getComponentId(), unUsedLink, componentParameters.getCopyOfInSocket(unusedSocket.getCopyOfInSocketId()));// uniqInputFields[i]); } } } }
From source file:ch.njol.skript.lang.SkriptParser.java
@Nullable
private final Expression<?> parseSingleExpr(final boolean allowUnparsedLiteral, @Nullable final LogEntry error,
final ExprInfo vi) {
if (expr.isEmpty()) // Empty expressions return nothing, obviously
return null;
// Command special parsing
if (context != ParseContext.COMMAND && expr.startsWith("(") && expr.endsWith(")")
&& next(expr, 0, context) == expr.length())
return new SkriptParser(this, "" + expr.substring(1, expr.length() - 1))
.parseSingleExpr(allowUnparsedLiteral, error, vi);
final ParseLogHandler log = SkriptLogger.startParseLogHandler();
try {/* w ww. j ava2 s .c om*/
// Construct types array which contains all potential classes
final Class<?>[] types = new Class[vi.classes.length]; // This may contain nulls!
boolean hasSingular = false;
boolean hasPlural = false;
// Another array for all potential types, but this time without any nulls
// (indexes do not align with other data in ExprInfo)
final Class<?>[] nonNullTypes = new Class[vi.classes.length];
int nonNullIndex = 0;
for (int i = 0; i < types.length; i++) {
if ((flags & vi.flagMask) == 0) { // Flag mask invalidates this, skip it
continue;
}
// Plural/singular checks
// TODO move them elsewhere, this method needs to be as fast as possible
if (vi.isPlural[i])
hasPlural = true;
else
hasSingular = true;
// Actually put class to types[i]
types[i] = vi.classes[i].getC();
// Handle nonNullTypes data fill
nonNullTypes[nonNullIndex] = types[i];
nonNullIndex++;
}
boolean onlyPlural = false;
boolean onlySingular = false;
if (hasSingular && !hasPlural)
onlySingular = true;
else if (!hasSingular && hasPlural)
onlyPlural = true;
if (context == ParseContext.DEFAULT || context == ParseContext.EVENT) {
// Attempt to parse variable first
if (onlySingular || onlyPlural) { // No mixed plurals/singulars possible
final Variable<?> var = parseVariable(expr, nonNullTypes);
if (var != null) { // Parsing succeeded, we have a variable
// If variables cannot be used here, it is now allowed
if ((flags & PARSE_EXPRESSIONS) == 0) {
Skript.error("Variables cannot be used here.");
log.printError();
return null;
}
// Plural/singular sanity check
if (hasSingular && !var.isSingle()) {
Skript.error("'" + expr + "' can only accept a single value of any type, not more",
ErrorQuality.SEMANTIC_ERROR);
return null;
}
log.printLog();
return var;
} else if (log.hasError()) {
log.printError();
return null;
}
} else { // Mixed plurals/singulars
@SuppressWarnings("unchecked")
final Variable<?> var = parseVariable(expr, types);
if (var != null) { // Parsing succeeded, we have a variable
// If variables cannot be used here, it is now allowed
if ((flags & PARSE_EXPRESSIONS) == 0) {
Skript.error("Variables cannot be used here.");
log.printError();
return null;
}
// Plural/singular sanity check
//
// It's (currently?) not possible to detect this at parse time when there are multiple
// acceptable types and only some of them are single, since variables, global especially,
// can hold any possible type, and the type used can only be 100% known at runtime
//
// TODO:
// despite of that, we should probably implement a runtime check for this somewhere
// before executing the syntax element (perhaps even exceptionally with a console warning,
// otherwise users may have some hard time debugging the plurality issues) - currently an
// improper use in a script would result in an exception
if (((vi.classes.length == 1 && !vi.isPlural[0]) || Booleans.contains(vi.isPlural, true))
&& !var.isSingle()) {
Skript.error(
"'" + expr + "' can only accept a single "
+ Classes.toString(Stream.of(vi.classes)
.map(ci -> ci.getName().toString()).toArray(), false)
+ ", not more",
ErrorQuality.SEMANTIC_ERROR);
return null;
}
log.printLog();
return var;
} else if (log.hasError()) {
log.printError();
return null;
}
}
// If it wasn't variable, do same for function call
final FunctionReference<?> fr = parseFunction(types);
if (fr != null) {
log.printLog();
return new ExprFunctionCall<>(fr);
} else if (log.hasError()) {
log.printError();
return null;
}
}
log.clear();
if ((flags & PARSE_EXPRESSIONS) != 0) {
final Expression<?> e;
if (expr.startsWith("\"") && expr.endsWith("\"") && expr.length() != 1
&& (types[0] == Object.class || CollectionUtils.contains(types, String.class))) {
e = VariableString.newInstance("" + expr.substring(1, expr.length() - 1));
} else {
e = (Expression<?>) parse(expr, (Iterator) Skript.getExpressions(types), null);
}
if (e != null) { // Expression/VariableString parsing success
Class<?> returnType = e.getReturnType(); // Sometimes getReturnType does non-trivial costly operations
assert returnType != null;
for (int i = 0; i < types.length; i++) {
final Class<?> t = types[i];
if (t == null) // Ignore invalid (null) types
continue;
// Check return type against everything that expression accepts
if (t.isAssignableFrom(returnType)) {
if (!vi.isPlural[i] && !e.isSingle()) { // Wrong number of arguments
if (context == ParseContext.COMMAND) {
Skript.error(
Commands.m_too_many_arguments.toString(
vi.classes[i].getName().getIndefiniteArticle(),
vi.classes[i].getName().toString()),
ErrorQuality.SEMANTIC_ERROR);
return null;
} else {
Skript.error("'" + expr + "' can only accept a single "
+ vi.classes[i].getName() + ", not more", ErrorQuality.SEMANTIC_ERROR);
return null;
}
}
log.printLog();
return e;
}
}
// No directly same type found
if (types.length == 1) { // Only one type is accepted here
// So, we'll just create converted expression
@SuppressWarnings("unchecked") // This is safe... probably
Expression<?> r = e.getConvertedExpression((Class<Object>[]) types);
if (r != null) {
log.printLog();
return r;
}
} else { // Multiple types accepted
if (returnType == Object.class) { // No specific return type, so probably variable etc.
log.printLog();
return e; // Expression will have to deal with it runtime
} else {
Expression<?> r = e.getConvertedExpression((Class<Object>[]) types);
if (r != null) {
log.printLog();
return r;
}
}
}
// Print errors, if we couldn't get the correct type
log.printError(e.toString(null, false) + " " + Language.get("is") + " " + notOfType(types),
ErrorQuality.NOT_AN_EXPRESSION);
return null;
}
log.clear();
}
if ((flags & PARSE_LITERALS) == 0) {
log.printError();
return null;
}
if (vi.classes[0].getC() == Object.class) {
if (!allowUnparsedLiteral) {
log.printError();
return null;
}
log.clear();
log.printLog();
final LogEntry e = log.getError();
return new UnparsedLiteral(expr,
e != null && (error == null || e.quality > error.quality) ? e : error);
}
for (final ClassInfo<?> ci : vi.classes) {
log.clear();
assert ci.getC() != null;
final Object t = Classes.parse(expr, ci.getC(), context);
if (t != null) {
log.printLog();
return new SimpleLiteral<>(t, false);
}
}
log.printError();
return null;
} finally {
log.stop();
}
}