java.util.stream.Stream#concat ( )源码实例Demo

下面列出了java.util.stream.Stream#concat ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

@Override
    public boolean isValid(T212Map value, ConstraintValidatorContext constraintValidatorContext) {
        Map<String, String> result = value;

        Stream<DataElement> stream = Stream.of(DataElement.values())
                .filter(DataElement::isRequired);
        if(result.containsKey(DataElement.Flag.name())){
            String f = result.get(DataElement.Flag.name());
            int flag = Integer.valueOf(f);
            if(DataFlag.D.isMarked(flag)){
                stream = Stream.concat(stream,Stream.of(DataElement.PNO, DataElement.PNUM));
            }
        }

        Optional<DataElement> missing = stream
                .filter(e -> !result.containsKey(e.name()))
                .findFirst();
        if(missing.isPresent()){
//            T212FormatException.field_is_missing(PacketElement.DATA,missing.get().name());
            return false;
        }
        return true;
    }
 
源代码2 项目: Recaf   文件: SourceCode.java
/**
 * @return List of all classes imported. This includes the {@link #getImports() explicit
 * imports} and the implied classes from the current and "java.lang" packages.
 */
public List<String> getAllImports() {
	if (impliedImports != null)
		return impliedImports;
	// Get stream of classes in the same package
	String pkg = getPackage();
	Stream<String> pkgStream;
	if (pkg.equals(DEFAULT_PACKAGE))
		pkgStream = resource.getClasses().keySet().stream().filter(name ->!name.contains("/"));
	else
		pkgStream = resource.getClasses().keySet().stream().filter(name -> {
			if (!name.contains("/"))
				return false;
			String tmpPackageName = name.substring(0, name.lastIndexOf("/"));
			return tmpPackageName.equals(pkg);
		});
	pkgStream = Stream.concat(pkgStream, Stream.of(LANG_PACKAGE_NAMES).map(n -> "java/lang/" + n));
	// Combine with explicit
	return impliedImports = Stream.concat(getImports().stream(), pkgStream)
			.collect(Collectors.toList());
}
 
源代码3 项目: LuckPerms   文件: LPNukkitPlugin.java
@Override
public Stream<Sender> getOnlineSenders() {
    return Stream.concat(
            Stream.of(getConsoleSender()),
            this.bootstrap.getServer().getOnlinePlayers().values().stream().map(p -> getSenderFactory().wrap(p))
    );
}
 
源代码4 项目: webtau   文件: TokenizedMessageToAnsiConverter.java
private Stream<?> convertToAnsiSequence(TokenRenderDetails renderDetails, MessageToken messageToken, boolean addSpace) {
    Stream<Object> valueStream = addSpace ?
            Stream.of(messageToken.getValue(), " "):
            Stream.of(messageToken.getValue());

    return Stream.concat(renderDetails.ansiSequence.stream(), valueStream);
}
 
源代码5 项目: vertx-codegen   文件: CodeGen.java
public Stream<Map.Entry<? extends Element, ? extends Model>> getModels() {
  Stream<Map.Entry<? extends Element, ? extends Model>> s = Stream.empty();
  for (Map<String, Map.Entry<TypeElement, Model>> m : models.values()) {
    s = Stream.concat(s, m.values().stream());
  }
  return Stream.concat(s, Stream.concat(getModuleModels(), getPackageModels()));
}
 
源代码6 项目: tcases   文件: SystemInputs.java
/**
 * Returns the IConditional instances defined by the given variable definition.
 */
private static Stream<IConditional> conditionals( IVarDef var)
  {
  return
    Stream.concat
    ( Stream.of( var),
      Stream.concat
      ( Optional.ofNullable( var.getMembers()).map( members -> toStream( members).flatMap( member -> conditionals( member))).orElse( Stream.empty()),
        Optional.ofNullable( var.getValues()).map( values -> toStream( values).map( value -> new VarBindingDef( (VarDef)var, value))).orElse( Stream.empty())));
  }
 
源代码7 项目: beanshell   文件: CollectionManager.java
/** Apply reflection to supplied value returning an
 * iterable stream of strings. Allows iteration over
 * true string representations of the class and member
 * definitions. For generated classes the true or bsh
 * definitions are retrieved and not the java reflection
 * of the mock instances.
 * @param obj the type to reflect
 * @return an iterable stream of String definitions */
private Stream<String> reflectNames(Object obj) {
    Class<?> type = obj.getClass();
    if (obj instanceof Class<?>)
        type = (Class<?>) obj;
    if (obj instanceof ClassIdentifier)
        type = ((ClassIdentifier)obj).getTargetClass();
    if (Reflect.isGeneratedClass(type))
        return Stream.concat(Stream.concat(
            Stream.of(StringUtil.classString(type)),
            Stream.concat(
                Stream.of(Reflect.getDeclaredVariables(type))
                    .map(StringUtil::variableString)
                    .map("    "::concat),
                Stream.of(Reflect.getDeclaredMethods(type))
                    .map(StringUtil::methodString)
                    .map("    "::concat))), Stream.of("}"));
    else
        return Stream.concat(Stream.concat(
            Stream.of(StringUtil.classString(type)),
            Stream.concat(
                Stream.of(type.getFields())
                    .map(StringUtil::variableString)
                    .map("    "::concat),
                Stream.of(type.getMethods())
                    .map(StringUtil::methodString)
                    .map("    "::concat))), Stream.of("}"));
}
 
private static Stream<PublicKey> testSource() {
  Stream<PublicKey> keysFromBytes =
      Stream.of(
          Bytes.bytes("key string"),
          Bytes.bytes(1, 2, 3, 4, 6))
          .map(PublicKey::fromBytes);

  Stream<PublicKey> ed25519Keys =
      Stream.of(
          ed25519().generateKeyPair())
          .map(KeyPair::getPublicKey);

  return Stream.concat(keysFromBytes, ed25519Keys);
}
 
源代码9 项目: protonpack   文件: Window.java
<R> Stream<R> reduce(Function<Stream<T>, R> reducer) {
  if (count < size) {
    return Stream.empty();
  }
  try (Stream<T> windowStream = Stream.concat(
      IntStream.range(index, size).mapToObj(contents::get),
      IntStream.range(0, index).mapToObj(contents::get))) {
    return Stream.of(reducer.apply(windowStream));
  }
}
 
源代码10 项目: nemo   文件: InputReader.java
/**
 * Combine the given list of futures.
 *
 * @param futures to combine.
 * @return the combined iterable of elements.
 * @throws ExecutionException   when fail to get results from futures.
 * @throws InterruptedException when interrupted during getting results from futures.
 */
@VisibleForTesting
public static Iterator combineFutures(final List<CompletableFuture<DataUtil.IteratorWithNumBytes>> futures)
    throws ExecutionException, InterruptedException {
  final List concatStreamBase = new ArrayList<>();
  Stream<Object> concatStream = concatStreamBase.stream();
  for (int srcTaskIdx = 0; srcTaskIdx < futures.size(); srcTaskIdx++) {
    final Iterator dataFromATask = futures.get(srcTaskIdx).get();
    final Iterable iterable = () -> dataFromATask;
    concatStream = Stream.concat(concatStream, StreamSupport.stream(iterable.spliterator(), false));
  }
  return concatStream.collect(Collectors.toList()).iterator();
}
 
源代码11 项目: openjdk-jdk9   文件: ManagementFactory.java
/**
 * Returns the list of the platform MXBean proxies for
 * forwarding the method calls of the {@code mxbeanInterface}
 * through the given {@code MBeanServerConnection}.
 * The returned list may contain zero, one, or more instances.
 * The number of instances in the returned list is defined
 * in the specification of the given management interface.
 * The order is undefined and there is no guarantee that
 * the list returned is in the same order as previous invocations.
 *
 * @param connection the {@code MBeanServerConnection} to forward to.
 * @param mxbeanInterface a management interface for a platform
 *                        MXBean
 * @param <T> an {@code mxbeanInterface} type parameter
 *
 * @return the list of platform MXBean proxies for
 * forwarding the method calls of the {@code mxbeanInterface}
 * through the given {@code MBeanServerConnection}.
 *
 * @throws IllegalArgumentException if {@code mxbeanInterface}
 * is not a platform management interface.
 *
 * @throws java.io.IOException if a communication problem
 * occurred when accessing the {@code MBeanServerConnection}.
 *
 * @see #newPlatformMXBeanProxy
 * @since 1.7
 */
public static <T extends PlatformManagedObject>
        List<T> getPlatformMXBeans(MBeanServerConnection connection,
                                   Class<T> mxbeanInterface)
    throws java.io.IOException
{
    // Validates at first the specified interface by finding at least one
    // PlatformComponent whose MXBean implements this interface.
    // An interface can be implemented by different MBeans, provided by
    // different platform components.
    PlatformComponent<?> pc = PlatformMBeanFinder.findFirst(mxbeanInterface);
    if (pc == null) {
        throw new IllegalArgumentException(mxbeanInterface.getName()
                + " is not a platform management interface");
    }

    // Collect all names, eliminate duplicates.
    Stream<String> names = Stream.empty();
    for (PlatformComponent<?> p : platformComponents()) {
        names = Stream.concat(names, getProxyNames(p, connection, mxbeanInterface));
    }
    Set<String> objectNames = names.collect(Collectors.toSet());
    if (objectNames.isEmpty()) return Collections.emptyList();

    // Map names on proxies.
    List<T> proxies = new ArrayList<>();
    for (String name : objectNames) {
        proxies.add(newPlatformMXBeanProxy(connection, name, mxbeanInterface));
    }
    return proxies;
}
 
源代码12 项目: buck   文件: GoTestX.java
@Override
public Stream<BuildTarget> getRuntimeDeps(BuildRuleResolver buildRuleResolver) {
  return Stream.concat(
      Stream.of((testMain.getBuildTarget())),
      resources.stream()
          .map(buildRuleResolver::filterBuildRuleInputs)
          .flatMap(ImmutableSet::stream)
          .map(BuildRule::getBuildTarget));
}
 
源代码13 项目: buck   文件: RobolectricTest.java
@Override
public Stream<BuildTarget> getRuntimeDeps(BuildRuleResolver buildRuleResolver) {
  return Stream.concat(
      // Inherit any runtime deps from `JavaTest`.
      super.getRuntimeDeps(buildRuleResolver),
      robolectricTestHelper.getExtraRuntimeDeps(buildRuleResolver, getBuildDeps()));
}
 
源代码14 项目: monsoon   文件: Histogram.java
/**
 * Subtracts two histograms.
 *
 * @throws IllegalArgumentException If the result contains mixed signs.
 */
public static Histogram subtract(Histogram x, Histogram y) {
    return new Histogram(Stream.concat(
            x.stream(),
            y.stream().map(rwc -> {
                rwc.setCount(-rwc.getCount());
                return rwc;
            })));
}
 
源代码15 项目: ProjectAres   文件: Streams.java
public static <T> Stream<T> compact3(T t1, T t2, T t3, Optional<T>... elements) {
    return Stream.concat(Stream.of(t1, t2, t3), compact(Stream.of(elements)));
}
 
源代码16 项目: latexdraw   文件: StdGridSupplier.java
public static Stream<StandardGrid> createDiversifiedStdGrids() {
	return Stream.concat(ShapeSupplier.createDiversifiedGrid(), ShapeSupplier.createDiversifiedAxes());
}
 
源代码17 项目: smallrye-graphql   文件: MethodInfo.java
private static <A extends Annotation> Stream<A> resolveAnnotations(AnnotatedElement annotatedElement, Class<A> type) {
    return Stream.concat(Stream.of(annotatedElement.getAnnotationsByType(type)),
            resolveStereotypes(annotatedElement.getAnnotations(), type));
}
 
源代码18 项目: latexdraw   文件: ExportTest.java
@Override
protected Stream<Runnable> canDoFixtures() {
	return Stream.concat(Stream.of(
		() -> cmd = new Export(canvas, pstGen, ExportFormat.PDF, dialogueBox),
		() -> {
			Mockito.when(dialogueBox.showSaveDialog(Mockito.any())).thenReturn(file);
			Mockito.when(pstGen.createPDFFile(Mockito.anyString())).thenReturn(Optional.empty());
			cmd = new Export(canvas, pstGen, ExportFormat.PDF, dialogueBox);
		}, () -> {
			Mockito.when(dialogueBox.showSaveDialog(Mockito.any())).thenReturn(file);
			Mockito.when(pstGen.createEPSFile(Mockito.anyString())).thenReturn(Optional.empty());
			cmd = new Export(canvas, pstGen, ExportFormat.EPS_LATEX, dialogueBox);
		}, () -> {
			Mockito.when(dialogueBox.showSaveDialog(Mockito.any())).thenReturn(file);
			Mockito.when(pstGen.createEPSFile(Mockito.anyString())).thenReturn(Optional.of(new File("eifdjfd__hsi")));
			cmd = new Export(canvas, pstGen, ExportFormat.EPS_LATEX, dialogueBox);
		}, () -> {
			Mockito.when(file.getName()).thenReturn("foo" + ExportFormat.EPS_LATEX.getFileExtension());
			Mockito.when(dialogueBox.showSaveDialog(Mockito.any())).thenReturn(file);
			Mockito.when(pstGen.createEPSFile(Mockito.anyString())).thenReturn(Optional.of(file));
			cmd = new Export(canvas, pstGen, ExportFormat.EPS_LATEX, dialogueBox);
		}, () -> {
			Mockito.when(dialogueBox.showSaveDialog(Mockito.any())).thenReturn(file);
			Mockito.when(pstGen.createPDFFile(Mockito.anyString())).thenReturn(Optional.of(new File("eifdjfdhsizr__u")));
			cmd = new Export(canvas, pstGen, ExportFormat.PDF, dialogueBox);
		}, () -> {
			Mockito.when(dialogueBox.showSaveDialog(Mockito.any())).thenReturn(file);
			Mockito.when(pstGen.createPDFFile(Mockito.anyString())).thenThrow(SecurityException.class);
			cmd = new Export(canvas, pstGen, ExportFormat.PDF, dialogueBox);
		}, () -> {
			Mockito.when(dialogueBox.showSaveDialog(Mockito.any())).thenReturn(file);
			Mockito.when(pstGen.createEPSFile(Mockito.any())).thenThrow(SecurityException.class);
			cmd = new Export(canvas, pstGen, ExportFormat.EPS_LATEX, dialogueBox);
		}, () -> {
			Mockito.when(dialogueBox.showSaveDialog(Mockito.any())).thenReturn(new File(System.getProperty("java.io.tmpdir")));
			cmd = new Export(canvas, pstGen, ExportFormat.TEX, dialogueBox);
		}, () -> {
			Mockito.when(dialogueBox.showSaveDialog(Mockito.any())).thenReturn(new File(System.getProperty("java.io.tmpdir")));
			cmd = new Export(canvas, pstGen, ExportFormat.PNG, dialogueBox);
		}),
		Stream.of(ExportFormat.values()).map(f -> () -> {
			try {
				final File tempFile = File.createTempFile("foo", "");
				tempFile.deleteOnExit();
				Mockito.when(dialogueBox.showSaveDialog(Mockito.any())).thenReturn(tempFile);
				cmd = new Export(canvas, pstGen, f, dialogueBox);
				assertThat(cmd.hadEffect()).isFalse();
			}catch(final IOException ex) {
				fail();
			}
		}));
}
 
源代码19 项目: powsybl-core   文件: NetworkImpl.java
@Override
public Stream<Branch> getBranchStream() {
    return Stream.concat(getLineStream(), getTwoWindingsTransformerStream());
}
 
源代码20 项目: baleen   文件: DependencyTree.java
/**
 * Flatten the tree to a stream.
 *
 * @return a stream of the tree and all it's subtrees
 */
public Stream<DependencyTree> flattened() {
  return Stream.concat(
      Stream.of(this),
      dependencies.stream().map(DependencyEdge::getTree).flatMap(DependencyTree::flattened));
}