本文整理匯總了Java中java.util.stream.Stream.toArray方法的典型用法代碼示例。如果您正苦於以下問題:Java Stream.toArray方法的具體用法?Java Stream.toArray怎麽用?Java Stream.toArray使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.util.stream.Stream
的用法示例。
在下文中一共展示了Stream.toArray方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: open
import java.util.stream.Stream; //導入方法依賴的package包/類
@Override
public void open(Serializable prevCheckpointInfo) throws Exception {
JobOperator jobOperator = getJobOperator();
Properties jobParameters = jobOperator.getParameters(jobContext.getExecutionId());
String resourceName = (String) jobParameters.get(INPUT_DATA_FILE_NAME);
InputStream inputStream = new FileInputStream(resourceName);
br = new BufferedReader(new InputStreamReader(inputStream));
Stream<String> lines = br.lines();
if (prevCheckpointInfo != null)
recordNumber = (Integer) prevCheckpointInfo;
else
recordNumber = 0;
stringLines = lines.toArray();
logger.info("[SimpleItemReader] Opened Payroll file for reading from record number: " + recordNumber);
}
開發者ID:PacktPublishing,項目名稱:Mastering-Java-EE-Development-with-WildFly,代碼行數:17,代碼來源:PayrollItemReader.java
示例2: loadFromFile
import java.util.stream.Stream; //導入方法依賴的package包/類
protected static String[] loadFromFile(Console con, File directory, String filename)
{
con.print("Loading '" + filename + "'...");
Path path = new File(directory, filename).toPath();
try
{
Stream<String> lines = Files.lines(path).filter(s -> !s.isEmpty());
String[] result = lines.toArray(String[]::new);
con.println("found " + result.length + " entries!");
return result;
}
catch (IOException e)
{
e.printStackTrace();
}
con.println("cannot find any entries!");
return new String[0];
}
示例3: loadFromFile
import java.util.stream.Stream; //導入方法依賴的package包/類
private static String[] loadFromFile(String filename)
{
System.out.print("Loading '" + filename + "'...");
Path path = new File(DIRECTORY, filename).toPath();
try
{
Stream<String> lines = Files.lines(path);
String[] result = lines.toArray(String[]::new);
System.out.println("found " + result.length + " entries!");
return result;
}
catch (IOException e)
{
e.printStackTrace();
}
System.out.println("cannot find any entries!");
return new String[0];
}
示例4: collectBounds
import java.util.stream.Stream; //導入方法依賴的package包/類
private TypeRef[] collectBounds(InferenceVariable infVar, boolean onlyProper, boolean resolveRawTypes,
Predicate<? super TypeBound> predicate) {
final Set<TypeBound> bounds = resolveRawTypes ? resolveRawTypes(getBounds(infVar)) : getBounds(infVar);
Stream<TypeRef> result = bounds.stream()
.filter(predicate)
.map(b -> b.right);
if (onlyProper) {
result = result.filter(t -> TypeUtils.isProper(t));
}
return result.toArray(TypeRef[]::new);
}
示例5: testCollectionSizeRemove
import java.util.stream.Stream; //導入方法依賴的package包/類
@Test(dataProvider = "collections")
public void testCollectionSizeRemove(String name, Collection<Integer> c) {
assertTrue(c.remove(1));
Stream<Integer> s = c.stream();
assertTrue(c.remove(2));
Object[] result = s.toArray();
assertEquals(result.length, c.size());
}
示例6: runWithSecurityManager
import java.util.stream.Stream; //導入方法依賴的package包/類
private String[] runWithSecurityManager(String[] options) {
Path policyFile = Paths.get(TEST_SRC, "policy");
Stream<String> opts = Stream.concat(Stream.of("-Djava.security.manager",
"-Djava.security.policy=" + policyFile.toString()),
Arrays.stream(options));
return opts.toArray(String[]::new);
}
示例7: mapLinkedResourceURL
import java.util.stream.Stream; //導入方法依賴的package包/類
@Override
public void mapLinkedResourceURL(
JSONObjectBuilder jsonObjectBuilder,
FunctionalList<String> embeddedPathElements, String url) {
String head = embeddedPathElements.head();
Stream<String> tailStream = embeddedPathElements.tailStream();
String[] tail = tailStream.toArray(String[]::new);
jsonObjectBuilder.nestedField(
head, tail
).stringValue(
url
);
Stream<String> middleStream = embeddedPathElements.middleStream();
String[] middle = middleStream.toArray(String[]::new);
Optional<String> optional = embeddedPathElements.lastOptional();
jsonObjectBuilder.ifElseCondition(
optional.isPresent(),
builder -> builder.nestedField(
head, middle
).nestedField(
"@context", optional.get()
),
builder -> builder.nestedField("@context", head)
).field(
"@type"
).stringValue(
"@id"
);
}
示例8: parseNonNull
import java.util.stream.Stream; //導入方法依賴的package包/類
@Override
public Either<String, Pair<X, Y>> parseNonNull(Stream<String> tokens) {
String[] ts = tokens.toArray(String[]::new);
int len = ts == null ? 0 : ts.length;
if (len < 2) {
return left("two tokens expected, found: " + len);
}
return fstTokenParser
.parse(ts[0])
.bind(x -> sndTokenParser.parse(ts[1])
.map(y -> new Pair<>(x, y)));
}
示例9: listToStream
import java.util.stream.Stream; //導入方法依賴的package包/類
@Theory
public void listToStream(Integer[] xs) {
Stream<Integer> actual = asStream(Arrayz.asList(xs));
assertNotNull(actual);
Integer[] extracted = actual.toArray(Integer[]::new);
assertArrayEquals(xs, extracted);
}
示例10: optionalToStreamPutsValueIntoStream
import java.util.stream.Stream; //導入方法依賴的package包/類
@Test
public void optionalToStreamPutsValueIntoStream() {
Stream<Boolean> actual = asStream(Optional.of(true));
assertNotNull(actual);
Boolean[] extracted = actual.toArray(Boolean[]::new);
assertThat(extracted.length, is(1));
assertThat(extracted[0], is(true));
}
示例11: testEntrySetSizeRemove
import java.util.stream.Stream; //導入方法依賴的package包/類
private void testEntrySetSizeRemove(String name, Set<Map.Entry<Integer, Integer>> c) {
Map.Entry<Integer, Integer> first = c.iterator().next();
assertTrue(c.remove(first));
Stream<Map.Entry<Integer, Integer>> s = c.stream();
Map.Entry<Integer, Integer> second = c.iterator().next();
assertTrue(c.remove(second));
Object[] result = s.toArray();
assertEquals(result.length, c.size());
}
示例12: getFieldsUpToJpaOlingoEntity
import java.util.stream.Stream; //導入方法依賴的package包/類
/**
* Extracts fields from the whole hierarchy.
*
* @param firstClass
* first class in the hierarchy
* @return array of extracted fields
*/
public static Field[] getFieldsUpToJpaOlingoEntity(Class<?> firstClass) {
Stream<Field> result = Stream.of(firstClass.getDeclaredFields());
Class<?> superclass = firstClass.getSuperclass();
if (!isLastClass(superclass)) {
result = Stream.concat(result, Stream.of(getFieldsUpToJpaOlingoEntity(superclass)));
}
return result.toArray(Field[]::new);
}
示例13: onFinishEmbeddedOperation
import java.util.stream.Stream; //導入方法依賴的package包/類
@Override
public void onFinishEmbeddedOperation(
JSONObjectBuilder singleModelJSONObjectBuilder,
JSONObjectBuilder operationJSONObjectBuilder,
FunctionalList<String> embeddedPathElements, Operation operation) {
Stream<String> tailStream = embeddedPathElements.tailStream();
String head = embeddedPathElements.head();
String[] tail = tailStream.toArray(String[]::new);
operationJSONObjectBuilder.field(
"@id"
).stringValue(
operation.name
);
operationJSONObjectBuilder.field(
"@type"
).stringValue(
"Operation"
);
singleModelJSONObjectBuilder.nestedField(
head, tail
).field(
"operation"
).arrayValue(
).add(
operationJSONObjectBuilder
);
}
示例14: mapEmbeddedResourceLink
import java.util.stream.Stream; //導入方法依賴的package包/類
@Override
public void mapEmbeddedResourceLink(
JSONObjectBuilder jsonObjectBuilder,
FunctionalList<String> embeddedPathElements, String fieldName,
String url) {
Optional<String> optional = embeddedPathElements.lastOptional();
String head = embeddedPathElements.head();
Stream<String> middleStream = embeddedPathElements.middleStream();
String[] middle = middleStream.toArray(String[]::new);
jsonObjectBuilder.field(
"_embedded"
).ifElseCondition(
optional.isPresent(),
fieldStep -> fieldStep.nestedSuffixedField(
"_embedded", head, middle
).field(
optional.get()
),
fieldStep -> fieldStep.field(head)
).nestedField(
"_links", fieldName, "href"
).stringValue(
url
);
}
示例15: test4
import java.util.stream.Stream; //導入方法依賴的package包/類
/**
* Test (Not really a test) that dumps the list of all Processes.
*/
@Test
public static void test4() {
printf(" Parent Child Info%n");
Stream<ProcessHandle> s = ProcessHandle.allProcesses();
ProcessHandle[] processes = s.toArray(ProcessHandle[]::new);
int len = processes.length;
ProcessHandle[] parent = new ProcessHandle[len];
Set<ProcessHandle> processesSet =
Arrays.stream(processes).collect(Collectors.toSet());
Integer[] sortindex = new Integer[len];
for (int i = 0; i < len; i++) {
sortindex[i] = i;
}
for (int i = 0; i < len; i++) {
parent[sortindex[i]] = processes[sortindex[i]].parent().orElse(null);
}
Arrays.sort(sortindex, (i1, i2) -> {
int cmp = Long.compare((parent[i1] == null ? 0L : parent[i1].pid()),
(parent[i2] == null ? 0L : parent[i2].pid()));
if (cmp == 0) {
cmp = Long.compare((processes[i1] == null ? 0L : processes[i1].pid()),
(processes[i2] == null ? 0L : processes[i2].pid()));
}
return cmp;
});
boolean fail = false;
for (int i = 0; i < len; i++) {
ProcessHandle p = processes[sortindex[i]];
ProcessHandle p_parent = parent[sortindex[i]];
ProcessHandle.Info info = p.info();
String indent = " ";
if (p_parent != null) {
if (!processesSet.contains(p_parent)) {
fail = true;
indent = "*** ";
}
}
printf("%s %7s, %7s, %s%n", indent, p_parent, p, info);
}
Assert.assertFalse(fail, "Parents missing from all Processes");
}