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


Java Unchecked.biConsumer方法代码示例

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


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

示例1: write

import org.jooq.lambda.Unchecked; //导入方法依赖的package包/类
/**
 * Saves a PreferenceData instance in two files for user and item preferences, respectively. The format of the user preferences stream consists on one list per line, starting with the identifier of the user followed by the identifiers of the items related to that. The item preferences stream follows the same format by swapping the roles of users and items.
 *
 * @param prefData preferences
 * @param uo stream of user preferences
 * @param io stream of user preferences
 */
public void write(FastPreferenceData<?, ?> prefData, OutputStream uo, OutputStream io) {
    BiConsumer<FastPreferenceData<?, ?>, OutputStream> saver = Unchecked.biConsumer((prefs, os) -> {
        try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(os))) {
            prefs.getUidxWithPreferences().forEach(Unchecked.intConsumer(uidx -> {
                String a = prefs.getUidxPreferences(uidx)
                        .mapToInt(IdxPref::v1)
                        .sorted()
                        .mapToObj(Integer::toString)
                        .collect(joining("\t"));

                writer.write(uidx + "\t" + a);
                writer.newLine();
            }));
        }
    });

    saver.accept(prefData, uo);
    saver.accept(new TransposedPreferenceData<>(prefData), io);
}
 
开发者ID:RankSys,项目名称:RankSys,代码行数:27,代码来源:CompressibleBinaryPreferencesFormat.java

示例2: write

import org.jooq.lambda.Unchecked; //导入方法依赖的package包/类
/**
 * Saves a PreferenceData instance in two files for user and item preferences, respectively. The format of the user preferences stream consists on one list per line, starting with the identifier of the user followed by the identifier-rating pairs of the items related to that. The item preferences stream follows the same format by swapping the roles of users and items.
 *
 * @param prefData preferences
 * @param uo stream of user preferences
 * @param io stream of user preferences
 */
public void write(FastPreferenceData<?, ?> prefData, OutputStream uo, OutputStream io) {
    BiConsumer<FastPreferenceData<?, ?>, OutputStream> saver = Unchecked.biConsumer((prefs, os) -> {
        try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(os))) {
            prefs.getUidxWithPreferences().forEach(Unchecked.intConsumer(uidx -> {
                String a = prefs.getUidxPreferences(uidx)
                        .sorted((p1, p2) -> Integer.compare(p1.v1, p2.v1))
                        .map(p -> p.v1 + "\t" + (int) p.v2)
                        .collect(joining("\t"));

                writer.write(uidx + "\t" + a);
                writer.newLine();
            }));
        }
    });

    saver.accept(prefData, uo);
    saver.accept(new TransposedPreferenceData<>(prefData), io);
}
 
开发者ID:RankSys,项目名称:RankSys,代码行数:26,代码来源:CompressibleRatingPreferencesFormat.java

示例3: runMapper

import org.jooq.lambda.Unchecked; //导入方法依赖的package包/类
private static void runMapper(Reader input, List<ValueMapping> map, Writer output, boolean writeHeaders,
		List<String> outputHeaders, List<String> overrideHeaders, int headerLineCount, CsvMapper inputMapper,
		CsvSchema inputSchema) throws ScriptException, IOException {

	final Map<String, String> defaultValues = ValueMapping.getDefaultValuesFromList(map);
	final CsvSchema schema = CSVStream.buildSchema(outputHeaders, writeHeaders);
	final Writer writer = output;

	try (final SequenceWriter csvWriter = CSVStream.newCSVWriter(writer, schema);) {
		final List<String> inputHeaders = new ArrayList<>();
		final List<String> previousLine = new ArrayList<>();
		final List<String> previousMappedLine = new ArrayList<>();
		final JDefaultDict<String, Set<String>> primaryKeys = new JDefaultDict<>(k -> new HashSet<>());
		final JDefaultDict<String, JDefaultDict<String, AtomicInteger>> valueCounts = new JDefaultDict<>(
				k -> new JDefaultDict<>(v -> new AtomicInteger(0)));
		final AtomicInteger lineNumber = new AtomicInteger(0);
		final AtomicInteger filteredLineNumber = new AtomicInteger(0);
		final long startTime = System.currentTimeMillis();
		final BiConsumer<List<String>, List<String>> mapLineConsumer = Unchecked.biConsumer((l, m) -> {
			previousLine.clear();
			previousLine.addAll(l);
			previousMappedLine.clear();
			previousMappedLine.addAll(m);
			csvWriter.write(m);
		});
		CSVStream.parse(input, h -> inputHeaders.addAll(h), (h, l) -> {
			final int nextLineNumber = lineNumber.incrementAndGet();
			if (nextLineNumber % 1000 == 0) {
				double secondsSinceStart = (System.currentTimeMillis() - startTime) / 1000.0d;
				System.out.printf("%d\tSeconds since start: %f\tRecords per second: %f%n", nextLineNumber,
						secondsSinceStart, nextLineNumber / secondsSinceStart);
			}
			final int nextFilteredLineNumber = filteredLineNumber.incrementAndGet();
			try {
				List<String> mapLine = ValueMapping.mapLine(new ValueMappingContext(inputHeaders, l, previousLine,
						previousMappedLine, map, primaryKeys, valueCounts, nextLineNumber, nextFilteredLineNumber,
						mapLineConsumer, outputHeaders, defaultValues, Optional.empty()));
				mapLineConsumer.accept(l, mapLine);
			} catch (final LineFilteredException e) {
				// Swallow line filtered exception and return null below to
				// eliminate it
				// We expect streamCSV to operate in sequential order, print
				// a warning if it doesn't
				boolean success = filteredLineNumber.compareAndSet(nextFilteredLineNumber,
						nextFilteredLineNumber - 1);
				if (!success) {
					System.out.println("Line numbers may not be consistent");
				}
			}
			return null;
		}, l -> {
		}, overrideHeaders, Collections.emptyList(), headerLineCount, inputMapper, inputSchema);
	}
}
 
开发者ID:ansell,项目名称:csvsum,代码行数:55,代码来源:CSVMapper.java

示例4: runMapper

import org.jooq.lambda.Unchecked; //导入方法依赖的package包/类
private static void runMapper(Reader input, List<ValueMapping> map, Writer output, JsonPointer basePath,
		ObjectMapper jsonMapper, boolean writeHeaders) throws ScriptException, IOException {

	final List<String> inputHeaders = ValueMapping.getInputFieldsFromList(map);
	final List<String> outputHeaders = ValueMapping.getOutputFieldsFromList(map);
	final Map<String, String> defaultValues = ValueMapping.getDefaultValuesFromList(map);
	final Map<String, Optional<JsonPointer>> fieldRelativePaths = map.stream()
			.collect(Collectors.toMap(ValueMapping::getOutputField,
					nextMapping -> nextMapping.getInputField().trim().isEmpty() ? Optional.empty()
							: Optional.of(JsonPointer.compile(nextMapping.getInputField()))));
	final CsvSchema schema = CSVStream.buildSchema(outputHeaders, writeHeaders);
	final Writer writer = output;

	try (final SequenceWriter csvWriter = CSVStream.newCSVWriter(writer, schema);) {
		final List<String> previousLine = new ArrayList<>();
		final List<String> previousMappedLine = new ArrayList<>();
		final JDefaultDict<String, Set<String>> primaryKeys = new JDefaultDict<>(k -> new HashSet<>());
		final JDefaultDict<String, JDefaultDict<String, AtomicInteger>> valueCounts = new JDefaultDict<>(
				k -> new JDefaultDict<>(v -> new AtomicInteger(0)));
		final AtomicInteger lineNumber = new AtomicInteger(0);
		final AtomicInteger filteredLineNumber = new AtomicInteger(0);
		final long startTime = System.currentTimeMillis();
		final BiConsumer<List<String>, List<String>> mapLineConsumer = Unchecked.biConsumer((l, m) -> {
			previousLine.clear();
			previousLine.addAll(l);
			previousMappedLine.clear();
			previousMappedLine.addAll(m);
			csvWriter.write(m);
		});
		JSONStream.parse(input, h -> {
		}, (node, headers, line) -> {
			final int nextLineNumber = lineNumber.incrementAndGet();
			if (nextLineNumber % 1000 == 0) {
				double secondsSinceStart = (System.currentTimeMillis() - startTime) / 1000.0d;
				System.out.printf("%d\tSeconds since start: %f\tRecords per second: %f%n", nextLineNumber,
						secondsSinceStart, nextLineNumber / secondsSinceStart);
			}
			final int nextFilteredLineNumber = filteredLineNumber.incrementAndGet();
			try {
				List<String> mapLine = ValueMapping.mapLine(new ValueMappingContext(inputHeaders, line,
						previousLine, previousMappedLine, map, primaryKeys, valueCounts, nextLineNumber,
						nextFilteredLineNumber, mapLineConsumer, outputHeaders, defaultValues, Optional.of(node)));
				mapLineConsumer.accept(line, mapLine);
			} catch (final LineFilteredException e) {
				// Swallow line filtered exception and return null below to
				// eliminate it
				// We expect streamCSV to operate in sequential order, print
				// a warning if it doesn't
				boolean success = filteredLineNumber.compareAndSet(nextFilteredLineNumber,
						nextFilteredLineNumber - 1);
				if (!success) {
					System.out.println("Line numbers may not be consistent");
				}
			}
			return null;
		}, l -> {
		}, basePath, fieldRelativePaths, defaultValues, jsonMapper);
	}
}
 
开发者ID:ansell,项目名称:csvsum,代码行数:60,代码来源:JSONMapper.java

示例5: unchecked

import org.jooq.lambda.Unchecked; //导入方法依赖的package包/类
/**
 * @see {@link Unchecked#biConsumer(CheckedBiConsumer)}
 */
static <T, U> BiConsumer<T, U> unchecked(CheckedBiConsumer<T, U> consumer) {
    return Unchecked.biConsumer(consumer);
}
 
开发者ID:jOOQ,项目名称:jOOL,代码行数:7,代码来源:CheckedBiConsumer.java


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