use of java.util.function.BiPredicate in project cassandra by apache.
the class CustomClassLoader method addClassPath.
public void addClassPath(File dir) {
if (dir == null || !dir.exists())
return;
BiPredicate<File, String> filter = (ignore, name) -> name.endsWith(".jar");
for (File inputJar : dir.tryList(filter)) {
File lib = new File(FileUtils.getTempDir(), "lib");
if (!lib.exists()) {
lib.tryCreateDirectory();
lib.deleteOnExit();
}
File out = FileUtils.createTempFile("cassandra-", ".jar", lib);
out.deleteOnExit();
logger.info("Loading new jar {}", inputJar.absolutePath());
try {
copy(inputJar.toPath(), out.toPath());
addURL(out.toPath().toUri().toURL());
} catch (IOException ex) {
throw new FSWriteError(ex, out);
}
}
}
use of java.util.function.BiPredicate in project cassandra by apache.
the class CQLSSTableWriterTest method testSyncWithinPartition.
@Test
public void testSyncWithinPartition() throws Exception {
// Check that the write respect the buffer size even if we only insert rows withing the same partition (#7360)
// To do that simply, we use a writer with a buffer of 1MiB, and write 2 rows in the same partition with a value
// > 1MiB and validate that this created more than 1 sstable.
String schema = "CREATE TABLE " + qualifiedTable + " (" + " k int PRIMARY KEY," + " v blob" + ")";
String insert = "INSERT INTO " + qualifiedTable + " (k, v) VALUES (?, ?)";
CQLSSTableWriter writer = CQLSSTableWriter.builder().inDirectory(dataDir).using(insert).forTable(schema).withBufferSizeInMiB(1).build();
ByteBuffer val = ByteBuffer.allocate(1024 * 1050);
writer.addRow(0, val);
writer.addRow(1, val);
writer.close();
BiPredicate<File, String> filterDataFiles = (dir, name) -> name.endsWith("-Data.db");
assert dataDir.tryListNames(filterDataFiles).length > 1 : Arrays.toString(dataDir.tryListNames(filterDataFiles));
}
use of java.util.function.BiPredicate in project j2objc by google.
the class BiPredicateTest method testAnd.
public void testAnd() throws Exception {
Object arg1 = "one";
Object arg2 = "two";
AtomicBoolean alwaysTrueInvoked = new AtomicBoolean(false);
AtomicBoolean alwaysTrue2Invoked = new AtomicBoolean(false);
AtomicBoolean alwaysFalseInvoked = new AtomicBoolean(false);
AtomicBoolean alwaysFalse2Invoked = new AtomicBoolean(false);
AtomicBoolean[] invocationState = { alwaysTrueInvoked, alwaysTrue2Invoked, alwaysFalseInvoked, alwaysFalse2Invoked };
BiPredicate<Object, Object> alwaysTrue = (x, y) -> {
alwaysTrueInvoked.set(true);
assertSame(arg1, x);
assertSame(arg2, y);
return true;
};
BiPredicate<Object, Object> alwaysTrue2 = (x, y) -> {
alwaysTrue2Invoked.set(true);
assertSame(arg1, x);
assertSame(arg2, y);
return true;
};
BiPredicate<Object, Object> alwaysFalse = (x, y) -> {
alwaysFalseInvoked.set(true);
assertSame(arg1, x);
assertSame(arg2, y);
return false;
};
BiPredicate<Object, Object> alwaysFalse2 = (x, y) -> {
alwaysFalse2Invoked.set(true);
assertSame(arg1, x);
assertSame(arg2, y);
return false;
};
// true && true
resetToFalse(invocationState);
assertTrue(alwaysTrue.and(alwaysTrue2).test(arg1, arg2));
assertTrue(alwaysTrueInvoked.get() && alwaysTrue2Invoked.get());
// true && false
resetToFalse(invocationState);
assertFalse(alwaysTrue.and(alwaysFalse).test(arg1, arg2));
assertTrue(alwaysTrueInvoked.get() && alwaysFalseInvoked.get());
// false && false
resetToFalse(invocationState);
assertFalse(alwaysFalse.and(alwaysFalse2).test(arg1, arg2));
assertTrue(alwaysFalseInvoked.get() && !alwaysFalse2Invoked.get());
// false && true
resetToFalse(invocationState);
assertFalse(alwaysFalse.and(alwaysTrue).test(arg1, arg2));
assertTrue(alwaysFalseInvoked.get() && !alwaysTrueInvoked.get());
}
use of java.util.function.BiPredicate in project j2objc by google.
the class BiPredicateTest method testOr.
public void testOr() throws Exception {
Object arg1 = "one";
Object arg2 = "two";
AtomicBoolean alwaysTrueInvoked = new AtomicBoolean(false);
AtomicBoolean alwaysTrue2Invoked = new AtomicBoolean(false);
AtomicBoolean alwaysFalseInvoked = new AtomicBoolean(false);
AtomicBoolean alwaysFalse2Invoked = new AtomicBoolean(false);
AtomicBoolean[] invocationState = { alwaysTrueInvoked, alwaysTrue2Invoked, alwaysFalseInvoked, alwaysFalse2Invoked };
BiPredicate<Object, Object> alwaysTrue = (x, y) -> {
alwaysTrueInvoked.set(true);
assertSame(arg1, x);
assertSame(arg2, y);
return true;
};
BiPredicate<Object, Object> alwaysTrue2 = (x, y) -> {
alwaysTrue2Invoked.set(true);
assertSame(arg1, x);
assertSame(arg2, y);
return true;
};
BiPredicate<Object, Object> alwaysFalse = (x, y) -> {
alwaysFalseInvoked.set(true);
assertSame(arg1, x);
assertSame(arg2, y);
return false;
};
BiPredicate<Object, Object> alwaysFalse2 = (x, y) -> {
alwaysFalse2Invoked.set(true);
assertSame(arg1, x);
assertSame(arg2, y);
return false;
};
// true || true
resetToFalse(invocationState);
assertTrue(alwaysTrue.or(alwaysTrue2).test(arg1, arg2));
assertTrue(alwaysTrueInvoked.get() && !alwaysTrue2Invoked.get());
// true || false
resetToFalse(invocationState);
assertTrue(alwaysTrue.or(alwaysFalse).test(arg1, arg2));
assertTrue(alwaysTrueInvoked.get() && !alwaysFalseInvoked.get());
// false || false
resetToFalse(invocationState);
assertFalse(alwaysFalse.or(alwaysFalse2).test(arg1, arg2));
assertTrue(alwaysFalseInvoked.get() && alwaysFalse2Invoked.get());
// false || true
resetToFalse(invocationState);
assertTrue(alwaysFalse.or(alwaysTrue).test(arg1, arg2));
assertTrue(alwaysFalseInvoked.get() && alwaysTrueInvoked.get());
}
use of java.util.function.BiPredicate in project GDSC-SMLM by aherbert.
the class TcPalmAnalysis method analyseRois.
/**
* Analyses all the ROIs in the ROI manager.
*
* @param event the event
*/
private void analyseRois(ActionEvent event) {
final RoiManager manager = RoiManager.getInstance();
if (manager == null) {
IJ.error(TITLE, "ROI manager is not open");
return;
}
final LocalList<Roi> rois = Arrays.stream(manager.getRoisAsArray()).filter(Roi::isArea).collect(LocalCollectors.toLocalList());
if (rois.isEmpty()) {
IJ.error(TITLE, "No area ROIs");
return;
}
// Check for overlaps.
if (!settings.getDisableOverlapCheck() && anyOverlap(rois)) {
final GenericDialog gd = new GenericDialog(TITLE);
gd.addMessage(TextUtils.wrap("WARNING - Bounding rectangles of ROIs overlap. You can verify " + "the ROIs on the image using the ROI manager 'Show all' function.", 80));
gd.setOKLabel("Continue");
gd.showDialog();
if (gd.wasCanceled()) {
return;
}
}
// For each ROI:
// - Extract the current groups
// - Build the cumulative count plot
// - Identify the bursts
// - Extract ClusterData for each burst
final TcPalmAnalysisSettings settings = this.settings.build();
final LocalList<ClusterData> allClusters = rois.parallelStream().map(roi -> {
final Rectangle2D scaledBounds = createScaledBounds(roi);
final BiPredicate<ClusterData, Rectangle2D> filter = createSelectionFilter(roi, settings);
// Filter all cluster groups
final LocalList<ClusterData> clusters = new LocalList<>();
clusterData.forEach(c -> {
if (filter.test(c, scaledBounds)) {
clusters.add(c);
}
});
// Extract activation bursts
final CumulativeCountData countData = createCumulativeCountData(clusters, false);
final LocalList<int[]> bursts = runBurstAnalysis(settings, countData);
final LocalList<LocalList<PeakResult>> burstLocalisations = createBurstLocalisations(clusters, bursts);
clusters.clear();
burstLocalisations.forEach(list -> {
final ClusterData d = new ClusterData(clusters.size() + 1, list);
// Save this for analysis
d.sourceRoi = roi;
d.getArea();
clusters.add(d);
});
return clusters;
}).collect(LocalList::new, LocalList::addAll, LocalList::addAll);
// Reorder
final Counter count = new Counter();
allClusters.forEach(c -> c.id = count.incrementAndGet());
// Display in a table
final ClusterDataTableModelFrame frame = createAllClustersTable();
frame.getModel().setData(allClusters, dataCalibration);
// Allow the results to be repeated
frame.selectedAction = clusters -> {
// Expecting a single cluster. No clusters occurs when the table (and selection) is cleared.
if (clusters.size() == 1) {
final ClusterData c = clusters.get(0);
// Push the correct ROI and settings to the analysis action.
// We do not directly update the ROI or dialog settings as
// these trigger events that are processed to add work with a delay.
// Updating them at the end should generate events that are
// ignored when finally executed as the ROI/settings should be the same.
addWork(0, c.sourceRoi, settings, () -> {
// When analysis has finished update the settings and image ROI.
image.getImagePlus().setRoi(c.sourceRoi);
darkTimeToleranceTextField.setText(Integer.toString(settings.getDarkTimeTolerance()));
minClusterSizeTextField.setText(Integer.toString(settings.getMinClusterSize()));
// When analysis has finished the cluster should be selected in the
// current clusters table.
final ClusterDataTableModelFrame currentClusters = currentClustersTable.get();
if (currentClusters != null) {
currentClusters.select(c);
}
});
}
};
// Show histogram of cluster size/duration
reportAnalysis(settings, allClusters, dataCalibration);
// Save clusters to memory
final Trace[] traces = allClusters.stream().map(c -> {
final Trace t = new Trace();
t.setId(c.id);
c.results.forEach(t::add);
return t;
}).toArray(Trace[]::new);
TraceMolecules.saveResults(results, traces, "TC PALM");
IJ.showStatus(TITLE + ": " + TextUtils.pleural(allClusters.size(), "cluster"));
}
Aggregations