use of java.util.function.Predicate in project pulsar by yahoo.
the class ManagedLedgerTest method testBackwardCompatiblityForMeta.
@Test
public void testBackwardCompatiblityForMeta() throws Exception {
final ManagedLedgerInfo[] storedMLInfo = new ManagedLedgerInfo[3];
final Stat[] versions = new Stat[1];
ManagedLedgerFactory factory = new ManagedLedgerFactoryImpl(bkc, bkc.getZkHandle());
ManagedLedgerConfig conf = new ManagedLedgerConfig();
conf.setMaxEntriesPerLedger(1);
conf.setRetentionSizeInMB(10);
conf.setRetentionTime(1, TimeUnit.HOURS);
ManagedLedger ml = factory.open("backward_test_ledger", conf);
ml.openCursor("c1");
ml.addEntry("msg1".getBytes());
ml.addEntry("msg2".getBytes());
ml.close();
MetaStore store = new MetaStoreImplZookeeper(zkc, executor);
CountDownLatch l1 = new CountDownLatch(1);
// obtain the ledger info
store.getManagedLedgerInfo("backward_test_ledger", new MetaStoreCallback<ManagedLedgerInfo>() {
@Override
public void operationComplete(ManagedLedgerInfo result, Stat version) {
storedMLInfo[0] = result;
versions[0] = version;
l1.countDown();
}
@Override
public void operationFailed(MetaStoreException e) {
fail("on get ManagedLedgerInfo backward_test_ledger");
}
});
l1.await();
ManagedLedgerInfo.Builder builder1 = ManagedLedgerInfo.newBuilder();
// simulate test for old ledger with no timestampl
for (LedgerInfo info : storedMLInfo[0].getLedgerInfoList()) {
LedgerInfo noTimestamp = ManagedLedgerInfo.LedgerInfo.newBuilder().mergeFrom(info).clearTimestamp().build();
assertFalse(noTimestamp.hasTimestamp(), "expected old version info with no timestamp");
builder1.addLedgerInfo(noTimestamp);
}
storedMLInfo[1] = builder1.build();
// test timestamp on new ledger
CountDownLatch l2 = new CountDownLatch(1);
store.asyncUpdateLedgerIds("backward_test_ledger", storedMLInfo[1], versions[0], new MetaStoreCallback<Void>() {
@Override
public void operationComplete(Void result, Stat version) {
l2.countDown();
}
@Override
public void operationFailed(MetaStoreException e) {
fail("on asyncUpdateLedgerIds");
}
});
// verify that after update ledgers have timestamp
ManagedLedgerImpl newVersionLedger = (ManagedLedgerImpl) factory.open("backward_test_ledger", conf);
List<LedgerInfo> mlInfo = newVersionLedger.getLedgersInfoAsList();
assertTrue(mlInfo.stream().allMatch(new Predicate<LedgerInfo>() {
@Override
public boolean test(LedgerInfo ledgerInfo) {
return ledgerInfo.hasTimestamp();
}
}));
}
use of java.util.function.Predicate in project jdk8u_jdk by JetBrains.
the class SerializedLambdaTest method testDirectStdNonser.
// standard MF: nonserializable supertype
public void testDirectStdNonser() throws Throwable {
MethodHandle fooMH = MethodHandles.lookup().findStatic(SerializedLambdaTest.class, "foo", predicateMT);
// Standard metafactory, non-serializable target: not serializable
CallSite cs = LambdaMetafactory.metafactory(MethodHandles.lookup(), "test", MethodType.methodType(Predicate.class), predicateMT, fooMH, stringPredicateMT);
Predicate<String> p = (Predicate<String>) cs.getTarget().invokeExact();
assertNotSerial(p, fooAsserter);
}
use of java.util.function.Predicate in project minecolonies by Minecolonies.
the class AbstractEntityAIBasic method dumpOneMoreSlot.
/**
* Dumps one inventory slot into the building chest.
*
* @param keepIt used to test it that stack should be kept
* @return true if is has to dump more.
*/
private boolean dumpOneMoreSlot(@NotNull final Predicate<ItemStack> keepIt) {
//Items already kept in the inventory
final Map<ItemStorage, Integer> alreadyKept = new HashMap<>();
final Map<ItemStorage, Integer> shouldKeep = getOwnBuilding().getRequiredItemsAndAmount();
@Nullable final AbstractBuildingWorker buildingWorker = getOwnBuilding();
return buildingWorker != null && (walkToBuilding() || InventoryFunctions.matchFirstInProvider(worker, (slot, stack) -> !(InventoryUtils.isItemStackEmpty(stack) || keepIt.test(stack)) && shouldDumpItem(alreadyKept, shouldKeep, buildingWorker, stack, slot)));
}
use of java.util.function.Predicate in project Railcraft by Railcraft.
the class GeneratorMine method getGen.
@Nullable
private static WorldGenerator getGen(@Nullable IBlockState ore, int density) {
Predicate<IBlockState> genCheck = state -> RailcraftConfig.isWorldGenEnabled("sky") ? GenTools.AIR_STONE.test(state) : GenTools.STONE.test(state);
WorldGenerator gen;
if (ore == null)
gen = null;
else if (density >= 4)
gen = new WorldGenMinable(ore, density, genCheck::test);
else
gen = new WorldGenSmallDeposits(ore, density, genCheck);
return gen;
}
use of java.util.function.Predicate in project jena by apache.
the class TupleIndex method scan.
public static Iterator<Tuple<NodeId>> scan(Iterator<Tuple<NodeId>> iter, Tuple<NodeId> pattern) {
int tupleLength = pattern.len();
Predicate<Tuple<NodeId>> filter = new Predicate<Tuple<NodeId>>() {
@Override
public boolean test(Tuple<NodeId> item) {
// Check on pattern and item (both in natural order)
for (int i = 0; i < tupleLength; i++) {
NodeId n = pattern.get(i);
// The pattern must be null/Any or match the tuple being tested.
if (!NodeId.isAny(n))
if (!item.get(i).equals(n))
return false;
}
return true;
}
};
return Iter.filter(iter, filter);
}
Aggregations