List of usage examples for java.util.stream Stream concat
public static <T> Stream<T> concat(Stream<? extends T> a, Stream<? extends T> b)
From source file:org.lightjason.agentspeak.common.CCommon.java
/** * reads all methods by the action-annotations * for building agent-actions//from www. j a v a 2s . c om * * @param p_class class * @param p_root root class * @return stream of all methods with inheritance */ private static Stream<Method> methods(final Class<?> p_class, final Class<?> p_root) { final Pair<Boolean, IAgentAction.EAccess> l_classannotation = CCommon.isActionClass(p_class); if (!l_classannotation.getLeft()) return p_class.getSuperclass() == null ? Stream.of() : methods(p_class.getSuperclass(), p_root); final Predicate<Method> l_filter = IAgentAction.EAccess.WHITELIST.equals(l_classannotation.getRight()) ? i -> !CCommon.isActionFiltered(i, p_root) : i -> CCommon.isActionFiltered(i, p_root); return Stream.concat(Arrays.stream(p_class.getDeclaredMethods()).parallel().map(i -> { i.setAccessible(true); return i; }).filter(i -> !Modifier.isAbstract(i.getModifiers())).filter(i -> !Modifier.isInterface(i.getModifiers())) .filter(i -> !Modifier.isNative(i.getModifiers())).filter(i -> !Modifier.isStatic(i.getModifiers())) .filter(l_filter), methods(p_class.getSuperclass(), p_root)); }
From source file:com.thinkbiganalytics.metadata.modeshape.user.JcrUserGroup.java
private Stream<Node> streamAllContainingGroupNodes(Node groupNode) { Set<Node> referenced = JcrPropertyUtil.<Node>getSetProperty(groupNode, JcrUserGroup.GROUPS); return Stream.concat(referenced.stream(), referenced.stream().flatMap(node -> streamAllContainingGroupNodes(node))); }
From source file:org.springframework.cloud.deployer.spi.cloudfoundry.CloudFoundry2620AndEarlierTaskLauncher.java
private String getCommand(Droplet droplet, AppDeploymentRequest request) { String defaultCommand = ((StagedResult) droplet.getResult()).getProcessTypes().get("web"); return Stream.concat(Stream.of(defaultCommand), request.getCommandlineArguments().stream()) .collect(Collectors.joining(" ")); }
From source file:com.wrmsr.wava.analyze.ValueTypeAnalysis.java
public static ValueTypeAnalysis analyze(Node root, boolean isRootUsed) { Map<Node, Entry> analyses = newIdentityHashMap(); Entry rootAnalysis = root.accept(new Visitor<Context, Entry>() { private Entry analyzeChild(Node child, Context context) { Entry analysis = child.accept(this, context); analyses.put(child, analysis); return analysis; }/*from w w w . j a va 2s. com*/ @Override protected Entry visitNode(Node node, Context context) { throw new IllegalStateException(); } @Override public Entry visitBinary(Binary node, Context context) { Entry left = analyzeChild(node.getLeft(), new Context(true)); Entry right = analyzeChild(node.getRight(), new Context(true)); checkState(left.getType() == right.getType()); checkState(left.getType().isConcrete()); Type resultType = requireNonNull( node.getOp().getTypeMap().get(ImmutablePair.of(left.getType(), right.getType()))); checkState(node.getType() == resultType); return new Entry(node.getType(), mergeValueInitializations(left.getInitialization(), right.getInitialization()), mergeValueOwnerships(left.getOwnership(), right.getOwnership()), mergeBreakValueTypes(left.getBreakValueTypes(), right.getBreakValueTypes()), context); } @Override public Entry visitBlock(Block node, Context context) { List<Node> children = node.getChildren(); List<Entry> init = listInit(children).map(c -> analyzeChild(c, new Context(false))) .collect(toImmutableList()); Entry last = analyzeChild(listLast(children), new Context(context.isUsed)); ImMap<Name, Set<Type>> breakValueTypes = Stream.concat(init.stream(), Stream.of(last)) .map(Entry::getBreakValueTypes) .reduce(EMPTY_BREAK_VALUE_TYPES, ValueTypeAnalysis::mergeBreakValueTypes); return new Entry(last.getType(), init.isEmpty() && last.getInitialization() == Initialization.INLINE ? Initialization.INLINE : !last.getType().isConcrete() ? Initialization.VOID : Initialization.SETUP, last.getOwnership(), breakValueTypes, context); } @Override public Entry visitBreak(Break node, Context context) { // checkState(!context.isUsed); Entry value = analyzeChild(node.getValue(), new Context(true)); return new Entry(Type.NONE, Initialization.VOID, Ownership.VOID, updateBreakValueTypes( value.getBreakValueTypes(), ImmutableList.of(node.getTarget()), value.getType()), context); } @Override public Entry visitBreakTable(BreakTable node, Context context) { // checkState(!context.isUsed); Entry condition = analyzeChild(node.getCondition(), new Context(true)); return new Entry(Type.NONE, Initialization.VOID, Ownership.VOID, updateBreakValueTypes(condition.getBreakValueTypes(), ImmutableList.<Name>builder() .addAll(node.getTargets()).add(node.getDefaultTarget()).build(), Type.NONE), context); } @Override public Entry visitCall(Call node, Context context) { // TODO: check operands? Call.Target target = node.getTarget(); Type type = node.getSignature().getResult(); requireNonNull(type); List<Entry> operands = node.getOperands().stream().map(o -> analyzeChild(o, new Context(true))) .collect(toImmutableList()); checkState(operands.stream().allMatch(o -> o.getType().isConcrete())); return new Entry(type, mergeValueInitializations(operands.stream().map(Entry::getInitialization) .collect(toImmutableList()).toArray(new Initialization[] {})), Ownership.FREE, operands.stream().map(Entry::getBreakValueTypes) .reduce(EMPTY_BREAK_VALUE_TYPES, ValueTypeAnalysis::mergeBreakValueTypes), context); } @Override public Entry visitCallIndirect(CallIndirect node, Context context) { Entry target = analyzeChild(node.getTarget(), new Context(true)); checkState(target.getType().isConcrete()); List<Entry> operands = node.getOperands().stream().map(o -> analyzeChild(o, new Context(true))) .collect(toImmutableList()); checkState(operands.stream().allMatch(o -> o.getType().isConcrete())); return new Entry(node.getSignature().getResult(), mergeValueInitializations( Stream.concat(Stream.of(target), operands.stream()).map(Entry::getInitialization) .collect(toImmutableList()).toArray(new Initialization[] {})), Ownership.FREE, Stream.concat(Stream.of(target), operands.stream()).map(Entry::getBreakValueTypes) .reduce(EMPTY_BREAK_VALUE_TYPES, ValueTypeAnalysis::mergeBreakValueTypes), context); } @Override public Entry visitConst(Const node, Context context) { return new Entry(node.getLiteral().getType(), Initialization.INLINE, Ownership.FREE, EMPTY_BREAK_VALUE_TYPES, context); } @Override public Entry visitGetLocal(GetLocal node, Context context) { return new Entry(node.getType(), Initialization.INLINE, Ownership.FREE, EMPTY_BREAK_VALUE_TYPES, context); } @Override public Entry visitIf(If node, Context context) { Entry condition = analyzeChild(node.getCondition(), new Context(true)); Entry ifTrue = analyzeChild(node.getIfTrue(), new Context(context.isUsed)); Entry ifFalse = analyzeChild(node.getIfFalse(), new Context(context.isUsed)); checkState(condition.getType().isConcrete()); ImMap<Name, Set<Type>> breakValueTypes = Stream.of(condition, ifTrue, ifFalse) .map(Entry::getBreakValueTypes) .reduce(EMPTY_BREAK_VALUE_TYPES, ValueTypeAnalysis::mergeBreakValueTypes); if (context.isUsed) { checkState(ifTrue.getType() == ifFalse.getType()); checkState(ifTrue.getType().isConcrete()); return new Entry(ifTrue.getType(), mergeValueInitializations(condition.getInitialization(), ifTrue.getInitialization(), ifFalse.getInitialization()), mergeValueOwnerships(ifTrue.getOwnership(), ifFalse.getOwnership()), breakValueTypes, context); } else { return new Entry(Type.NONE, Initialization.VOID, Ownership.VOID, breakValueTypes, context); } } @Override public Entry visitLabel(Label node, Context context) { // FIXME CFA -> ignore unreachable tails? or expect removed? Entry body = analyzeChild(node.getBody(), new Context(context.isUsed)); ImMap<Name, Set<Type>> breakValueTypes = body.getBreakValueTypes(); Type type = body.getType(); Initialization initialization = body.getInitialization(); Ownership ownership = body.getOwnership(); if (breakValueTypes.containsKey(node.getName())) { Type breakType = Iterables.getOnlyElement(breakValueTypes.get(node.getName())); if (breakType.isConcrete()) { checkState(type == breakType || type == Type.NONE); type = breakType; initialization = Initialization.SETUP; ownership = Ownership.TEMP; } else { if (context.isUsed) { checkState(type == Type.NONE); } else { type = Type.NONE; initialization = Initialization.VOID; ownership = Ownership.VOID; } } breakValueTypes = breakValueTypes.without(node.getName()); } return new Entry(type, initialization, ownership, breakValueTypes, context); } @Override public Entry visitLoad(Load node, Context context) { Entry ptr = analyzeChild(node.getPtr(), new Context(true)); checkState(ptr.getType() == Type.I32); return new Entry(node.getType(), ptr.getInitialization(), Ownership.FREE, ptr.getBreakValueTypes(), context); } @Override public Entry visitLoop(Loop node, Context context) { Entry body = analyzeChild(node.getBody(), new Context(context.isUsed)); ImMap<Name, Set<Type>> breakValueTypes = body.getBreakValueTypes(); if (breakValueTypes.containsKey(node.getName())) { checkState(breakValueTypes.get(node.getName()).equals(EnumSet.of(Type.NONE))); breakValueTypes = breakValueTypes.without(node.getName()); } return new Entry(body.getType(), body.getInitialization(), body.getOwnership(), breakValueTypes, context); } @Override public Entry visitNop(Nop node, Context context) { return new Entry(Type.NONE, Initialization.VOID, Ownership.VOID, EMPTY_BREAK_VALUE_TYPES, context); } @Override public Entry visitReturn(Return node, Context context) { checkState(!context.isUsed); Entry value = analyzeChild(node.getValue(), new Context(true)); return new Entry(Type.NONE, Initialization.VOID, Ownership.VOID, value.getBreakValueTypes(), context); } @Override public Entry visitSelect(Select node, Context context) { Entry ifTrue = analyzeChild(node.getIfTrue(), new Context(true)); Entry ifFalse = analyzeChild(node.getIfFalse(), new Context(true)); Entry condition = analyzeChild(node.getCondition(), new Context(true)); checkState(ifTrue.getType() == ifFalse.getType()); checkState(ifTrue.getType().isConcrete()); checkState(condition.getType() == Type.I32); return new Entry(ifTrue.getType(), Initialization.SETUP, // FIXME? used check? Ownership.TEMP, mergeBreakValueTypes(ImmutableList.of(ifTrue.getBreakValueTypes(), ifFalse.getBreakValueTypes(), condition.getBreakValueTypes())), context); } @Override public Entry visitSetLocal(SetLocal node, Context context) { Entry value = analyzeChild(node.getValue(), new Context(true)); checkState(value.getType().isConcrete()); checkState(value.getType() == node.getType()); return new Entry(value.getType(), value.getInitialization(), value.getOwnership(), value.getBreakValueTypes(), context); } @Override public Entry visitStore(Store node, Context context) { Entry ptr = analyzeChild(node.getPtr(), new Context(true)); Entry value = analyzeChild(node.getValue(), new Context(true)); checkState(ptr.getType() == Type.I32); checkState(value.getType() == node.getType()); return new Entry(node.getType(), mergeValueInitializations(ptr.getInitialization(), value.getInitialization()), value.getOwnership(), mergeBreakValueTypes(ptr.getBreakValueTypes(), value.getBreakValueTypes()), context); } @Override public Entry visitSwitch(Switch node, Context context) { List<Entry> cases = node.getEntries().stream().map(Switch.Entry::getBody) .map(child -> analyzeChild(child, new Context(false))).collect(toImmutableList()); Entry condition = analyzeChild(node.getCondition(), new Context(true)); checkState(condition.getType().isConcrete() && !condition.getType().isFloat()); return new Entry(Type.NONE, Initialization.VOID, Ownership.VOID, mergeBreakValueTypes(Stream.concat(Stream.of(condition.getBreakValueTypes()), cases.stream().map(Entry::getBreakValueTypes)).iterator()), context); } @Override public Entry visitUnary(Unary node, Context context) { Entry value = analyzeChild(node.getValue(), new Context(true)); checkState(value.getType().isConcrete()); Set<Type> resultTypes = requireNonNull(node.getOp().getTypeMap().get(value.getType())); checkState(resultTypes.contains(node.getType())); return new Entry(node.getType(), value.getInitialization(), value.getOwnership(), value.getBreakValueTypes(), context); } @Override public Entry visitUnreachable(Unreachable node, Context context) { return new Entry(Type.UNREACHABLE, Initialization.VOID, Ownership.VOID, EMPTY_BREAK_VALUE_TYPES, context); } }, new Context(isRootUsed)); checkState(rootAnalysis.getBreakValueTypes().isEmpty()); analyses.put(root, rootAnalysis); return new ValueTypeAnalysis(analyses); }
From source file:org.apache.james.jmap.model.message.MimePart.java
private Optional<String> retrieveTextBody(Predicate<MimePart> filter) { return Stream.concat(Stream.of(this), getAttachmentsStream()).filter(filter).map(MimePart::getTextualBody) .filter(Optional::isPresent).map(Optional::get).findFirst(); }
From source file:org.apache.james.mailbox.elasticsearch.json.MimePart.java
private Stream<MimePart> textAttachments() { return Stream.concat(Stream.of(this), attachments.stream()).filter(this::isTextMediaType); }
From source file:com.thinkbiganalytics.feedmgr.rest.controller.UtilityRestController.java
/** * Gets the list of functions that can be used to produce partition values. * * @return an HTTP response containing the list of formulas *//*from w w w .jav a2s. co m*/ @GET @Path("/partition-functions") @Produces(MediaType.APPLICATION_JSON) @ApiOperation(value = "Gets the list of partition functions.", notes = "These functions can be used to produce partition values.") @ApiResponses(@ApiResponse(code = 200, message = "Returns the partition functions.", response = String.class, responseContainer = "Set")) @Nonnull public Response partitionFunctions() { final Stream<String> kyloFunctions = Stream.of("val", "to_date", "year", "month", "day", "hour", "minute"); final Stream<String> userFunctions = Arrays.stream(env.getProperty("kylo.metadata.udfs", "").split(",")) .map(String::trim).filter(StringUtils::isNotEmpty); return Response.ok(Stream.concat(kyloFunctions, userFunctions).collect(Collectors.toSet())).build(); }
From source file:org.lightjason.agentspeak.common.CPath.java
@Override public final synchronized IPath pushfront(final IPath p_path) { final List<String> l_path = Stream.concat(p_path.stream(), m_path.stream()).collect(Collectors.toList()); m_path.clear();// ww w . jav a2 s . c om l_path.forEach(m_path::add); return this; }
From source file:org.bonej.wrapperPlugins.FractalDimensionWrapper.java
private boolean allValuesFinite(final Collection<ValuePair<DoubleType, DoubleType>> pairs) { final Stream<Double> xValues = pairs.stream().map(p -> p.a.get()); final Stream<Double> yValues = pairs.stream().map(p -> p.b.get()); return Stream.concat(xValues, yValues).allMatch(Double::isFinite); }
From source file:org.apache.james.jmap.model.message.MimePart.java
@JsonIgnore public Stream<MimePart> getAttachmentsStream() { return attachments.stream() .flatMap((mimePart) -> Stream.concat(Stream.of(mimePart), mimePart.getAttachmentsStream())); }