当前位置: 首页>>代码示例>>Java>>正文


Java Set.stream方法代码示例

本文整理汇总了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
	);
}
 
开发者ID:liferay,项目名称:com-liferay-apio-architect,代码行数:31,代码来源:FieldsWriter.java

示例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()
	);
}
 
开发者ID:liferay,项目名称:com-liferay-apio-architect,代码行数:17,代码来源:CollectionRouterManagerImpl.java

示例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();
	
}
 
开发者ID:PacktPublishing,项目名称:Spring-5.0-Cookbook,代码行数:13,代码来源:EmployeeStreamService.java

示例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();
    }
}
 
开发者ID:vmantek,项目名称:chimera,代码行数:54,代码来源:Q2DeploymentsHealthIndicator.java

示例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;
}
 
开发者ID:liferay,项目名称:com-liferay-apio-architect,代码行数:55,代码来源:IsJsonObject.java

示例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);
	};
}
 
开发者ID:liferay,项目名称:com-liferay-apio-architect,代码行数:49,代码来源:FieldsProvider.java

示例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();
}
 
开发者ID:pchudzik,项目名称:springmock,代码行数:6,代码来源:AnnotatedElementsScanner.java

示例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));
}
 
开发者ID:liferay,项目名称:com-liferay-apio-architect,代码行数:10,代码来源:FormUtil.java


注:本文中的java.util.Set.stream方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。