Search in sources :

Example 21 with Predicate

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();
        }
    }));
}
Also used : ManagedLedger(org.apache.bookkeeper.mledger.ManagedLedger) CountDownLatch(java.util.concurrent.CountDownLatch) ManagedLedgerInfo(org.apache.bookkeeper.mledger.proto.MLDataFormats.ManagedLedgerInfo) Predicate(java.util.function.Predicate) ManagedLedgerInfo(org.apache.bookkeeper.mledger.proto.MLDataFormats.ManagedLedgerInfo) LedgerInfo(org.apache.bookkeeper.mledger.proto.MLDataFormats.ManagedLedgerInfo.LedgerInfo) MetaStoreException(org.apache.bookkeeper.mledger.ManagedLedgerException.MetaStoreException) Stat(org.apache.bookkeeper.mledger.impl.MetaStore.Stat) ManagedLedgerFactory(org.apache.bookkeeper.mledger.ManagedLedgerFactory) ManagedLedgerConfig(org.apache.bookkeeper.mledger.ManagedLedgerConfig) Test(org.testng.annotations.Test)

Example 22 with Predicate

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);
}
Also used : CallSite(java.lang.invoke.CallSite) MethodHandle(java.lang.invoke.MethodHandle) Predicate(java.util.function.Predicate) BiPredicate(java.util.function.BiPredicate)

Example 23 with Predicate

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)));
}
Also used : InventoryCitizen(com.minecolonies.coremod.inventory.InventoryCitizen) java.util(java.util) Blocks(net.minecraft.init.Blocks) ICapabilityProvider(net.minecraftforge.common.capabilities.ICapabilityProvider) AbstractJob(com.minecolonies.coremod.colony.jobs.AbstractJob) TextComponentBase(net.minecraft.util.text.TextComponentBase) TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) TileEntityChest(net.minecraft.tileentity.TileEntityChest) JobDeliveryman(com.minecolonies.coremod.colony.jobs.JobDeliveryman) ItemStack(net.minecraft.item.ItemStack) InvWrapper(net.minecraftforge.items.wrapper.InvWrapper) AITarget(com.minecolonies.coremod.entity.ai.util.AITarget) Block(net.minecraft.block.Block) com.minecolonies.api.util(com.minecolonies.api.util) TranslationConstants(com.minecolonies.api.util.constant.TranslationConstants) ItemStorage(com.minecolonies.coremod.entity.ai.item.handling.ItemStorage) WalkToProxy(com.minecolonies.coremod.entity.pathfinding.WalkToProxy) Predicate(java.util.function.Predicate) EnumFacing(net.minecraft.util.EnumFacing) BlockPos(net.minecraft.util.math.BlockPos) AIState(com.minecolonies.coremod.entity.ai.util.AIState) Nullable(org.jetbrains.annotations.Nullable) AbstractBuildingWorker(com.minecolonies.coremod.colony.buildings.AbstractBuildingWorker) TileEntity(net.minecraft.tileentity.TileEntity) NotNull(org.jetbrains.annotations.NotNull) AbstractBuildingWorker(com.minecolonies.coremod.colony.buildings.AbstractBuildingWorker) ItemStorage(com.minecolonies.coremod.entity.ai.item.handling.ItemStorage) Nullable(org.jetbrains.annotations.Nullable)

Example 24 with Predicate

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;
}
Also used : java.util(java.util) NoiseGenSimplex(mods.railcraft.common.worldgen.NoiseGen.NoiseGenSimplex) World(net.minecraft.world.World) Predicate(java.util.function.Predicate) EventType(net.minecraftforge.event.terraingen.OreGenEvent.GenerateMinable.EventType) Metal(mods.railcraft.common.items.Metal) BlockPos(net.minecraft.util.math.BlockPos) WorldGenMinable(net.minecraft.world.gen.feature.WorldGenMinable) IBlockState(net.minecraft.block.state.IBlockState) WorldGenerator(net.minecraft.world.gen.feature.WorldGenerator) BiomeDictionary(net.minecraftforge.common.BiomeDictionary) Type(net.minecraftforge.common.BiomeDictionary.Type) RailcraftConfig(mods.railcraft.common.core.RailcraftConfig) TerrainGen(net.minecraftforge.event.terraingen.TerrainGen) MapMaker(com.google.common.collect.MapMaker) Biome(net.minecraft.world.biome.Biome) Nullable(javax.annotation.Nullable) WorldGenerator(net.minecraft.world.gen.feature.WorldGenerator) IBlockState(net.minecraft.block.state.IBlockState) WorldGenMinable(net.minecraft.world.gen.feature.WorldGenMinable) Nullable(javax.annotation.Nullable)

Example 25 with Predicate

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);
}
Also used : NodeId(org.apache.jena.tdb.store.NodeId) Tuple(org.apache.jena.atlas.lib.tuple.Tuple) Predicate(java.util.function.Predicate)

Aggregations

Predicate (java.util.function.Predicate)76 List (java.util.List)34 Map (java.util.Map)21 Arrays (java.util.Arrays)19 IOException (java.io.IOException)18 Collections (java.util.Collections)16 Collectors (java.util.stream.Collectors)16 Test (org.junit.Test)14 ArrayList (java.util.ArrayList)13 Assert.assertEquals (org.junit.Assert.assertEquals)10 Mockito.mock (org.mockito.Mockito.mock)9 InputStream (java.io.InputStream)7 HashMap (java.util.HashMap)7 Optional (java.util.Optional)7 ImmutableList (com.google.common.collect.ImmutableList)6 ImmutableSet (com.google.common.collect.ImmutableSet)6 BufferedReader (java.io.BufferedReader)6 Set (java.util.Set)6 SortedSet (java.util.SortedSet)6 Before (org.junit.Before)6