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


Java ImmutableList.forEach方法代码示例

本文整理汇总了Java中com.google.common.collect.ImmutableList.forEach方法的典型用法代码示例。如果您正苦于以下问题:Java ImmutableList.forEach方法的具体用法?Java ImmutableList.forEach怎么用?Java ImmutableList.forEach使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.common.collect.ImmutableList的用法示例。


在下文中一共展示了ImmutableList.forEach方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getVisibleContainerHandles

import com.google.common.collect.ImmutableList; //导入方法依赖的package包/类
/**
 * @param handle
 *            uri for the current project prefixed with {@code FileBasedWorkspace#N4FBPRJ}
 * @return a list of visible projects in form of handles.
 */
@Override
public List<String> getVisibleContainerHandles(String handle) {

	URI containerURI = FileBasedWorkspace.uriFrom(handle);

	List<String> visiContainers = new ArrayList<>();
	// add self
	visiContainers.add(handle);

	Optional<? extends IN4JSProject> project = in4jscore.findProject(containerURI);

	if (!project.isPresent()) {
		throw new IllegalStateException("No project with handle '" + handle + "' known in current In4jscore.");
	}

	ImmutableList<? extends IN4JSProject> dps = n4jsmodel.getDependencies((N4JSProject) project.get());
	// map uri to handle-form and add.
	dps.forEach(d -> visiContainers.add(FileBasedWorkspace.handleFrom(d.getLocation())));

	return visiContainers;
}
 
开发者ID:eclipse,项目名称:n4js,代码行数:27,代码来源:N4FilebasedWorkspaceResourceSetContainerState.java

示例2: accept

import com.google.common.collect.ImmutableList; //导入方法依赖的package包/类
@Override
public void accept(SiteConfig siteConfig, ImmutableList<Document> documents) {
	if (!documents.isEmpty()) {
		System.out.println("-------------------------");
		System.out.println("Documents: ");
		documents.forEach(d -> {
			System.out.println(" - "+d.path());
		});
		System.out.println("-------------------------");
		if (showContent) {
			documents.forEach(d -> {
			if (d.content() instanceof Text) {
				System.out.println(" - "+d.path());
				System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
				System.out.println(((Text) d.content()).text());
				System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
			}
		});
		}

	} else {
		System.out.println("-------------------------");
		System.out.println("No generated Documents.");
		System.out.println("-------------------------");
	}
}
 
开发者ID:flapdoodle-oss,项目名称:de.flapdoodle.solid,代码行数:27,代码来源:DebuggingPageSink.java

示例3: sampleWordpressDump

import com.google.common.collect.ImmutableList; //导入方法依赖的package包/类
@Test
public void sampleWordpressDump() throws IOException, DocumentException {
	try (Reader reader = new InputStreamReader(Resources.asByteSource(Resources.getResource(getClass(), "wordpress-sample-rss.xml")).openBufferedStream())) {
		WordpressRss wordpressRss = WordpressRssConverter.build(XmlParser.of(reader));
		System.out.println("------------------------");
		System.out.println(wordpressRss);
		System.out.println("------------------------");
		ImmutableList<Document> documents = WordpressRss2Solid.convert(wordpressRss);
		documents.forEach(doc -> {
			String docAsString = doc.toString();
			int idx = docAsString.indexOf("---");
			if (idx!=-1) {
				int idxE = docAsString.indexOf("---", idx+3);
				if (idxE!=-1) {
					docAsString=docAsString.substring(0, idxE+3);
				}
			}
			System.out.println(docAsString);
		});
		System.out.println("------------------------");
	}
}
 
开发者ID:flapdoodle-oss,项目名称:de.flapdoodle.solid,代码行数:23,代码来源:WordpressRssConverterTest.java

示例4: onLoaded

import com.google.common.collect.ImmutableList; //导入方法依赖的package包/类
/**
 * Callback for loading Tickets during world load.
 * <p>
 * During this callback you cannot associate chunks to tickets. This
 * callback gets all loaded non-player tickets. The returned list will
 * be truncated to maxTickets after this callback is called, and and
 * tickets absent from the list will be released.
 *
 * @param tickets    The list of loaded tickets
 * @param world      The world tickets were loaded for
 * @param maxTickets The maximum tickets allowed for this plugin
 * @return A list of all tickets you wish to keep
 */
@Override
public List<LoadingTicket> onLoaded(ImmutableList<LoadingTicket> tickets, World world, int maxTickets) {
	List<LoadingTicket> personalTickets = Lists.newArrayList();
	List<LoadingTicket> worldTickets = Lists.newArrayList();
	List<LoadingTicket> toKeep = Lists.newArrayList();

	StickyChunk.getInstance().getLogger().info("sorting tickets");

	if (tickets.size() > maxTickets || unassignedRegions.size() > maxTickets) {
		tickets.forEach(ticket -> ticket.getCompanionData().getString(DataQuery.of("type")).ifPresent(type -> {
			switch (type) {
				case "world":
					worldTickets.add(ticket);
					break;
				case "personal":
					personalTickets.add(ticket);
					break;
				default:
					ticket.release();
					break;
			}

			StickyChunk.getInstance().getLogger().info("sorting ticket");
		}));

		toKeep.addAll(worldTickets);
		toKeep.addAll(personalTickets);

		StickyChunk.getInstance().getLogger().info(String.format("Returning sorted tickets of size: %s", toKeep.size()));

		return toKeep;
	} else {
		StickyChunk.getInstance().getLogger().info(String.format("Returning all tickets of size: %s", tickets.size()));

		return tickets;
	}
}
 
开发者ID:DevOnTheRocks,项目名称:StickyChunk,代码行数:51,代码来源:ChunkLoadCallback.java

示例5: printAllGenerated

import com.google.common.collect.ImmutableList; //导入方法依赖的package包/类
@ParameterizedTest
@MethodSource("inputSourceBlocks")
public void printAllGenerated(List<String> block) throws IOException {

    List<JavaFileObject> sourceJavaFileObject = getResourceStrings("input", block);

    AutoValueProcessor processor = new AutoValueProcessor();

    Compilation compilation = javac().withProcessors(processor).compile(sourceJavaFileObject);

    ImmutableList<JavaFileObject> javaFileObjects = ImmutableList.<JavaFileObject>builder()
            .addAll(compilation.generatedSourceFiles())
            .build();
    String destination = "src/test/resources/expected";
    Files.createDirectories(Paths.get(destination));

    javaFileObjects.forEach(
            generated -> {
                try {
                    String fileName = destination + generated.getName().replace("SOURCE_OUTPUT/", "");
                    Path parent = Paths.get(fileName).getParent();
                    Files.createDirectories(parent);

                    try (PrintWriter printWriter = new PrintWriter(fileName)) {
                        printWriter.println(generated.getCharContent(true).toString());
                    }
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
    );
}
 
开发者ID:sopak,项目名称:auto-value-step-builder,代码行数:33,代码来源:GeneratorTest.java

示例6: implementDeserializeMethod

import com.google.common.collect.ImmutableList; //导入方法依赖的package包/类
@Override
protected MethodSpec implementDeserializeMethod(TypeElement typeElement, Builder deserializeMethodBuilder) {
    Optional<DeserializationConstructs> constructs = loadConstructs(typeElement);
    if (!constructs.isPresent()) {
        return deserializeMethodBuilder.addStatement("return null").build();
    }

    TypeElement enumTypeElement = constructs.get().getEnumTypeElement();
    ImmutableList<Element> enumValueElements = constructs.get().getEnumValueElements();
    ExecutableElement enumValueAccessorMethod = constructs.get().getEnumValueAccessorMethod();
    ExecutableElement enumInstanceAccessorMethod = constructs.get().getEnumInstanceAccessorMethod();

    String memberVariableName = this.processorUtil.createMemberVariableName(enumValueAccessorMethod);

    deserializeMethodBuilder.addStatement("$T codec = $L.getCodec()", ObjectCodec.class, JSON_PARSER_PARAMETER_NAME)
            .addStatement("$T rootNode = codec.readTree($L)", JsonNode.class, JSON_PARSER_PARAMETER_NAME)
            .addStatement("$T typeNode = rootNode.get($S)", JsonNode.class, memberVariableName)
            .beginControlFlow("if (typeNode == null)")
            .addStatement("$T javaType = $L.constructType($T.class)", JavaType.class, DESERIALIZATION_CONTEXT_PARAMETER_NAME, enumTypeElement)
            .addStatement("throw new $T($L, \"$L not present\", javaType, null)", InvalidTypeIdException.class, JSON_PARSER_PARAMETER_NAME, memberVariableName)
            .endControlFlow()
            .addStatement("$T type = codec.treeToValue(typeNode, $T.$L)", enumTypeElement, enumTypeElement, "class")
            .beginControlFlow("switch (type)");

    enumValueElements.forEach(enumValueElement -> deserializeMethodBuilder
            .beginControlFlow("case $L:", enumValueElement)
            .addStatement("return codec.treeToValue(rootNode, $T.$L.$L)", enumTypeElement, enumValueElement, enumInstanceAccessorMethod)
            .endControlFlow());

    return deserializeMethodBuilder.beginControlFlow("default :")
            .addStatement("return null")
            .endControlFlow()
            .endControlFlow()
            .build();
}
 
开发者ID:peckb1,项目名称:autojackson,代码行数:36,代码来源:ComplexDeserializerCreator.java

示例7: testOnlyDescriptorBeanMethodsHaveCopyAnnotationsError

import com.google.common.collect.ImmutableList; //导入方法依赖的package包/类
@Test public void testOnlyDescriptorBeanMethodsHaveCopyAnnotationsError() {
	final ImmutableList<Pair<String,Boolean>> methods = ImmutableList.of(
			Pair.create("abstract void method();", false)
			, Pair.create("void method() { }", false)
			, Pair.create("public void method() { }", false)
			, Pair.create("public static void method() { }", false)
			, Pair.create("public abstract int getInteger();", true)
			, Pair.create("public abstract void setInteger(int value);", true)
			, Pair.create("public abstract IncorrectlyAnnotatedDescriptor setInteger(int value);", true)
			);

	methods.forEach(method -> {
		final JavaFileObject descriptor = forSourceLines("foo.bar.descriptors.IncorrectlyAnnotatedDescriptor"
				, "package foo.bar.descriptors;"
				, "import com.fermio.jct.annotations.Descriptor;"
				, "import com.fermio.jct.annotations.OutputTarget;"
				, "@Descriptor("
				, "  templateClass=foo.bar.templates.ClassTemplate.class,"
				, "  outputClassName=\"Output\""
				, ")"
				, "abstract class IncorrectlyAnnotatedDescriptor {"
				, "  @Descriptor.CopyAnnotationsTo(OutputTarget.BEAN_GETTERS)"
				, method.first()
				, "}"
				);

		final Compilation compilation = compileWithProcessor(minimalClassTemplate(), descriptor);
		if (method.second()) {
			assertThat(compilation).succeededWithoutWarnings();
		} else {
			assertThat(compilation).failed();
			assertThat(compilation).hadErrorCount(1);
			assertThat(compilation).hadErrorContaining(ValidationMessages.ONLY_BEAN_METHODS_COPY_ANNOTATIONS);
		}
	});
}
 
开发者ID:FermioCloud,项目名称:java-code-templates,代码行数:37,代码来源:TestDescriptorValidations.java

示例8: main

import com.google.common.collect.ImmutableList; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException, DocumentException {
	System.out.println("solid wordpress converter");
	Preconditions.checkArgument(args.length>=2,"usage: <rss-xml> <exportDirectory>");
	
	Path rssXml = Paths.get(args[0]);
	Path target = Paths.get(args[1]);
	
	try (Reader reader = new InputStreamReader(Files.newInputStream(rssXml, StandardOpenOption.READ))) {
		WordpressRss wordpressRss = WordpressRssConverter.build(XmlParser.of(reader));
		ImmutableList<Document> documents = WordpressRss2Solid.convert(wordpressRss);
		ImmutableSet<String> allPaths = documents.stream()
			.map(Document::path)
			.collect(ImmutableSet.toImmutableSet());
		Preconditions.checkArgument(allPaths.size()==documents.size(),"path collisions");
		
		// create directory for page and post
		createDirectoryIfNotExist(target.resolve("post"));
		createDirectoryIfNotExist(target.resolve("page"));
		
		documents.forEach((Document d) -> {
			Path filePath = target.resolve(d.path());
			Try.runable(() -> {
				Files.write(filePath, asBytes(d.content()), StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING);
			})
			.mapCheckedException(RuntimeException::new)
			.run();
		});
	}
}
 
开发者ID:flapdoodle-oss,项目名称:de.flapdoodle.solid,代码行数:30,代码来源:WordpressRssConverter.java

示例9: categoryTreeList

import com.google.common.collect.ImmutableList; //导入方法依赖的package包/类
private static PropertyTree categoryTreeList(ImmutableList<WpCategory> categories) {
	Builder builder = FixedPropertyTree.builder();
	
	categories.forEach(c -> {
		Builder entryBuilder = FixedPropertyTree.builder();
		entryBuilder.put("name", c.name());
		childNames(c, categories).forEach(n -> {
			entryBuilder.put("children", n);
		});
		ImmutableFixedPropertyTree entry = entryBuilder.build();
		builder.put(c.urlName(), entry);
	});
	
	return builder.build();
}
 
开发者ID:flapdoodle-oss,项目名称:de.flapdoodle.solid,代码行数:16,代码来源:WordpressRss2Solid.java

示例10: asToml

import com.google.common.collect.ImmutableList; //导入方法依赖的package包/类
private static void asToml(StringBuilder sb, ImmutableList<String> parentKey, int skipIndent, String key, List<Either<Object, ? extends PropertyTree>> values) {
	ImmutableList<String> currentKey = append(parentKey, key);
	
	if (values.size()==1) {
		Either<Object, ? extends PropertyTree> either = values.get(0);
		if (either.isLeft()) {
			Object value = either.left();
			sb.append(indent(parentKey, skipIndent)).append(key).append(" = ").append(valueAsToml(value)).append("\n");
		} else {
			PropertyTree propertyTree = either.right();
			boolean renderTreeKey = !containsOnlyOtherPropertyTrees(propertyTree);
			if (renderTreeKey) {
				sb.append(indent(parentKey, skipIndent)).append("[").append(Joiner.on(".").join(currentKey)).append("]").append("\n");
			}
			asToml(sb, propertyTree, currentKey, renderTreeKey ? skipIndent : skipIndent+1);
		}
	} else {
		ImmutableList<Object> onlyValues = values.stream().filter(Either::isLeft).map(e -> e.left()).collect(ImmutableList.toImmutableList());
		ImmutableList<? extends PropertyTree> onlyTrees = values.stream().filter(e -> !e.isLeft()).map(e -> e.right()).collect(ImmutableList.toImmutableList());
		if (!onlyValues.isEmpty() && onlyTrees.isEmpty()) {
			sb.append(indent(parentKey, skipIndent)).append(key).append(" = ").append("[")
				.append(onlyValues.stream().map(v -> valueAsToml(v)).collect(Collectors.joining(", ")))
				.append("]\n");
		} else {
			if (onlyValues.isEmpty() && !onlyTrees.isEmpty()) {
				onlyTrees.forEach(t -> {
					asToml(sb, t, currentKey, skipIndent);
				});
			} else {
				throw new IllegalArgumentException("not supported: "+key+" = "+values);
			}
		}
	}
}
 
开发者ID:flapdoodle-oss,项目名称:de.flapdoodle.solid,代码行数:35,代码来源:PropertyTreeAsText.java

示例11: accept

import com.google.common.collect.ImmutableList; //导入方法依赖的package包/类
@Override
public void accept(SiteConfig siteConfig, ImmutableList<Document> documents) {
	String baseUrl = siteConfig.baseUrl();
	
	documents.forEach(doc -> Try.consumer((Document d) -> write(baseUrl, d, exportDirectory))
			.mapCheckedException(SomethingWentWrong::new)
			.accept(doc));
}
 
开发者ID:flapdoodle-oss,项目名称:de.flapdoodle.solid,代码行数:9,代码来源:StaticHttpServerPageSink.java

示例12: createSetupClass

import com.google.common.collect.ImmutableList; //导入方法依赖的package包/类
public void createSetupClass(ImmutableList<TypeElement> interfaces) {

        MethodSpec constructor = MethodSpec.constructorBuilder()
                .addModifiers(Modifier.PRIVATE)
                .build();

        MethodSpec.Builder configurationMethodBuilder = MethodSpec.methodBuilder("configureObjectMapper")
                .addModifiers(Modifier.PUBLIC, Modifier.STATIC)
                .addParameter(ParameterSpec.builder(ObjectMapper.class, "objectMapper").build())
                .addStatement("$T deserialzationModule = new $T()", SimpleModule.class, SimpleModule.class);

        interfaces.forEach(element -> {
            String deserializationPackage = ClassName.get(element).packageName();
            ClassName deserializerClassName = ClassName.get(deserializationPackage, element.getSimpleName() + DESERIALIZER_CLASS_NAME_SUFFIX);
            if (element.getTypeParameters().isEmpty()) {
                configurationMethodBuilder.addStatement("deserialzationModule.addDeserializer($T.class, new $T())", element, deserializerClassName);
            } else {
                configurationMethodBuilder.addStatement("deserialzationModule.addDeserializer($L.class, new $T())", element.getQualifiedName(), deserializerClassName);
            }
        });

        configurationMethodBuilder
                .addStatement("objectMapper.registerModule(deserialzationModule)")
                .addStatement("objectMapper.setVisibility($T.$L, $T.$L)", PropertyAccessor.class, ALL, Visibility.class, NONE)
                .addStatement("objectMapper.configure($T.$L, $L)", DeserializationFeature.class, FAIL_ON_UNKNOWN_PROPERTIES, false)
                .build();

        TypeSpec setupClass = TypeSpec
                .classBuilder("AutoJacksonSetup")
                .addModifiers(Modifier.PUBLIC, Modifier.FINAL)
                .addMethod(constructor)
                .addMethod(configurationMethodBuilder.build())
                .build();

        JavaFile javaFile = JavaFile
                .builder("peckb1.autojackson", setupClass)
                .build();

        try {
            javaFile.writeTo(this.filer);
        } catch (IOException e) {
            this.processorUtil.error(null, e.getMessage());
        }
    }
 
开发者ID:peckb1,项目名称:autojackson,代码行数:45,代码来源:SetupCreator.java

示例13: testUninitializableTemplateForeachFieldsError

import com.google.common.collect.ImmutableList; //导入方法依赖的package包/类
@Test public void testUninitializableTemplateForeachFieldsError() {
	final ImmutableList<Pair<String,Boolean>> testsWithoutInitializer = ImmutableList.of(
			// No initializer - type does not matter
			Pair.create("int value;", true)
			, Pair.create("Object value;", true)
			, Pair.create("TestTemplate value;", true)
			, Pair.create("DescriptorTarget value;", true)
			, Pair.create("AutoCloseable value;", true)
			, Pair.create("Integer value;", true)
			, Pair.create("Boolean value;", true) 
			, Pair.create("Double value;", true)
			, Pair.create("Character value;", true)
			, Pair.create("Byte value;", true)
			);

	// Test variations of modifiers in cases with an initializer
	final ImmutableList<String> modifiers = ImmutableList.of("", "final ", "static ", "static final ", "final static ");

	final ImmutableList<Pair<String,Boolean>> testsWithInitializer = ImmutableList.of(

			// With initializer, type matters

			// Primitives
			Pair.create("int value = 0;", true)
			, Pair.create("long value = 0;", true)
			, Pair.create("short value = 0;", true)
			, Pair.create("boolean value = false;", true)
			, Pair.create("byte value = 0;", true)
			, Pair.create("char value = 'a';", true)
			, Pair.create("double value = 0;", true)
			, Pair.create("float value = 0;", true)
			, Pair.create("Class<?> value = null;", true)
			, Pair.create("Class<? extends AutoCloseable> value = null;", true)
			, Pair.create("String value = null;", true)

			// boxed primitives not (currently) supported
			, Pair.create("Integer value = null;", false)
			, Pair.create("Boolean value = null;", false) 
			, Pair.create("Double value = null;", false)
			, Pair.create("Character value = null;", false)
			, Pair.create("Byte value = null;", false)

			// Arbitrary objects not supported
			, Pair.create("Object value = null;", false)
			, Pair.create("TestTemplate value = null;", false)
			, Pair.create("DescriptorTarget value = null;", false)
			, Pair.create("AutoCloseable value = null;", false)
			);

	// Don't vary modifiers on tests w/o initializer
	testsWithoutInitializer.forEach(field ->
		assertOutcome(
				compileWithProcessor(templateWithField(field.first())),
				field.second(),
				ValidationMessages.TEMPLATE_INITIALIZED_FOREACH_FIELDS));

	// Vary modifiers on tests with initializer
	testsWithInitializer.forEach(field ->
		modifiers.forEach(modifier ->
			assertOutcome(
					compileWithProcessor(templateWithField(modifier + field.first())),
					field.second(),
					ValidationMessages.TEMPLATE_INITIALIZED_FOREACH_FIELDS)));
}
 
开发者ID:FermioCloud,项目名称:java-code-templates,代码行数:65,代码来源:TestTemplateValidations.java


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