本文整理汇总了Java中java.util.Set.stream方法的典型用法代码示例。如果您正苦于以下问题:Java Set.stream方法的具体用法?Java Set.stream怎么用?Java Set.stream使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.Set
的用法示例。
在下文中一共展示了Set.stream方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: writeFields
import java.util.Set; //导入方法依赖的package包/类
/**
* Writes a {@code Map<String, S>} returned by a {@link Representor}
* function. This method uses a consumer so each caller can decide what to
* do with each entry. Each member of the map is filtered using the {@link
* Fields} predicate provided by {@link #getFieldsPredicate()}.
*
* @param representorFunction the {@code Representor} function that returns
* the map being written
* @param consumer the consumer used to process each filtered entry
*/
public <U> void writeFields(
Function<Representor<T, S>, Map<String, U>> representorFunction,
Consumer<Entry<String, U>> consumer) {
Map<String, U> map = representorFunction.apply(_representor);
Set<Entry<String, U>> entries = map.entrySet();
Stream<Entry<String, U>> stream = entries.stream();
stream.filter(
entry -> {
Predicate<String> fieldsPredicate = getFieldsPredicate();
return fieldsPredicate.test(entry.getKey());
}
).forEach(
consumer
);
}
示例2: getResourceNames
import java.util.Set; //导入方法依赖的package包/类
@Override
public List<String> getResourceNames() {
Set<String> keys = getServiceTrackerMap().keySet();
Stream<String> stream = keys.stream();
return stream.map(
className -> _nameManager.getNameOptional(className)
).filter(
Optional::isPresent
).map(
Optional::get
).collect(
Collectors.toList()
);
}
示例3: getListData
import java.util.Set; //导入方法依赖的package包/类
public void getListData(){
List<String> employeeIDS =
Arrays.asList("23234", "353453", "22222", "5555", "676767");
Stream<String> streamsIds = employeeIDS.stream();
Set<String> candidates = new HashSet<String>();
candidates.add("Joel");
candidates.add("Candy");
candidates.add("Sherwin");
Stream<String> streamCandidates = candidates.stream();
}
示例4: doHealthCheck
import java.util.Set; //导入方法依赖的package包/类
@Override
protected void doHealthCheck(Builder builder) throws Exception
{
final MBeanServer server = getMBeanServer();
if (server != null)
{
final ObjectName on = new ObjectName("Q2:type=qbean,service=*");
final Set<ObjectName> names = server.queryNames(on, null);
final Stream<ObjectName> s = names.stream();
final long muxInTransitCount = getMuxInTransitCount(server, names);
final long tmInTransitCount = getTmInTransitCount(server, names);
builder.withDetail("mux.in-transit", String.valueOf(muxInTransitCount));
builder.withDetail("tm.in-transit", String.valueOf(tmInTransitCount));
builder.withDetail("in-transit", String.valueOf(Math.max(muxInTransitCount, tmInTransitCount)));
if (s.allMatch(name -> getStatus(server, name) == QBean.STARTED))
{
builder.up();
}
else if (s.anyMatch(name -> getStatus(server, name) == QBean.FAILED))
{
long cnt = s.filter(name -> getStatus(server, name) == QBean.FAILED).count();
Set<String> objs = s.filter(name -> getStatus(server, name) == QBean.FAILED)
.map(ObjectName::getCanonicalName)
.collect(Collectors.toSet());
String failedServices = StringUtils.collectionToCommaDelimitedString(objs);
builder.withDetail("failed-count", String.valueOf(cnt));
builder.withDetail("failed-services", failedServices);
builder.status("failed");
}
else if (s.allMatch(name -> getStatus(server, name) == QBean.DESTROYED))
{
builder.outOfService();
}
else if (s.allMatch(name -> getStatus(server, name) == QBean.STOPPED))
{
builder.down();
}
else
{
builder.unknown();
}
}
else
{
builder.unknown();
}
}
示例5: matchesSafely
import java.util.Set; //导入方法依赖的package包/类
@Override
protected boolean matchesSafely(
JsonObject jsonObject, Description description) {
Map<String, Consumer<Description>> mismatchedKeys = new HashMap<>();
_entryMatchers.forEach(
(key, value) -> {
JsonElement jsonElement = jsonObject.get(key);
if (!value.matches(jsonElement)) {
mismatchedKeys.put(
key,
consumerDescription -> value.describeMismatch(
jsonElement, consumerDescription));
}
});
Set<String> keys = _entryMatchers.keySet();
if (!mismatchedKeys.isEmpty()) {
description.appendText("was a JSON object ");
describeNestedMismatches(
keys, description, mismatchedKeys,
(text, innerDescription) -> innerDescription.appendText(text));
return false;
}
if (_strictMode && (jsonObject.size() > _entryMatchers.size())) {
Set<String> jsonObjectKeys = new HashSet<>(jsonObject.keySet());
jsonObjectKeys.removeAll(keys);
Stream<String> stream = jsonObjectKeys.stream();
String extraKeys = stream.collect(Collectors.joining(", "));
description.appendText(
"was a JSON object "
).appendText(
"with more fields than validated. "
).appendText(
"Extra keys: "
).appendText(
extraKeys
);
return false;
}
return true;
}
示例6: createContext
import java.util.Set; //导入方法依赖的package包/类
public Fields createContext(HttpServletRequest httpServletRequest) {
Map<String, String[]> parameterMap =
httpServletRequest.getParameterMap();
Set<Map.Entry<String, String[]>> set = parameterMap.entrySet();
Stream<Map.Entry<String, String[]>> stream = set.stream();
Map<String, List<String>> fieldsMap = stream.filter(
entry -> {
String key = entry.getKey();
return key.matches(_REGEXP);
}
).filter(
entry -> {
String[] value = entry.getValue();
if (value.length == 1) {
return true;
}
return false;
}
).filter(
entry -> !entry.getValue()[0].isEmpty()
).collect(
Collectors.toMap(
entry -> _getTypeFunction.apply(entry.getKey()),
entry -> Arrays.asList(entry.getValue()[0].split(",")))
);
return types -> field -> {
Stream<String> typesStream = types.stream();
List<String> fields = typesStream.map(
fieldsMap::get
).filter(
Objects::nonNull
).flatMap(
List::stream
).collect(
Collectors.toList()
);
return fields.isEmpty() || fields.contains(field);
};
}
示例7: findAllFields
import java.util.Set; //导入方法依赖的package包/类
private Stream<Field> findAllFields(Class<?> clazz) {
final Set<Field> allFields = new HashSet<>();
doWithFields(clazz, allFields::add);
return allFields.stream();
}
示例8: _getFormFieldStream
import java.util.Set; //导入方法依赖的package包/类
private static Stream<FormField> _getFormFieldStream(
Map<String, ?> map, Boolean required, FieldType fieldType) {
Set<String> keys = map.keySet();
Stream<String> stream = keys.stream();
return stream.map(name -> new FormField(name, required, fieldType));
}