Tabnine Logo
Collectors
Code IndexAdd Tabnine to your IDE (free)

How to use
Collectors
in
java.util.stream

Best Java code snippets using java.util.stream.Collectors (Showing top 20 results out of 89,442)

Refine searchRefine arrow

  • Stream
  • Optional
  • ImmutableList
  • ImmutableMap
  • TupleDomain
canonical example by Tabnine

private Double calculateAverageGrade(Map<String, List<Integer>> gradesList, String studentName)
  throws Exception {
 return Optional.ofNullable(gradesList.get(studentName))
   .map(list -> list.stream().collect(Collectors.averagingDouble(x -> x)))
   .orElseThrow(() -> new Exception("Student not found - " + studentName));
}
canonical example by Tabnine

public List<Integer> findDivisors(int number) {
 return Stream.iterate(1, k -> ++k)
   .limit(number)
   .filter(k -> number % k == 0)
   .collect(Collectors.toList());
}
canonical example by Tabnine

public void printFibonacciSequence(int length) {
 System.out.println(
   Stream.iterate(new long[] {0, 1}, pair -> new long[] {pair[1], pair[0] + pair[1]})
     .limit(length)
     .map(pair -> Long.toString(pair[1]))
     .collect(Collectors.joining(", ")));
}
origin: prestodb/presto

@Override
public synchronized Optional<List<String>> getAllTables(String databaseName)
{
  requireNonNull(databaseName, "databaseName is null");
  Optional<Database> database = getDatabase(databaseName);
  if (!database.isPresent()) {
    return Optional.empty();
  }
  Path databaseMetadataDirectory = getDatabaseMetadataDirectory(databaseName);
  List<String> tables = getChildSchemaDirectories(databaseMetadataDirectory).stream()
      .map(Path::getName)
      .collect(toList());
  return Optional.of(ImmutableList.copyOf(tables));
}
origin: prestodb/presto

private static Optional<Domain> getDomain(OptionalInt timestampOrdinalPosition, TupleDomain<LocalFileColumnHandle> predicate)
{
  Optional<Map<LocalFileColumnHandle, Domain>> domains = predicate.getDomains();
  Domain domain = null;
  if (domains.isPresent() && timestampOrdinalPosition.isPresent()) {
    Map<LocalFileColumnHandle, Domain> domainMap = domains.get();
    Set<Domain> timestampDomain = domainMap.entrySet().stream()
        .filter(entry -> entry.getKey().getOrdinalPosition() == timestampOrdinalPosition.getAsInt())
        .map(Map.Entry::getValue)
        .collect(toSet());
    if (!timestampDomain.isEmpty()) {
      domain = Iterables.getOnlyElement(timestampDomain);
    }
  }
  return Optional.ofNullable(domain);
}
origin: spring-projects/spring-framework

private String formatHeaders(HttpHeaders headers, String delimiter) {
  return headers.entrySet().stream()
      .map(entry -> entry.getKey() + ": " + entry.getValue())
      .collect(Collectors.joining(delimiter));
}
origin: spring-projects/spring-framework

  private static List<PathPattern> parse(String[] paths, PathPatternParser parser) {
    return Arrays
        .stream(paths)
        .map(path -> {
          if (StringUtils.hasText(path) && !path.startsWith("/")) {
            path = "/" + path;
          }
          return parser.parse(path);
        })
        .collect(Collectors.toList());
  }
}
origin: prestodb/presto

List<HivePartition> partitions = hiveLayoutHandle.getPartitions().get();
Optional<DiscretePredicates> discretePredicates = Optional.empty();
if (!partitionColumns.isEmpty()) {
  Iterable<TupleDomain<ColumnHandle>> partitionDomains = Iterables.transform(partitions, (hivePartition) -> TupleDomain.fromFixedValues(hivePartition.getKeys()));
  discretePredicates = Optional.of(new DiscretePredicates(partitionColumns, partitionDomains));
          hiveBucketHandle.getReadBucketCount(),
          hiveBucketHandle.getColumns().stream()
              .map(HiveColumnHandle::getHiveType)
              .collect(Collectors.toList()),
          OptionalInt.empty()),
      hiveBucketHandle.getColumns().stream()
          .map(ColumnHandle.class::cast)
          .collect(toList())));
    Optional.empty(),
    discretePredicates,
    ImmutableList.of());
origin: prestodb/presto

    .filter(TestColumn::isPartitionKey)
    .map(input -> new HivePartitionKey(input.getName(), (String) input.getWriteValue()))
    .collect(toList());
    split.getLength(),
    splitProperties,
    TupleDomain.all(),
    getColumnHandles(testColumns),
    partitionKeys,
    DateTimeZone.getDefault(),
    TYPE_MANAGER,
    ImmutableMap.of(),
    Optional.empty(),
    false);
RecordCursor cursor = ((RecordPageSource) pageSource.get()).getCursor();
origin: prestodb/presto

@Override
public ActualProperties visitTableScan(TableScanNode node, List<ActualProperties> inputProperties)
{
  checkArgument(node.getLayout().isPresent(), "table layout has not yet been chosen");
  TableLayout layout = metadata.getLayout(session, node.getLayout().get());
  Map<ColumnHandle, Symbol> assignments = ImmutableBiMap.copyOf(node.getAssignments()).inverse();
  ActualProperties.Builder properties = ActualProperties.builder();
  // Globally constant assignments
  Map<ColumnHandle, NullableValue> globalConstants = new HashMap<>();
  extractFixedValues(node.getCurrentConstraint()).orElse(ImmutableMap.of())
      .entrySet().stream()
      .filter(entry -> !entry.getValue().isNull())
      .forEach(entry -> globalConstants.put(entry.getKey(), entry.getValue()));
  Map<Symbol, NullableValue> symbolConstants = globalConstants.entrySet().stream()
      .filter(entry -> assignments.containsKey(entry.getKey()))
      .collect(toMap(entry -> assignments.get(entry.getKey()), Map.Entry::getValue));
  properties.constants(symbolConstants);
  // Partitioning properties
  properties.global(deriveGlobalProperties(layout, assignments, globalConstants));
  // Append the global constants onto the local properties to maximize their translation potential
  List<LocalProperty<ColumnHandle>> constantAppendedLocalProperties = ImmutableList.<LocalProperty<ColumnHandle>>builder()
      .addAll(globalConstants.keySet().stream().map(ConstantProperty::new).iterator())
      .addAll(layout.getLocalProperties())
      .build();
  properties.local(LocalProperties.translate(constantAppendedLocalProperties, column -> Optional.ofNullable(assignments.get(column))));
  return properties.build();
}
origin: prestodb/presto

/**
 * Get the physical layout for a inserting into an existing table.
 */
default Optional<ConnectorNewTableLayout> getInsertLayout(ConnectorSession session, ConnectorTableHandle tableHandle)
{
  List<ConnectorTableLayout> layouts = getTableLayouts(session, tableHandle, new Constraint<>(TupleDomain.all(), map -> true), Optional.empty())
      .stream()
      .map(ConnectorTableLayoutResult::getTableLayout)
      .filter(layout -> layout.getTablePartitioning().isPresent())
      .collect(toList());
  if (layouts.isEmpty()) {
    return Optional.empty();
  }
  if (layouts.size() > 1) {
    throw new PrestoException(NOT_SUPPORTED, "Tables with multiple layouts can not be written");
  }
  ConnectorTableLayout layout = layouts.get(0);
  ConnectorPartitioningHandle partitioningHandle = layout.getTablePartitioning().get().getPartitioningHandle();
  Map<ColumnHandle, String> columnNamesByHandle = getColumnHandles(session, tableHandle).entrySet().stream()
      .collect(Collectors.toMap(Map.Entry::getValue, Map.Entry::getKey));
  List<String> partitionColumns = layout.getTablePartitioning().get().getPartitioningColumns().stream()
      .map(columnNamesByHandle::get)
      .collect(toList());
  return Optional.of(new ConnectorNewTableLayout(partitioningHandle, partitionColumns));
}
origin: prestodb/presto

  @Override
  public ConnectorSplitSource getSplits(ConnectorTransactionHandle transaction, ConnectorSession session, ConnectorTableLayoutHandle layout, SplitSchedulingStrategy splitSchedulingStrategy)
  {
    JmxTableLayoutHandle jmxLayout = (JmxTableLayoutHandle) layout;
    JmxTableHandle tableHandle = jmxLayout.getTable();
    TupleDomain<ColumnHandle> predicate = jmxLayout.getConstraint();

    //TODO is there a better way to get the node column?
    Optional<JmxColumnHandle> nodeColumnHandle = tableHandle.getColumnHandles().stream()
        .filter(jmxColumnHandle -> jmxColumnHandle.getColumnName().equals(NODE_COLUMN_NAME))
        .findFirst();
    checkState(nodeColumnHandle.isPresent(), "Failed to find %s column", NODE_COLUMN_NAME);

    List<ConnectorSplit> splits = nodeManager.getAllNodes().stream()
        .filter(node -> {
          NullableValue value = NullableValue.of(createUnboundedVarcharType(), utf8Slice(node.getNodeIdentifier()));
          return predicate.overlaps(fromFixedValues(ImmutableMap.of(nodeColumnHandle.get(), value)));
        })
        .map(node -> new JmxSplit(tableHandle, ImmutableList.of(node.getHostAndPort())))
        .collect(toList());

    return new FixedSplitSource(splits);
  }
}
origin: spring-projects/spring-framework

@Override
public Set<Entry<String, List<String>>> entrySet() {
  return Collections.unmodifiableSet(this.headers.entrySet().stream()
      .map(AbstractMap.SimpleImmutableEntry::new)
      .collect(Collectors.toSet()));
}
origin: prestodb/presto

Map<ColumnHandle, NullableValue> fixedValues = TupleDomain.extractFixedValues(tupleDomain).orElse(ImmutableMap.of())
    .entrySet().stream()
    .filter(entry -> !indexableColumns.contains(entry.getKey()))
    .filter(entry -> !entry.getValue().isNull()) // strip nulls since meaningless in index join lookups
    .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
    .addAll(handleToNames(ImmutableList.copyOf(indexableColumns)))
    .addAll(handleToNames(ImmutableList.copyOf(fixedValues.keySet())))
    .build();
if (!indexedData.getIndexedTable(tpchTableHandle.getTableName(), tpchTableHandle.getScaleFactor(), lookupColumnNames).isPresent()) {
  return Optional.empty();
if (!tupleDomain.isNone()) {
  filteredTupleDomain = TupleDomain.withColumnDomains(Maps.filterKeys(tupleDomain.getDomains().get(), not(in(fixedValues.keySet()))));
origin: prestodb/presto

public List<Symbol> getOriginalNonDistinctAggregateArgs()
{
  return aggregations.values().stream()
      .filter(aggregation -> !aggregation.getMask().isPresent())
      .map(Aggregation::getCall)
      .flatMap(function -> function.getArguments().stream())
      .distinct()
      .map(Symbol::from)
      .collect(Collectors.toList());
}
origin: prestodb/presto

public static RowType anonymous(List<Type> types)
{
  List<Field> fields = types.stream()
      .map(type -> new Field(Optional.empty(), type))
      .collect(Collectors.toList());
  return new RowType(makeSignature(fields), fields);
}
origin: prestodb/presto

private static StorageDescriptor makeStorageDescriptor(String tableName, List<Column> columns, Storage storage)
{
  if (storage.isSkewed()) {
    throw new IllegalArgumentException("Writing to skewed table/partition is not supported");
  }
  SerDeInfo serdeInfo = new SerDeInfo();
  serdeInfo.setName(tableName);
  serdeInfo.setSerializationLib(storage.getStorageFormat().getSerDeNullable());
  serdeInfo.setParameters(storage.getSerdeParameters());
  StorageDescriptor sd = new StorageDescriptor();
  sd.setLocation(emptyToNull(storage.getLocation()));
  sd.setCols(columns.stream()
      .map(ThriftMetastoreUtil::toMetastoreApiFieldSchema)
      .collect(toList()));
  sd.setSerdeInfo(serdeInfo);
  sd.setInputFormat(storage.getStorageFormat().getInputFormatNullable());
  sd.setOutputFormat(storage.getStorageFormat().getOutputFormatNullable());
  sd.setParameters(ImmutableMap.of());
  Optional<HiveBucketProperty> bucketProperty = storage.getBucketProperty();
  if (bucketProperty.isPresent()) {
    sd.setNumBuckets(bucketProperty.get().getBucketCount());
    sd.setBucketCols(bucketProperty.get().getBucketedBy());
    if (!bucketProperty.get().getSortedBy().isEmpty()) {
      sd.setSortCols(bucketProperty.get().getSortedBy().stream()
          .map(column -> new Order(column.getColumnName(), column.getOrder().getHiveOrder()))
          .collect(toList()));
    }
  }
  return sd;
}
origin: prestodb/presto

private Map<TpchColumn<?>, List<Object>> getColumnValuesRestrictions(TpchTable<?> tpchTable, Constraint<ColumnHandle> constraint)
{
  TupleDomain<ColumnHandle> constraintSummary = constraint.getSummary();
  if (constraintSummary.isAll()) {
    return emptyMap();
  }
  else if (constraintSummary.isNone()) {
    Set<TpchColumn<?>> columns = ImmutableSet.copyOf(tpchTable.getColumns());
    return asMap(columns, key -> emptyList());
  }
  else {
    Map<ColumnHandle, Domain> domains = constraintSummary.getDomains().get();
    Optional<Domain> orderStatusDomain = Optional.ofNullable(domains.get(toColumnHandle(ORDER_STATUS)));
    Optional<Map<TpchColumn<?>, List<Object>>> allowedColumnValues = orderStatusDomain.map(domain -> {
      List<Object> allowedValues = ORDER_STATUS_VALUES.stream()
          .filter(domain::includesNullableValue)
          .collect(toList());
      return avoidTrivialOrderStatusRestriction(allowedValues);
    });
    return allowedColumnValues.orElse(emptyMap());
  }
}
origin: apache/incubator-dubbo

protected static Set<String> getSubProperties(Map<String, String> properties, String prefix) {
  return properties.keySet().stream().filter(k -> k.contains(prefix)).map(k -> {
    k = k.substring(prefix.length());
    return k.substring(0, k.indexOf("."));
  }).collect(Collectors.toSet());
}
origin: prestodb/presto

/**
 * Extract all column constraints that require exactly one value or only null in their respective Domains.
 * Returns an empty Optional if the Domain is none.
 */
public static <T> Optional<Map<T, NullableValue>> extractFixedValues(TupleDomain<T> tupleDomain)
{
  if (!tupleDomain.getDomains().isPresent()) {
    return Optional.empty();
  }
  return Optional.of(tupleDomain.getDomains().get()
      .entrySet().stream()
      .filter(entry -> entry.getValue().isNullableSingleValue())
      .collect(toMap(Map.Entry::getKey, entry -> new NullableValue(entry.getValue().getType(), entry.getValue().getNullableSingleValue()))));
}
java.util.streamCollectors

Most used methods

  • toList
  • toSet
  • joining
  • toMap
  • groupingBy
  • toCollection
  • collectingAndThen
  • counting
  • mapping
  • partitioningBy
  • reducing
  • toConcurrentMap
  • reducing,
  • toConcurrentMap,
  • maxBy,
  • summingInt,
  • summingLong,
  • groupingByConcurrent,
  • minBy,
  • summingDouble,
  • averagingInt,
  • summarizingLong

Popular in Java

  • Finding current android device location
  • getSupportFragmentManager (FragmentActivity)
  • runOnUiThread (Activity)
  • startActivity (Activity)
  • Font (java.awt)
    The Font class represents fonts, which are used to render text in a visible way. A font provides the
  • Date (java.sql)
    A class which can consume and produce dates in SQL Date format. Dates are represented in SQL as yyyy
  • ExecutorService (java.util.concurrent)
    An Executor that provides methods to manage termination and methods that can produce a Future for tr
  • Executors (java.util.concurrent)
    Factory and utility methods for Executor, ExecutorService, ScheduledExecutorService, ThreadFactory,
  • Response (javax.ws.rs.core)
    Defines the contract between a returned instance and the runtime when an application needs to provid
  • FileUtils (org.apache.commons.io)
    General file manipulation utilities. Facilities are provided in the following areas: * writing to a
  • Top PhpStorm plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now