Java Code Examples for java.util.stream.Stream#concat()

The following examples show how to use java.util.stream.Stream#concat() . 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: T212MapValueRangeValidator.java    From hj-t212-parser with Apache License 2.0 6 votes vote down vote up
@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;
    }
 
Example 2
Source File: SourceCode.java    From Recaf with MIT License 6 votes vote down vote up
/**
 * @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());
}
 
Example 3
Source File: Histogram.java    From monsoon with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * 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;
            })));
}
 
Example 4
Source File: LPNukkitPlugin.java    From LuckPerms with MIT License 5 votes vote down vote up
@Override
public Stream<Sender> getOnlineSenders() {
    return Stream.concat(
            Stream.of(getConsoleSender()),
            this.bootstrap.getServer().getOnlinePlayers().values().stream().map(p -> getSenderFactory().wrap(p))
    );
}
 
Example 5
Source File: RobolectricTest.java    From buck with Apache License 2.0 5 votes vote down vote up
@Override
public Stream<BuildTarget> getRuntimeDeps(BuildRuleResolver buildRuleResolver) {
  return Stream.concat(
      // Inherit any runtime deps from `JavaTest`.
      super.getRuntimeDeps(buildRuleResolver),
      robolectricTestHelper.getExtraRuntimeDeps(buildRuleResolver, getBuildDeps()));
}
 
Example 6
Source File: GoTestX.java    From buck with Apache License 2.0 5 votes vote down vote up
@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));
}
 
Example 7
Source File: ManagementFactory.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example 8
Source File: InputReader.java    From nemo with Apache License 2.0 5 votes vote down vote up
/**
 * 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();
}
 
Example 9
Source File: Window.java    From protonpack with MIT License 5 votes vote down vote up
<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));
  }
}
 
Example 10
Source File: PublicKeySerializerTest.java    From exonum-java-binding with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 11
Source File: CollectionManager.java    From beanshell with Apache License 2.0 5 votes vote down vote up
/** 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("}"));
}
 
Example 12
Source File: SystemInputs.java    From tcases with MIT License 5 votes vote down vote up
/**
 * 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())));
  }
 
Example 13
Source File: CodeGen.java    From vertx-codegen with Apache License 2.0 5 votes vote down vote up
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()));
}
 
Example 14
Source File: TokenizedMessageToAnsiConverter.java    From webtau with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 15
Source File: ExportTest.java    From latexdraw with GNU General Public License v3.0 4 votes vote down vote up
@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();
			}
		}));
}
 
Example 16
Source File: NetworkImpl.java    From powsybl-core with Mozilla Public License 2.0 4 votes vote down vote up
@Override
public Stream<Branch> getBranchStream() {
    return Stream.concat(getLineStream(), getTwoWindingsTransformerStream());
}
 
Example 17
Source File: MethodInfo.java    From smallrye-graphql with Apache License 2.0 4 votes vote down vote up
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));
}
 
Example 18
Source File: StdGridSupplier.java    From latexdraw with GNU General Public License v3.0 4 votes vote down vote up
public static Stream<StandardGrid> createDiversifiedStdGrids() {
	return Stream.concat(ShapeSupplier.createDiversifiedGrid(), ShapeSupplier.createDiversifiedAxes());
}
 
Example 19
Source File: DependencyTree.java    From baleen with Apache License 2.0 4 votes vote down vote up
/**
 * 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));
}
 
Example 20
Source File: Streams.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
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)));
}