當前位置: 首頁>>代碼示例>>Java>>正文


Java Stream.builder方法代碼示例

本文整理匯總了Java中java.util.stream.Stream.builder方法的典型用法代碼示例。如果您正苦於以下問題:Java Stream.builder方法的具體用法?Java Stream.builder怎麽用?Java Stream.builder使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.util.stream.Stream的用法示例。


在下文中一共展示了Stream.builder方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: checkModelConstraints

import java.util.stream.Stream; //導入方法依賴的package包/類
private Function<Triple, Stream<ConstraintViolation>> checkModelConstraints(final IRI model, final String domain) {
    requireNonNull(model, "The interaction model must not be null!");

    return triple -> {
        final Stream.Builder<ConstraintViolation> builder = Stream.builder();
        of(triple).filter(propertyFilter(model)).map(t -> new ConstraintViolation(Trellis.InvalidProperty, t))
            .ifPresent(builder::accept);

        of(triple).filter(typeFilter).map(t -> new ConstraintViolation(Trellis.InvalidType, t))
            .ifPresent(builder::accept);

        of(triple).filter(uriRangeFilter).map(t -> new ConstraintViolation(Trellis.InvalidRange, t))
            .ifPresent(builder::accept);

        of(triple).filter(inDomainRangeFilter(domain)).map(t -> new ConstraintViolation(Trellis.InvalidRange, t))
            .ifPresent(builder::accept);

        return builder.build();
    };
}
 
開發者ID:trellis-ldp,項目名稱:trellis,代碼行數:21,代碼來源:LdpConstraints.java

示例2: metricData

import java.util.stream.Stream; //導入方法依賴的package包/類
private Stream<MetricDatum> metricData(DistributionSummary summary) {
    final long wallTime = clock.wallTime();
    final HistogramSnapshot snapshot = summary.takeSnapshot(false);
    final Stream.Builder<MetricDatum> metrics = Stream.builder();

    metrics.add(metricDatum(idWithSuffix(summary.getId(), "sum"), wallTime, snapshot.total()));
    metrics.add(metricDatum(idWithSuffix(summary.getId(), "count"), wallTime, snapshot.count()));
    metrics.add(metricDatum(idWithSuffix(summary.getId(), "avg"), wallTime, snapshot.mean()));
    metrics.add(metricDatum(idWithSuffix(summary.getId(), "max"), wallTime, snapshot.max()));

    for (ValueAtPercentile v : snapshot.percentileValues()) {
        metrics.add(metricDatum(idWithSuffix(summary.getId(), percentileFormat.format(v.percentile()) + "percentile"),
                wallTime, v.value()));
    }

    return metrics.build();
}
 
開發者ID:micrometer-metrics,項目名稱:micrometer,代碼行數:18,代碼來源:CloudWatchMeterRegistry.java

示例3: performTraining

import java.util.stream.Stream; //導入方法依賴的package包/類
@Override
protected KNearestNeighborLearningModel performTraining(IDataset<?, ?, ?> dataset) throws TrainModelsFailedException {
   BaselearnerDataset trainingDataset = (BaselearnerDataset) dataset;
   KDTree<Double> kdTree = new KDTree<>();
   int numberOfPoints = trainingDataset.getNumberOfInstances();

   Stream.Builder<Tuple<DoubleVector, Double>> streamBuilder = Stream.builder();
   for (int i = 0; i < numberOfPoints; i++) {
      BaselearnerInstance currentInstance = trainingDataset.getInstance(i);
      DoubleVector featureVector = new DenseDoubleVector(currentInstance.getContextFeatureVector());
      Double result = currentInstance.getRating();
      streamBuilder.add(new Tuple<DoubleVector, Double>(featureVector, result));
   }
   kdTree.constructWithPayload(streamBuilder.build());
   kdTree.balanceBySort();

   return new KNearestNeighborLearningModel(kdTree, numberOfNeighbors, trainingDataset.getNumberOfFeatures());

}
 
開發者ID:Intelligent-Systems-Group,項目名稱:jpl-framework,代碼行數:20,代碼來源:KNearestNeighborClassification.java

示例4: writeTimer

import java.util.stream.Stream; //導入方法依賴的package包/類
private Stream<String> writeTimer(Timer timer, Map<String, DatadogMetricMetadata> metadata) {
    final long wallTime = clock.wallTime();
    final HistogramSnapshot snapshot = timer.takeSnapshot(false);
    final Stream.Builder<String> metrics = Stream.builder();

    Meter.Id id = timer.getId();
    metrics.add(writeMetric(id, "sum", wallTime, snapshot.total(getBaseTimeUnit())));
    metrics.add(writeMetric(id, "count", wallTime, snapshot.count()));
    metrics.add(writeMetric(id, "avg", wallTime, snapshot.mean(getBaseTimeUnit())));
    metrics.add(writeMetric(id, "max", wallTime, snapshot.max(getBaseTimeUnit())));

    addToMetadataList(metadata, id, "sum", Statistic.TotalTime, null);
    addToMetadataList(metadata, id, "count", Statistic.Count, "occurrence");
    addToMetadataList(metadata, id, "avg", Statistic.Value, null);
    addToMetadataList(metadata, id, "max", Statistic.Max, null);

    for (ValueAtPercentile v : snapshot.percentileValues()) {
        String suffix = DoubleFormat.toString(v.percentile() * 100) + "percentile";
        metrics.add(writeMetric(id, suffix, wallTime, v.value(getBaseTimeUnit())));

        addToMetadataList(metadata, id, suffix, Statistic.Value, null);
    }

    return metrics.build();
}
 
開發者ID:micrometer-metrics,項目名稱:micrometer,代碼行數:26,代碼來源:DatadogMeterRegistry.java

示例5: writeSummary

import java.util.stream.Stream; //導入方法依賴的package包/類
private Stream<String> writeSummary(DistributionSummary summary, Map<String, DatadogMetricMetadata> metadata) {
    final long wallTime = clock.wallTime();
    final HistogramSnapshot snapshot = summary.takeSnapshot(false);
    final Stream.Builder<String> metrics = Stream.builder();

    Meter.Id id = summary.getId();
    metrics.add(writeMetric(id, "sum", wallTime, snapshot.total()));
    metrics.add(writeMetric(id, "count", wallTime, snapshot.count()));
    metrics.add(writeMetric(id, "avg", wallTime, snapshot.mean()));
    metrics.add(writeMetric(id, "max", wallTime, snapshot.max()));

    addToMetadataList(metadata, id, "sum", Statistic.Total, null);
    addToMetadataList(metadata, id, "count", Statistic.Count, "occurrence");
    addToMetadataList(metadata, id, "avg", Statistic.Value, null);
    addToMetadataList(metadata, id, "max", Statistic.Max, null);

    for (ValueAtPercentile v : snapshot.percentileValues()) {
        String suffix = DoubleFormat.toString(v.percentile() * 100) + "percentile";
        metrics.add(writeMetric(id, suffix, wallTime, v.value()));

        addToMetadataList(metadata, id, suffix, Statistic.Value, null);
    }

    return metrics.build();
}
 
開發者ID:micrometer-metrics,項目名稱:micrometer,代碼行數:26,代碼來源:DatadogMeterRegistry.java

示例6: groupAndItsParentsStream

import java.util.stream.Stream; //導入方法依賴的package包/類
/**
 * Returns stream of the given group and its parents (recursively).
 * @param group
 * @return
 */
private Stream<GroupModel> groupAndItsParentsStream(GroupModel group) {
    Stream.Builder<GroupModel> sb = Stream.builder();
    while (group != null) {
        sb.add(group);
        group = group.getParent();
    }
    return sb.build();
}
 
開發者ID:Doccrazy,項目名稱:keycloak-protocol-cas,代碼行數:14,代碼來源:AbstractUserRoleMappingMapper.java

示例7: asPairs

import java.util.stream.Stream; //導入方法依賴的package包/類
public static Stream<Pair<String,String>> asPairs(JsonElement element) {
    Stream.Builder<Pair<String, String>> builder = Stream.builder();
    for (Map.Entry<String, JsonElement> entry : element.getAsJsonObject().entrySet()) {
        builder.add(Pair.of(entry.getKey(), entry.getValue().getAsString()));
    }
    return builder.build();
}
 
開發者ID:McJty,項目名稱:InControl,代碼行數:8,代碼來源:JSonTools.java

示例8: asArrayOrSingle

import java.util.stream.Stream; //導入方法依賴的package包/類
public static Stream<JsonElement> asArrayOrSingle(JsonElement element) {
    if (element.isJsonArray()) {
        Stream.Builder<JsonElement> builder = Stream.builder();
        for (JsonElement el : element.getAsJsonArray()) {
            builder.add(el);
        }
        return builder.build();
    } else {
        return Stream.of(element);
    }
}
 
開發者ID:McJty,項目名稱:InControl,代碼行數:12,代碼來源:JSonTools.java

示例9: writeSummary

import java.util.stream.Stream; //導入方法依賴的package包/類
private String writeSummary(DistributionSummary summary) {
    final HistogramSnapshot snapshot = summary.takeSnapshot(false);
    final Stream.Builder<Field> fields = Stream.builder();

    fields.add(new Field("sum", snapshot.total()));
    fields.add(new Field("count", snapshot.count()));
    fields.add(new Field("mean", snapshot.mean()));
    fields.add(new Field("upper", snapshot.max()));

    for (ValueAtPercentile v : snapshot.percentileValues()) {
        fields.add(new Field(format.format(v.percentile()) + "_percentile", v.value()));
    }

    return influxLineProtocol(summary.getId(), "histogram", fields.build(), clock.wallTime());
}
 
開發者ID:micrometer-metrics,項目名稱:micrometer,代碼行數:16,代碼來源:InfluxMeterRegistry.java

示例10: contents

import java.util.stream.Stream; //導入方法依賴的package包/類
public static Stream<ItemStack> contents(Inventory inventory) {
    // Do this without calling getContents(), because it create a temp array
    final Stream.Builder<ItemStack> builder = Stream.builder();
    for(int i = 0; i < inventory.getSize(); i++) {
        final ItemStack item = inventory.getItem(i);
        if(!ItemUtils.isNothing(item)) {
            builder.add(item);
        }
    }
    return builder.build();
}
 
開發者ID:OvercastNetwork,項目名稱:ProjectAres,代碼行數:12,代碼來源:InventoryUtils.java

示例11: match

import java.util.stream.Stream; //導入方法依賴的package包/類
/**
 * Return all locales from the given set that can serve as substitutes
 * for the given locale, from best to worst.
 */
public static Stream<Locale> match(Locale locale, Set<Locale> available) {
    final Stream.Builder<Locale> result = Stream.builder();

    // Exact match
    if(available.contains(locale)) {
        result.add(locale);
    }

    // Locale has a country, we have a matching language with no country
    if(!"".equals(locale.getCountry())) {
        final Locale language = new Locale(locale.getLanguage());
        if(available.contains(language)) {
            result.add(language);
        }
    }

    // Available locales with the same language and some other country
    for(Locale a : available) {
        if(!"".equals(a.getCountry()) &&
           !locale.getCountry().equals(a.getCountry()) &&
           locale.getLanguage().equals(a.getLanguage())) {

            result.add(a);
        }
    }

    // If the language matches the default locale, then it will already be added.
    // Otherwise, add it now.
    if(!locale.getLanguage().equals(DEFAULT_LOCALE.getLanguage())) {
        result.add(DEFAULT_LOCALE);
    }

    return result.build();
}
 
開發者ID:OvercastNetwork,項目名稱:ProjectAres,代碼行數:39,代碼來源:Locales.java

示例12: getAllCauses

import java.util.stream.Stream; //導入方法依賴的package包/類
private Stream<Throwable> getAllCauses(Throwable t) {
    Stream.Builder<Throwable> builder = Stream.builder();
    Set<Throwable> causes = new LinkedHashSet<>(4);
    while (causes.add(t)) {
        builder.accept(t);
    }
    return builder.build();
}
 
開發者ID:papyrusglobal,項目名稱:state-channels,代碼行數:9,代碼來源:Retriable.java

示例13: fixesStream

import java.util.stream.Stream; //導入方法依賴的package包/類
private static Stream<Fixes> fixesStream() {
    Stream.Builder<Fixes> builder = Stream.builder();
    for (final String prefix0 : PREFIXES) {
        for (final String suffix0 : SUFFIXES) {
            for (final String prefix1 : PREFIXES) {
                for (final String suffix1 : SUFFIXES) {
                    builder.accept(new Fixes(prefix0, suffix0,
                                             prefix1, suffix1));
                }
            }
        }
    }
    return builder.build();
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:15,代碼來源:MergeTest.java

示例14: testAfterBuilding

import java.util.stream.Stream; //導入方法依賴的package包/類
@Test(dataProvider = "sizes")
public void testAfterBuilding(int size) {
    Stream.Builder<Integer> sb = Stream.builder();
    IntStream.range(0, size).boxed().forEach(sb);
    sb.build();

    checkISE(() -> sb.accept(1));
    checkISE(() -> sb.add(1));
    checkISE(() -> sb.build());
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:11,代碼來源:StreamBuilderTest.java

示例15: stream

import java.util.stream.Stream; //導入方法依賴的package包/類
public default Stream<T> stream() {
    Stream.Builder<T> builder = Stream.builder();
    for (T element : this.getAll())
        builder.accept(element);
    return builder.build();
}
 
開發者ID:FrostTusk,項目名稱:DRAMA-Compiler,代碼行數:7,代碼來源:Container.java


注:本文中的java.util.stream.Stream.builder方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。