protected final Map<String, Object> getSessionAttributes(MockHttpServletRequest request) { HttpSession session = request.getSession(false); if (session != null) { Enumeration<String> attrNames = session.getAttributeNames(); if (attrNames != null) { return Collections.list(attrNames).stream(). collect(Collectors.toMap(n -> n, session::getAttribute)); } } return Collections.emptyMap(); }
private static Map<String, ClassProperty> createProperty(Class type) { List<String> fieldNames = Arrays.stream(type.getDeclaredFields()) .map(Field::getName).collect(Collectors.toList()); return Stream.of(propertyUtils.getPropertyDescriptors(type)) .filter(property -> !property.getName().equals("class") && property.getReadMethod() != null && property.getWriteMethod() != null) .map(BeanClassProperty::new) //让字段有序 .sorted(Comparator.comparing(property -> fieldNames.indexOf(property.name))) .collect(Collectors.toMap(ClassProperty::getName, Function.identity(), (k, k2) -> k, LinkedHashMap::new)); }
/** * Returns a map of dataSource to the total byte size of segments managed by this segmentManager. This method should * be used carefully because the returned map might be different from the actual data source states. * * @return a map of dataSources and their total byte sizes */ public Map<String, Long> getDataSourceSizes() { return dataSources.entrySet().stream() .collect(Collectors.toMap(Entry::getKey, entry -> entry.getValue().getTotalSegmentSize())); }
/** * Given two maps (A, B), returns all the key-value pairs in A whose keys are not contained in B */ public static <K, V> Map<K, V> subtractMap(Map<? extends K, ? extends V> minuend, Map<? extends K, ? extends V> subtrahend) { return minuend.entrySet().stream() .filter(entry -> !subtrahend.containsKey(entry.getKey())) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); }
protected BoltRequestMessageReader( BoltConnection connection, BoltResponseHandler externalErrorResponseHandler, List<RequestMessageDecoder> decoders ) { this.connection = connection; this.externalErrorResponseHandler = externalErrorResponseHandler; this.decoders = decoders.stream().collect( toMap( RequestMessageDecoder::signature, identity() ) ); }
/** * Creates a map of 'field name' to 'field value' from all {@code public} {@code int} fields * of a class. * @param cls source class * @return unmodifiable name to value map */ public static Map<String, Integer> nameToValueMapFromPublicIntFields(Class<?> cls) { final Map<String, Integer> map = Arrays.stream(cls.getDeclaredFields()) .filter(fld -> Modifier.isPublic(fld.getModifiers()) && fld.getType() == Integer.TYPE) .collect(Collectors.toMap(Field::getName, fld -> getIntFromField(fld, fld.getName()))); return Collections.unmodifiableMap(map); }
/** * Returns a map of dataSource to the number of segments managed by this segmentManager. This method should be * carefully because the returned map might be different from the actual data source states. * * @return a map of dataSources and number of segments */ public Map<String, Long> getDataSourceCounts() { return dataSources.entrySet().stream() .collect(Collectors.toMap(Entry::getKey, entry -> entry.getValue().getNumSegments())); }
AtopTable(String name, String atopLabel, List<AtopColumn> columns) { this.atopLabel = atopLabel; this.name = requireNonNull(name, "name is null"); this.columns = ImmutableList.copyOf(requireNonNull(columns, "columns is null")); columnIndex = this.columns.stream().collect(Collectors.toMap(AtopColumn::getName, Function.identity())); }
@Override public Map<SchemaTableName, List<ColumnMetadata>> listTableColumns(ConnectorSession session, SchemaTablePrefix prefix) { return tables.values().stream() .filter(table -> prefix.matches(table.toSchemaTableName())) .collect(toMap(BlackHoleTableHandle::toSchemaTableName, handle -> handle.toTableMetadata().getColumns())); }
private Mono<Map<String, Object>> initAttributes(ServerWebExchange exchange) { if (this.sessionAttributePredicate == null) { return EMPTY_ATTRIBUTES; } return exchange.getSession().map(session -> session.getAttributes().entrySet().stream() .filter(entry -> this.sessionAttributePredicate.test(entry.getKey())) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))); }
@Override public synchronized Map<SchemaTableName, List<ColumnMetadata>> listTableColumns(ConnectorSession session, SchemaTablePrefix prefix) { return tables.values().stream() .filter(table -> prefix.matches(table.toSchemaTableName())) .collect(toMap(MemoryTableHandle::toSchemaTableName, handle -> handle.toTableMetadata().getColumns())); }
public PollablePartitionsInfo(Set<TopicPartition> pollablePartitions, Map<TopicPartition, Long> earliestRetriableOffsets) { this.pollablePartitions = pollablePartitions; this.pollableEarliestRetriableOffsets = earliestRetriableOffsets.entrySet().stream() .filter(entry -> pollablePartitions.contains(entry.getKey())) .collect(Collectors.toMap(entry -> entry.getKey(), entry -> entry.getValue())); }
@SuppressWarnings("unused") @JsonProperty(FIELD_CHANGED_FIELDS) public Map<String, Object> changedFields() { return Sets.intersection(originalMessage().keySet(), decoratedMessage().keySet()) .stream() .filter(key -> !originalMessage().get(key).equals(decoratedMessage().get(key))) .collect(Collectors.toMap(Function.identity(), key -> originalMessage().get(key))); }