本文整理了Java中java.util.stream.IntStream.sorted()
方法的一些代码示例,展示了IntStream.sorted()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。IntStream.sorted()
方法的具体详情如下:
包路径:java.util.stream.IntStream
类名称:IntStream
方法名:sorted
[英]Returns a stream consisting of the elements of this stream in sorted order.
This is a stateful intermediate operation.
[中]
代码示例来源:origin: speedment/speedment
public IntSortedAction() {
super(s -> s.sorted(), IntStream.class, SORTED);
}
代码示例来源:origin: shekhargulati/99-problems
public static IntPair minimize_unsorted(int[] numbers) {
int[] sorted = IntStream.of(numbers).sorted().toArray();
return minimize_sorted(sorted);
}
代码示例来源:origin: jdbi/jdbi
.sorted()
.toArray();
代码示例来源:origin: CalebFenton/simplify
private void replaceMethodInvoke() {
int[] invokeAddresses = Arrays.stream(addresses)
.filter(this::canReplaceMethodInvoke)
.sorted()
.toArray();
int count = invokeAddresses.length;
if (count == 0) {
return;
}
madeChanges = true;
unreflectedMethodCount += count;
for (int i = count - 1; i >= 0; i--) {
// Always replace in reverse order to avoid changing addresses
int address = invokeAddresses[i];
try {
List<BuilderInstruction> replacements = buildMethodInvokeReplacement(address);
manipulator.replaceInstruction(address, replacements);
} catch (Exception e) {
log.error("Unable to unreflect method invocation @" + address, e);
}
}
}
代码示例来源:origin: speedment/speedment
@Override
public IntStream sorted() {
return wrap(stream().sorted());
}
代码示例来源:origin: speedment/speedment
@Override
@SuppressWarnings("unchecked")
public TS build(boolean parallel) {
final TS built = previous().build(parallel);
if (built instanceof Stream<?>) {
if (comparator == null) {
return (TS) ((Stream<T>) built).sorted();
} else {
return (TS) ((Stream<T>) built).sorted(comparator);
}
} else if (built instanceof IntStream) {
return (TS) ((IntStream) built).sorted();
} else if (built instanceof LongStream) {
return (TS) ((LongStream) built).sorted();
} else if (built instanceof DoubleStream) {
return (TS) ((DoubleStream) built).sorted();
} else {
throw new UnsupportedOperationException(
"Built stream did not match any known stream interface."
);
}
}
}
代码示例来源:origin: apache/hbase
@Test
public void testAppend() throws InterruptedException, ExecutionException {
AsyncTable<?> table = getTable.get();
int count = 10;
CountDownLatch latch = new CountDownLatch(count);
char suffix = ':';
AtomicLong suffixCount = new AtomicLong(0L);
IntStream.range(0, count).forEachOrdered(
i -> table.append(new Append(row).addColumn(FAMILY, QUALIFIER, Bytes.toBytes("" + i + suffix)))
.thenAccept(r -> {
suffixCount.addAndGet(Bytes.toString(r.getValue(FAMILY, QUALIFIER)).chars()
.filter(x -> x == suffix).count());
latch.countDown();
}));
latch.await();
assertEquals((1 + count) * count / 2, suffixCount.get());
String value = Bytes.toString(
table.get(new Get(row).addColumn(FAMILY, QUALIFIER)).get().getValue(FAMILY, QUALIFIER));
int[] actual = Arrays.asList(value.split("" + suffix)).stream().mapToInt(Integer::parseInt)
.sorted().toArray();
assertArrayEquals(IntStream.range(0, count).toArray(), actual);
}
代码示例来源:origin: DV8FromTheWorld/JDA
@Override
public void restart()
{
TIntObjectMap<JDA> map = this.shards.getMap();
synchronized (map)
{
Arrays.stream(map.keys())
.sorted() // this ensures shards are started in natural order
.forEach(this::restart);
}
}
代码示例来源:origin: mahmoudparsian/data-algorithms-book
/**
* Sort a single string
*
* @param word a string
* @return a sorted word
*/
public static String sort8(final String word) {
String sorted = word.chars()
.sorted()
.collect(StringBuilder::new,
StringBuilder::appendCodePoint,
StringBuilder::append)
.toString();
return sorted;
}
代码示例来源:origin: inferred/FreeBuilder
@Override
public String intsInOrder(int... examples) {
return IntStream.of(examples).sorted().mapToObj(Integer::toString).collect(joining(", "));
}
};
代码示例来源:origin: geotools/geotools
return bands.stream().mapToInt(b -> b).sorted().toArray();
代码示例来源:origin: neo4j-contrib/neo4j-apoc-procedures
@BeforeClass
public static void setUp() throws Exception {
db = new TestGraphDatabaseFactory()
.newImpermanentDatabaseBuilder()
.setConfig(GraphDatabaseSettings.default_schema_provider, GraphDatabaseSettings.SchemaIndex.NATIVE20.providerName()) // TODO: switch to NATIVE20 - the default in 3.4
.newGraphDatabase();
TestUtil.registerProcedure(db, SchemaIndex.class);
db.execute("CREATE (city:City {name:'London'}) WITH city UNWIND range("+firstPerson+","+lastPerson+") as id CREATE (:Person {name:'name'+id, id:id, age:id % 100, address:id+'Main St.'})-[:LIVES_IN]->(city)").close();
//
// db.execute("CALL db.createIndex(':Person(name)', 'lucene-1.0')").close();
db.execute("CREATE INDEX ON :Person(name)").close();
db.execute("CREATE INDEX ON :Person(age)").close();
db.execute("CREATE INDEX ON :Person(address)").close();
// db.execute("CALL db.createIndex(':Person(address)', 'lucene-1.0')").close();
db.execute("CREATE CONSTRAINT ON (p:Person) ASSERT p.id IS UNIQUE").close();
db.execute("CREATE INDEX ON :Foo(bar)").close();
db.execute("CREATE (f:Foo {bar:'three'}), (f2a:Foo {bar:'four'}), (f2b:Foo {bar:'four'})").close();
personIds = IntStream.range(firstPerson, lastPerson+1).mapToObj(Long::new).collect(Collectors.toList());
personNames = IntStream.range(firstPerson, lastPerson+1).mapToObj(Integer::toString).map(i -> "name"+i).sorted().collect(Collectors.toList());
personAddresses = IntStream.range(firstPerson, lastPerson+1).mapToObj(Integer::toString).map(i -> i+"Main St.").sorted().collect(Collectors.toList());
personAges = IntStream.range(firstPerson, lastPerson+1).map(i -> i % 100).sorted().mapToObj(Long::new).collect(Collectors.toList());
try (Transaction tx=db.beginTx()) {
db.schema().awaitIndexesOnline(2,TimeUnit.SECONDS);
tx.success();
}
}
代码示例来源:origin: hazelcast/hazelcast-jet
private static void validateInboundEdgeOrdinals(Map<String, List<Edge>> inboundEdgeMap) {
for (Map.Entry<String, List<Edge>> entry : inboundEdgeMap.entrySet()) {
String vertex = entry.getKey();
int[] ordinals = entry.getValue().stream().mapToInt(Edge::getDestOrdinal).sorted().toArray();
for (int i = 0; i < ordinals.length; i++) {
if (ordinals[i] != i) {
throw new IllegalArgumentException("Input ordinals for vertex " + vertex
+ " are not properly numbered. Actual: " + Arrays.toString(ordinals)
+ " Expected: " + Arrays.toString(IntStream.range(0, ordinals.length).toArray()));
}
}
}
}
代码示例来源:origin: ml.alternet/alternet-tools
/**
* Defines a range with the codepoints given.
*
* @param equal <code>true</code> to indicate inclusion,
* <code>false</code> to indicate exclusion.
* @param codepoints The actual codepoints.
*/
Chars(boolean equal, IntStream codepoints) {
int[] cp = codepoints.sorted().distinct().toArray();
this.chars = new String(cp, 0, cp.length);
this.equal = equal;
}
代码示例来源:origin: asakusafw/asakusafw
/**
* Sets column indices which quoting is always required.
* @param indices the column indices
* @since 0.9.0
*/
public void setForceQuoteColumns(int... indices) {
this.forceQuoteColumns = IntStream.of(indices).sorted().distinct().toArray();
}
}
代码示例来源:origin: hazelcast/hazelcast-jet
Composite(OutboundCollector[] collectors) {
this.collectors = collectors;
this.broadcastTracker = new BitSet(collectors.length);
this.partitions = Stream.of(collectors)
.flatMapToInt(c -> IntStream.of(c.getPartitions()))
.sorted().toArray();
}
代码示例来源:origin: stackoverflow.com
class UniqueRandomIntArray {
public static void main(String[] args) {
new Random().ints(0, 101).distinct() // generate a stream of random
// integers
.limit(20) // we only need 20 random numbers
.sorted().forEach((int i) -> System.out.print(" | " + i));
System.out.println(" | ");
}
} // class ends
代码示例来源:origin: numenta/htm.java
/**
* Converts a Collection of {@link Cell}s to {@link Column} indexes.
*
* @param cells the list of cells to convert
*
* @return sorted array of column indices.
*/
public static int[] asColumnList(Collection<Cell> cells) {
return cells.stream().mapToInt(c -> c.getColumn().getIndex()).sorted().distinct().toArray();
}
代码示例来源:origin: locationtech/geogig
protected @Override List<PR> _call() {
IntStream ids = configDatabase().getAllSubsections("pr").stream()
.mapToInt(s -> Integer.valueOf(s)).sorted();
Stream<PR> prstream = ids.parallel()
.mapToObj(prId -> command(PRFindOp.class).setId(prId).call().orElse(null))
.filter(r -> r != null);
List<PR> prs = prstream.collect(Collectors.toList());
return prs;
}
代码示例来源:origin: BruceEckel/OnJava8-Examples
public static void main(String[] args) {
new Random(47)
.ints(5, 20)
.distinct()
.limit(7)
.sorted()
.forEach(System.out::println);
}
}
内容来源于网络,如有侵权,请联系作者删除!