use of java.util.stream.Stream in project android by JetBrains.
the class NlUsageTrackerManager method logRenderResult.
@Override
public void logRenderResult(@Nullable NlModel.ChangeType trigger, @NotNull RenderResult result, long totalRenderTimeMs) {
// Renders are a quite common event so we sample them
if (!shouldLog(LOG_RENDER_PERCENT)) {
return;
}
logStudioEvent(LayoutEditorEvent.LayoutEditorEventType.RENDER, (event) -> {
LayoutEditorRenderResult.Builder builder = LayoutEditorRenderResult.newBuilder().setResultCode(result.getRenderResult().getStatus().ordinal()).setTotalRenderTimeMs(totalRenderTimeMs);
if (trigger != null) {
switch(trigger) {
case RESOURCE_EDIT:
case RESOURCE_CHANGED:
builder.setTrigger(LayoutEditorRenderResult.Trigger.RESOURCE_CHANGE);
break;
case EDIT:
case ADD_COMPONENTS:
case DELETE:
case DND_COMMIT:
case DND_END:
case DROP:
case RESIZE_END:
case RESIZE_COMMIT:
builder.setTrigger(LayoutEditorRenderResult.Trigger.EDIT);
break;
case REQUEST_RENDER:
builder.setTrigger(LayoutEditorRenderResult.Trigger.USER);
break;
case BUILD:
builder.setTrigger(LayoutEditorRenderResult.Trigger.BUILD);
break;
case CONFIGURATION_CHANGE:
case UPDATE_HIERARCHY:
break;
}
}
builder.setComponentCount((int) result.getRootViews().stream().flatMap(s -> Stream.concat(s.getChildren().stream(), Stream.of(s))).count());
RenderErrorModel errorModel = RenderErrorModelFactory.createErrorModel(result, null);
builder.setTotalIssueCount(errorModel.getSize());
if (errorModel.getSize() > 0) {
int errorCount = 0;
int fidelityWarningCount = 0;
for (RenderErrorModel.Issue issue : errorModel.getIssues()) {
if (HighlightSeverity.ERROR.equals(issue.getSeverity())) {
errorCount++;
} else if (issue.getSummary().startsWith("Layout fid")) {
fidelityWarningCount++;
}
}
builder.setErrorCount(errorCount).setFidelityWarningCount(fidelityWarningCount);
}
event.setRenderResult(builder.build());
});
}
use of java.util.stream.Stream in project RecurrentComplex by Ivorforce.
the class TransformerNaturalAir method transform.
@Override
public void transform(InstanceData instanceData, Phase phase, StructureSpawnContext context, IvWorldData worldData, RunTransformer transformer) {
super.transform(instanceData, phase, context, worldData, transformer);
if (phase == Phase.AFTER) {
WorldServer world = context.environment.world;
IvBlockCollection blockCollection = worldData.blockCollection;
int[] areaSize = new int[] { blockCollection.width, blockCollection.height, blockCollection.length };
BlockPos lowerCoord = StructureBoundingBoxes.min(context.boundingBox);
// Remove dying foliage
HashSet<BlockPos> check = instanceData.cloud.keySet().stream().flatMap(pos -> new BlockArea(pos.subtract(new Vec3i(2, 2, 2)), pos.add(new Vec3i(2, 2, 2))).stream()).filter(pos -> !instanceData.cloud.containsKey(pos)).map(pos -> context.transform.apply(pos, areaSize).add(lowerCoord)).collect(Collectors.toCollection(HashSet::new));
Set<BlockPos> remove = new HashSet<>();
HashSet<BlockPos> start = new HashSet<>();
// Do each one separately, since each block needs to be connected to floor separately
check.forEach(checking -> {
start.add(checking);
if (visitRecursively(start, (changed, pos) -> {
IBlockState state = world.getBlockState(pos);
boolean isFoliage = RCBlockLogic.isFoliage(state, world, pos);
if (!RCBlockLogic.canStay(state, world, pos))
context.setBlock(pos, Blocks.AIR.getDefaultState(), 2);
else if (!isFoliage && !state.getBlock().isReplaceable(world, pos))
return false;
else if (isFoliage && remove.size() < MAX_TREE_SIZE && remove.add(pos))
neighbors(pos).forEach(changed::add);
return true;
})) {
remove.forEach(pos -> context.setBlock(pos, Blocks.AIR.getDefaultState(), 2));
}
start.clear();
remove.clear();
});
}
}
use of java.util.stream.Stream in project RecurrentComplex by Ivorforce.
the class CommandRetrogen method existingRegions.
public static Stream<Pair<Integer, Integer>> existingRegions(File worldDir) {
File regionsDirectory = RCFiles.getValidatedFolder(new File(worldDir, "region"), false);
if (regionsDirectory == null)
return Stream.empty();
String[] mcas = regionsDirectory.list(new FileSuffixFilter("mca"));
if (mcas == null)
throw new IllegalStateException();
return Arrays.stream(mcas).map(s -> s.split("\\.")).filter(// Is region file
p -> p.length == 4 && p[0].equals("r")).map(p -> Pair.of(Integer.parseInt(p[1]), Integer.parseInt(p[2]))).filter(// Has coords
rfc -> rfc.getLeft() != null && rfc.getRight() != null);
}
use of java.util.stream.Stream in project jabref by JabRef.
the class CiteKeyBasedFileFinder method findFilesByExtension.
/**
* Returns a list of all files in the given directories which have one of the given extension.
*/
public Set<Path> findFilesByExtension(List<Path> directories, List<String> extensions) {
Objects.requireNonNull(extensions, "Extensions must not be null!");
BiPredicate<Path, BasicFileAttributes> isFileWithCorrectExtension = (path, attributes) -> !Files.isDirectory(path) && extensions.contains(FileHelper.getFileExtension(path).orElse(""));
Set<Path> result = new HashSet<>();
for (Path directory : directories) {
try (Stream<Path> files = Files.find(directory, Integer.MAX_VALUE, isFileWithCorrectExtension)) {
result.addAll(files.collect(Collectors.toSet()));
} catch (IOException e) {
LOGGER.error("Problem in finding files", e);
}
}
return result;
}
use of java.util.stream.Stream in project bitsquare by bitsquare.
the class TransactionsView method showStatisticsPopup.
private void showStatisticsPopup() {
Map<Long, List<Coin>> map = new HashMap<>();
Map<String, Tuple4<Date, Integer, Integer, Integer>> dataByDayMap = new HashMap<>();
observableList.stream().forEach(item -> {
Coin amountAsCoin = item.getAmountAsCoin();
List<Coin> amounts;
long key = amountAsCoin.getValue();
if (!map.containsKey(key)) {
amounts = new ArrayList<>();
map.put(key, amounts);
} else {
amounts = map.get(key);
}
amounts.add(amountAsCoin);
DateFormat dateFormatter = DateFormat.getDateInstance(DateFormat.DEFAULT, Locale.US);
String day = dateFormatter.format(item.getDate());
if (!dataByDayMap.containsKey(day)) {
int numOffers = 0;
int numTrades = 0;
if (amountAsCoin.compareTo(FeePolicy.getCreateOfferFee().subtract(FeePolicy.getFixedTxFeeForTrades())) == 0)
numOffers++;
else if (amountAsCoin.compareTo(FeePolicy.getTakeOfferFee().subtract(FeePolicy.getFixedTxFeeForTrades())) == 0)
numTrades++;
dataByDayMap.put(day, new Tuple4<>(item.getDate(), 1, numOffers, numTrades));
} else {
Tuple4<Date, Integer, Integer, Integer> tuple = dataByDayMap.get(day);
int prev = tuple.second;
int numOffers = tuple.third;
int numTrades = tuple.forth;
if (amountAsCoin.compareTo(FeePolicy.getCreateOfferFee().subtract(FeePolicy.getFixedTxFeeForTrades())) == 0)
numOffers++;
else if (amountAsCoin.compareTo(FeePolicy.getTakeOfferFee().subtract(FeePolicy.getFixedTxFeeForTrades())) == 0)
numTrades++;
dataByDayMap.put(day, new Tuple4<>(tuple.first, ++prev, numOffers, numTrades));
}
});
StringBuilder stringBuilder = new StringBuilder();
map.entrySet().stream().forEach(e -> {
stringBuilder.append("No. of transactions for amount ").append(formatter.formatCoinWithCode(Coin.valueOf(e.getKey()))).append(": ").append(e.getValue().size()).append("\n");
});
List<Tuple4<String, Date, Integer, Tuple2<Integer, Integer>>> sortedDataByDayList = dataByDayMap.entrySet().stream().map(e -> {
Tuple4<Date, Integer, Integer, Integer> data = e.getValue();
return new Tuple4<>(e.getKey(), data.first, data.second, new Tuple2<>(data.third, data.forth));
}).collect(Collectors.toList());
sortedDataByDayList.sort((o1, o2) -> o2.second.compareTo(o1.second));
StringBuilder transactionsByDayStringBuilder = new StringBuilder();
StringBuilder offersStringBuilder = new StringBuilder();
StringBuilder tradesStringBuilder = new StringBuilder();
StringBuilder allStringBuilder = new StringBuilder();
allStringBuilder.append("Date").append(";").append("Offers").append(";").append("Trades").append("\n");
sortedDataByDayList.stream().forEach(tuple4 -> {
offersStringBuilder.append(tuple4.forth.first).append(",");
tradesStringBuilder.append(tuple4.forth.second).append(",");
allStringBuilder.append(tuple4.first).append(";").append(tuple4.forth.first).append(";").append(tuple4.forth.second).append("\n");
transactionsByDayStringBuilder.append("\n").append(tuple4.first).append(": ").append(tuple4.third).append(" (Offers: ").append(tuple4.forth.first).append(" / Trades: ").append(tuple4.forth.second).append(")");
});
String message = stringBuilder.toString() + "\nNo. of transactions by day:" + transactionsByDayStringBuilder.toString();
new Popup().headLine("Statistical info").information(message).actionButtonText("Copy").onAction(() -> Utilities.copyToClipboard(message + "\n\nCSV (Offers):\n" + offersStringBuilder.toString() + "\n\nCSV (Trades):\n" + tradesStringBuilder.toString() + "\n\nCSV (all):\n" + allStringBuilder.toString())).show();
}
Aggregations