/** * If a value is present in {@code optional}, returns a stream containing only that element, * otherwise returns an empty stream. * * <p><b>Java 9 users:</b> use {@code optional.stream()} instead. */ public static IntStream stream(OptionalInt optional) { return optional.isPresent() ? IntStream.of(optional.getAsInt()) : IntStream.empty(); }
private static IntStream empty() { return IntStream.empty(); }
/** * If a value is present in {@code optional}, returns a stream containing only that element, * otherwise returns an empty stream. * * <p><b>Java 9 users:</b> use {@code optional.stream()} instead. */ public static IntStream stream(OptionalInt optional) { return optional.isPresent() ? IntStream.of(optional.getAsInt()) : IntStream.empty(); }
/** * If a value is present in {@code optional}, returns a stream containing only that element, * otherwise returns an empty stream. * * <p><b>Java 9 users:</b> use {@code optional.stream()} instead. */ public static IntStream stream(OptionalInt optional) { return optional.isPresent() ? IntStream.of(optional.getAsInt()) : IntStream.empty(); }
/** * If a value is present in {@code optional}, returns a stream containing only that element, * otherwise returns an empty stream. * * <p><b>Java 9 users:</b> use {@code optional.stream()} instead. */ public static IntStream stream(OptionalInt optional) { return optional.isPresent() ? IntStream.of(optional.getAsInt()) : IntStream.empty(); }
private int extractMaxIndex(String key, String suffixPattern) { // extract index and property keys final String escapedKey = Pattern.quote(key); final Pattern pattern = Pattern.compile(escapedKey + "\\.(\\d+)" + suffixPattern); final IntStream indexes = properties.keySet().stream() .flatMapToInt(k -> { final Matcher matcher = pattern.matcher(k); if (matcher.find()) { return IntStream.of(Integer.valueOf(matcher.group(1))); } return IntStream.empty(); }); // determine max index return indexes.max().orElse(-1); }
@SuppressWarnings( "unchecked" ) public static IntStream toBooleanStream( Object list ) { if ( list == null ) { return IntStream.empty(); } else if ( list instanceof SequenceValue ) { throw new IllegalArgumentException( "Need to implement support for SequenceValue in CompiledConversionUtils.toBooleanStream" ); } else if ( list instanceof List ) { return ((List) list).stream().mapToInt( n -> ((Number) n).intValue() ); } else if ( Object[].class.isAssignableFrom( list.getClass() ) ) { return Arrays.stream( (Object[]) list ).mapToInt( n -> ((Number) n).intValue() ); } else if ( list instanceof boolean[] ) { boolean[] array = (boolean[]) list; return IntStream.range( 0, array.length ).map( i -> (array[i]) ? 1 : 0 ); } throw new IllegalArgumentException( format( "Can not be converted to stream: %s", list.getClass().getName() ) ); }
@Override public TS build(boolean parallel) { if (Stream.class.equals(streamType)) { @SuppressWarnings("unchecked") final TS result = (TS) Stream.empty(); return result; } else if (IntStream.class.equals(streamType)) { @SuppressWarnings("unchecked") final TS result = (TS) IntStream.empty(); return result; } else if (LongStream.class.equals(streamType)) { @SuppressWarnings("unchecked") final TS result = (TS) LongStream.empty(); return result; } else if (DoubleStream.class.equals(streamType)) { @SuppressWarnings("unchecked") final TS result = (TS) DoubleStream.empty(); return result; } else { throw new UnsupportedOperationException( "Unknown stream type '" + streamType.getName() + "'." ); } } }
public void testConcat_intStream() { assertThat( Streams.concat(IntStream.of(1), IntStream.of(2), IntStream.empty(), IntStream.of(3, 4))) .containsExactly(1, 2, 3, 4) .inOrder(); }
/** * Extract the lines of all the locations in the specified component. All the flows and secondary locations * are taken into account. The lines present in multiple flows and locations are kept * duplicated. Ordering of results is not guaranteed. * <p> * TODO should be a method of DefaultIssue, as soon as it's no * longer in sonar-core and can access sonar-db-dao. */ public static IntStream allLinesFor(DefaultIssue issue, String componentId) { DbIssues.Locations locations = issue.getLocations(); if (locations == null) { return IntStream.empty(); } Stream<DbCommons.TextRange> textRanges = Stream.concat( locations.hasTextRange() ? Stream.of(locations.getTextRange()) : Stream.empty(), locations.getFlowList().stream() .flatMap(f -> f.getLocationList().stream()) .filter(l -> Objects.equals(componentIdOf(issue, l), componentId)) .map(DbIssues.Location::getTextRange)); return textRanges.flatMapToInt(range -> IntStream.rangeClosed(range.getStartLine(), range.getEndLine())); }
public void testCopyOf_stream() { assertThat(ImmutableIntArray.copyOf(IntStream.empty())).isSameAs(ImmutableIntArray.of()); assertThat(ImmutableIntArray.copyOf(IntStream.of(0, 1, 3)).asList()) .containsExactly(0, 1, 3) .inOrder(); }
return outOps.createIntList(inOps.getIntStream(input).orElse(IntStream.empty()));
/** * Converts nullable int array into an empty stream, and non-null array into a stream. * @param nullable The nullable array to convert. * @return A stream of zero or more values. */ public static IntStream ofNullable(int[] nullable) { return null == nullable ? IntStream.empty() : Arrays.stream(nullable); }
/** * Converts nullable int array into an empty stream, and non-null array into a stream. * @param nullable The nullable array to convert. * @return A stream of zero or more values. */ public static IntStream ofNullable(int[] nullable) { return null == nullable ? IntStream.empty() : Arrays.stream(nullable); }
/** * If a value is present in {@code optional}, returns a stream containing only that element, * otherwise returns an empty stream. * * <p><b>Java 9 users:</b> use {@code optional.stream()} instead. */ public static IntStream stream(OptionalInt optional) { return optional.isPresent() ? IntStream.of(optional.getAsInt()) : IntStream.empty(); }
/** * If a value is present in {@code optional}, returns a stream containing only that element, * otherwise returns an empty stream. * * <p><b>Java 9 users:</b> use {@code optional.stream()} instead. */ public static IntStream stream(OptionalInt optional) { return optional.isPresent() ? IntStream.of(optional.getAsInt()) : IntStream.empty(); }
/** * If a value is present in {@code optional}, returns a stream containing only that element, * otherwise returns an empty stream. * * <p><b>Java 9 users:</b> use {@code optional.stream()} instead. */ public static IntStream stream(OptionalInt optional) { return optional.isPresent() ? IntStream.of(optional.getAsInt()) : IntStream.empty(); }
/** * If a value is present in {@code optional}, returns a stream containing only that element, * otherwise returns an empty stream. * * <p><b>Java 9 users:</b> use {@code optional.stream()} instead. */ public static IntStream stream(OptionalInt optional) { return optional.isPresent() ? IntStream.of(optional.getAsInt()) : IntStream.empty(); }
/** * If a value is present in {@code optional}, returns a stream containing only that element, * otherwise returns an empty stream. * * <p><b>Java 9 users:</b> use {@code optional.stream()} instead. */ public static IntStream stream(OptionalInt optional) { return optional.isPresent() ? IntStream.of(optional.getAsInt()) : IntStream.empty(); }
/** * If a value is present in {@code optional}, returns a stream containing only that element, * otherwise returns an empty stream. * * <p><b>Java 9 users:</b> use {@code optional.stream()} instead. */ public static IntStream stream(OptionalInt optional) { return optional.isPresent() ? IntStream.of(optional.getAsInt()) : IntStream.empty(); }