Here are the examples of the java api lib.AsyncBufferedFileWriter taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
4 Examples
14
View Complete Implementation : UseCSVPathOutput.java
Copyright Apache License 2.0
Author : knewjade
Copyright Apache License 2.0
Author : knewjade
@Override
public void output(PathPairs pathPairs, Field field, SizedBit sizedBit) throws FinderExecuteException {
List<PathPair> pathPairList = pathPairs.getUniquePathPairList();
outputLog("Found path = " + pathPairList.size());
AtomicInteger allCounter = new AtomicInteger();
Map<PieceCounter, List<PathPair>> groupingByClockCounter = pathPairList.parallelStream().collect(Collectors.groupingBy(pathPair -> {
List<MinoOperationWithKey> operations = pathPair.getSampleOperations();
return new PieceCounter(operations.stream().map(OperationWithKey::getPiece));
}));
List<PathPair> emptyValidList = Collections.emptyList();
try (AsyncBufferedFileWriter writer = outputBaseFile.newAsyncWriter()) {
writer.writeAndNewLine("使用ミノ,対応地形数,対応ツモ数 (対パターン),テト譜,ツモ (対パターン)");
generator.blockCountersStream().parallel().map(blockCounter -> {
// カウンターをインクリメント
allCounter.incrementAndGet();
// 組み合わせ名を取得
String blockCounterName = blockCounter.getBlockStream().map(Piece::getName).collect(Collectors.joining());
// パフェ可能な地形を抽出
List<PathPair> valid = groupingByClockCounter.getOrDefault(blockCounter, emptyValidList);
// パフェ可能な地形数
int possibleSize = valid.size();
// パフェ可能な地形のテト譜を連結
String fumens = valid.stream().sorted(Comparator.comparing(PathPair::getPatternSize).reversed()).map(pathPair -> "v115@" + pathPair.getFumen()).collect(Collectors.joining(";"));
// 対応できるパターンを重複なく抽出
Set<LongPieces> possiblePatternSet = valid.stream().flatMap(PathPair::blocksStreamForPattern).collect(Collectors.toSet());
// 対応できるパターン数
int possiblePatternSize = possiblePatternSet.size();
// パターンを連結
String patterns = possiblePatternSet.stream().map(LongPieces::getPieces).map(blocks -> blocks.stream().map(Piece::getName).collect(Collectors.joining(""))).collect(Collectors.joining(";"));
return String.format("%s,%d,%d,%s,%s", blockCounterName, possibleSize, possiblePatternSize, fumens, patterns);
}).forEach(writer::writeAndNewLine);
writer.flush();
} catch (IOException e) {
throw new FinderExecuteException("Failed to output file", e);
}
outputLog("Found piece combinations = " + allCounter.get());
}
13
View Complete Implementation : CSVSetupOutput.java
Copyright Apache License 2.0
Author : knewjade
Copyright Apache License 2.0
Author : knewjade
@Override
public void output(SetupResults setupResults, Field initField, SizedBit sizedBit) throws FinderExecuteException {
Map<BlockField, List<SetupResult>> resultMap = setupResults.getResultMap();
int maxHeight = sizedBit.getHeight();
BiFunction<List<MinoOperationWithKey>, Field, String> naming = setupFunctions.getNaming();
Comparator<Pair<Long, ?>> comparator = Comparator.comparingLong(Pair::getKey);
try (AsyncBufferedFileWriter writer = outputSetupFile.newAsyncWriter()) {
writer.writeAndNewLine("テト譜,使用ミノ,手順数");
for (List<SetupResult> results : resultMap.values()) {
results.stream().map(setupResult -> {
List<MinoOperationWithKey> operationWithKeys = setupResult.getSolution();
BuildUpStream buildUpStream = buildUpStreamThreadLocal.get();
long counter = buildUpStream.existsValidBuildPattern(initField, operationWithKeys).count();
return new Pair<>(counter, setupResult);
}).sorted(comparator.reversed()).forEach(pair -> {
Long counter = pair.getKey();
SetupResult setupResult = pair.getValue();
// 操作に変換
List<MinoOperationWithKey> operationWithKeys = setupResult.getSolution();
// パターンを表す名前 を生成
String blocksName = operationWithKeys.stream().map(OperationWithKey::getPiece).map(Piece::getName).collect(Collectors.joining());
// 譜面の作成
String encode = fumenParser.parse(operationWithKeys, initField, maxHeight);
// 名前の作成
String name = naming.apply(operationWithKeys, setupResult.getRawField());
String line = String.format("http://fumen.zui.jp/?v115@%s,%s,%d", encode, name, counter);
writer.writeAndNewLine(line);
});
}
writer.flush();
} catch (IOException e) {
throw new FinderExecuteException("Failed to output file", e);
}
}
8
View Complete Implementation : FumenCSVPathOutput.java
Copyright Apache License 2.0
Author : knewjade
Copyright Apache License 2.0
Author : knewjade
@Override
public void output(PathPairs pathPairs, Field field, SizedBit sizedBit) throws FinderExecuteException {
List<PathPair> pathPairList = pathPairs.getUniquePathPairList();
outputLog("Found path = " + pathPairList.size());
try (AsyncBufferedFileWriter writer = outputBaseFile.newAsyncWriter()) {
writer.writeAndNewLine("テト譜,使用ミノ,対応ツモ数 (対地形&パターン),対応ツモ数 (対地形),対応ツモ数 (対パターン),ツモ (対地形&パターン),ツモ (対地形),ツモ (対パターン)");
pathPairList.parallelStream().map(pathPair -> {
// テト譜
String encode = pathPair.getFumen();
// パターンに対する有効なミノ順をまとめる
List<LongPieces> patternBuildBlocks = pathPair.blocksStreamForPattern().collect(Collectors.toList());
// 対応ツモ数 (対パターン)
int pattern = patternBuildBlocks.size();
// 使用ミノをまとめる
String usingPieces = pathPair.getUsingBlockName();
// 地形に対する有効なミノ順 && パターンに対して有効なミノ順をまとめる
AtomicInteger counterValidSolutions = new AtomicInteger();
String validOrdersValidSolution = pathPair.blocksStreamForValidSolution().peek(it -> counterValidSolutions.incrementAndGet()).map(longBlocks -> longBlocks.blockStream().map(Piece::getName).collect(Collectors.joining())).collect(Collectors.joining(";"));
// 地形に対する有効なミノ順をまとめる
HashSet<LongPieces> solutionBuildBlocks = pathPair.blocksHashSetForSolution();
String validOrdersSolution = solutionBuildBlocks.stream().map(longBlocks -> longBlocks.blockStream().map(Piece::getName).collect(Collectors.joining())).collect(Collectors.joining(";"));
// パターンに対する有効なミノ順をまとめる
String validOrdersPattern = patternBuildBlocks.stream().map(longBlocks -> longBlocks.blockStream().map(Piece::getName).collect(Collectors.joining())).collect(Collectors.joining(";"));
// 対応ツモ数 (対地形)
int solution = solutionBuildBlocks.size();
return String.format("http://fumen.zui.jp/?v115@%s,%s,%d,%d,%d,%s,%s,%s", encode, usingPieces, counterValidSolutions.get(), solution, pattern, validOrdersValidSolution, validOrdersSolution, validOrdersPattern);
}).forEach(writer::writeAndNewLine);
writer.flush();
} catch (IOException e) {
throw new FinderExecuteException("Failed to output file", e);
}
}
6
View Complete Implementation : PatternCSVPathOutput.java
Copyright Apache License 2.0
Author : knewjade
Copyright Apache License 2.0
Author : knewjade
@Override
public void output(PathPairs pathPairs, Field field, SizedBit sizedBit) throws FinderExecuteException {
List<PathPair> pathPairList = pathPairs.getUniquePathPairList();
outputLog("Found path = " + pathPairList.size());
AtomicInteger validCounter = new AtomicInteger();
AtomicInteger allCounter = new AtomicInteger();
try (AsyncBufferedFileWriter writer = outputBaseFile.newAsyncWriter()) {
writer.writeAndNewLine("ツモ,対応地形数,使用ミノ,未使用ミノ,テト譜");
generator.blocksStream().parallel().map(blocks -> {
// シーケンス名を取得
String sequenceName = blocks.blockStream().map(Piece::getName).collect(Collectors.joining());
// パフェ可能な地形を抽出
List<PathPair> valid = pathPairList.stream().filter(pathPair -> {
HashSet<? extends Pieces> buildBlocks = pathPair.blocksHashSetForPattern();
return buildBlocks.contains(blocks);
}).collect(Collectors.toList());
// パフェ可能な地形数
int possibleSize = valid.size();
// パフェ可能ならカウンターをインクリメント
allCounter.incrementAndGet();
if (0 < possibleSize)
validCounter.incrementAndGet();
// パフェ可能な地形のテト譜を連結
String fumens = valid.stream().sorted(Comparator.comparing(PathPair::getPatternSize).reversed()).map(pathPair -> "v115@" + pathPair.getFumen()).collect(Collectors.joining(";"));
// 使うミノ一覧を抽出
Set<PieceCounter> usesSet = valid.stream().map(PathPair::getBlockCounter).collect(Collectors.toSet());
String uses = usesSet.stream().map(blockCounter -> {
return blockCounter.getBlockStream().sorted().map(Piece::getName).collect(Collectors.joining());
}).collect(Collectors.joining(";"));
// 残せるミノ一覧を抽出
PieceCounter orderPieceCounter = new PieceCounter(blocks.blockStream());
String noUses = usesSet.stream().map(orderPieceCounter::removeAndReturnNew).distinct().map(blockCounter -> {
return blockCounter.getBlockStream().sorted().map(Piece::getName).collect(Collectors.joining());
}).collect(Collectors.joining(";"));
return String.format("%s,%d,%s,%s,%s", sequenceName, possibleSize, uses, noUses, fumens);
}).forEach(writer::writeAndNewLine);
writer.flush();
} catch (IOException e) {
throw new FinderExecuteException("Failed to output file", e);
}
outputLog("");
outputLog("perfect clear percent");
outputLog(String.format(" -> success = %.2f%% (%d/%d)", 100.0 * validCounter.get() / allCounter.get(), validCounter.get(), allCounter.get()));
}