Search in sources :

Example 36 with Predicate

use of java.util.function.Predicate in project RecurrentComplex by Ivorforce.

the class WorldGenStructures method planStructuresInChunk.

public static void planStructuresInChunk(Random random, ChunkPos chunkPos, WorldServer world, Biome biomeGen, @Nullable Predicate<Structure> structurePredicate) {
    MixingStructureSelector<NaturalGeneration, NaturalStructureSelector.Category> structureSelector = StructureRegistry.INSTANCE.naturalStructureSelectors().get(biomeGen, world.provider);
    float distanceToSpawn = distance(new ChunkPos(world.getSpawnPoint()), chunkPos);
    // TODO Use STRUCTURE_TRIES
    List<Pair<Structure<?>, NaturalGeneration>> generated = structureSelector.generatedStructures(random, world.getBiome(chunkPos.getBlock(0, 0, 0)), world.provider, distanceToSpawn);
    generated.stream().filter(pair -> structurePredicate == null || structurePredicate.test(pair.getLeft())).forEach(pair -> planStructureInChunk(chunkPos, world, pair.getLeft(), pair.getRight(), random.nextLong()));
}
Also used : BlockSurfacePos(ivorius.ivtoolkit.blocks.BlockSurfacePos) NaturalStructureSelector(ivorius.reccomplex.world.gen.feature.selector.NaturalStructureSelector) StaticGeneration(ivorius.reccomplex.world.gen.feature.structure.generic.generation.StaticGeneration) Structures(ivorius.reccomplex.world.gen.feature.structure.Structures) Predicate(java.util.function.Predicate) Structure(ivorius.reccomplex.world.gen.feature.structure.Structure) StructureSpawnContext(ivorius.reccomplex.world.gen.feature.structure.context.StructureSpawnContext) StructureRegistry(ivorius.reccomplex.world.gen.feature.structure.StructureRegistry) ChunkPos(net.minecraft.util.math.ChunkPos) BlockPos(net.minecraft.util.math.BlockPos) Random(java.util.Random) RCConfig(ivorius.reccomplex.RCConfig) Collectors(java.util.stream.Collectors) List(java.util.List) Pair(org.apache.commons.lang3.tuple.Pair) MathHelper(net.minecraft.util.math.MathHelper) MixingStructureSelector(ivorius.reccomplex.world.gen.feature.selector.MixingStructureSelector) NaturalGeneration(ivorius.reccomplex.world.gen.feature.structure.generic.generation.NaturalGeneration) RecurrentComplex(ivorius.reccomplex.RecurrentComplex) WorldServer(net.minecraft.world.WorldServer) IvVecMathHelper(ivorius.ivtoolkit.math.IvVecMathHelper) Biome(net.minecraft.world.biome.Biome) Nullable(javax.annotation.Nullable) ChunkPos(net.minecraft.util.math.ChunkPos) NaturalGeneration(ivorius.reccomplex.world.gen.feature.structure.generic.generation.NaturalGeneration) Pair(org.apache.commons.lang3.tuple.Pair)

Example 37 with Predicate

use of java.util.function.Predicate in project indy by Commonjava.

the class ValidationRequest method getSourcePaths.

public synchronized Set<String> getSourcePaths(boolean includeMetadata, boolean includeChecksums) throws PromotionValidationException {
    if (requestPaths == null) {
        Set<String> paths = null;
        if (promoteRequest instanceof PathsPromoteRequest) {
            paths = ((PathsPromoteRequest) promoteRequest).getPaths();
        }
        if (paths == null) {
            ArtifactStore store = null;
            try {
                store = tools.getArtifactStore(promoteRequest.getSource());
            } catch (IndyDataException e) {
                throw new PromotionValidationException("Failed to retrieve source ArtifactStore: {}. Reason: {}", e, promoteRequest.getSource(), e.getMessage());
            }
            if (store != null) {
                try {
                    paths = new HashSet<>();
                    listRecursively(store, "/", paths);
                } catch (IndyWorkflowException e) {
                    throw new PromotionValidationException("Failed to list paths in source: {}. Reason: {}", e, promoteRequest.getSource(), e.getMessage());
                }
            }
        }
        requestPaths = paths;
    }
    if (!includeMetadata || !includeChecksums) {
        Predicate<String> filter = (path) -> (includeMetadata || !path.matches(".+/maven-metadata\\.xml(\\.(md5|sha[0-9]+))?")) && (includeChecksums || !path.matches(".+\\.(md5|sha[0-9]+)"));
        return requestPaths.stream().filter(filter).collect(Collectors.toSet());
    }
    return requestPaths;
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) PathsPromoteRequest(org.commonjava.indy.promote.model.PathsPromoteRequest) PromotionValidationException(org.commonjava.indy.promote.validate.PromotionValidationException) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) Predicate(java.util.function.Predicate) Set(java.util.Set) Collectors(java.util.stream.Collectors) HashSet(java.util.HashSet) Transfer(org.commonjava.maven.galley.model.Transfer) ValidationRuleSet(org.commonjava.indy.promote.model.ValidationRuleSet) List(java.util.List) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) StoreResource(org.commonjava.indy.content.StoreResource) PromotionValidationTools(org.commonjava.indy.promote.validate.PromotionValidationTools) PromoteRequest(org.commonjava.indy.promote.model.PromoteRequest) IndyDataException(org.commonjava.indy.data.IndyDataException) StoreKey(org.commonjava.indy.model.core.StoreKey) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) PathsPromoteRequest(org.commonjava.indy.promote.model.PathsPromoteRequest) PromotionValidationException(org.commonjava.indy.promote.validate.PromotionValidationException)

Example 38 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 39 with Predicate

use of java.util.function.Predicate in project amos-ss17-alexa by c-i-ber.

the class AmosAlexaSimpleTestImpl method categoryLimitTest.

@Ignore
public void categoryLimitTest() throws IllegalAccessException, NoSuchFieldException, IOException {
    newSession();
    // Fetch category object 'lebensmittel' previously to be able to set it back afterwards, so that the test
    // does not affect our data
    List<Category> categories = DynamoDbMapper.getInstance().loadAll(Category.class);
    Category category = null;
    // We assume that 'lebensmittel' category exists!
    for (Category cat : categories) {
        if (cat.getName().equals("auto")) {
            category = cat;
        }
    }
    // Test limit info with unknown category name
    testIntent("CategoryLimitInfoIntent", "Category:dsafoihdsfzzzzzssdf", "Es gibt keine Kategorie mit diesem Namen. Waehle eine andere Kategorie oder" + " erhalte eine Info zu den verfuegbaren Kategorien.");
    // Test plain category name input
    testIntentMatches("PlainCategoryIntent", "Category:auto", "Das Limit fuer die Kategorie auto liegt bei (.*) Euro.");
    // Test limit setting
    testIntent("CategoryLimitSetIntent", "Category:lebensmittel", "CategoryLimit:250", "Moechtest du das Ausgabelimit fuer die Kategorie lebensmittel wirklich auf 250 Euro setzen?");
    // Setting confirmation (yes)
    testIntent("AMAZON.YesIntent", "Limit fuer lebensmittel wurde gesetzt.");
    // Test limit info after setting
    testIntent("CategoryLimitInfoIntent", "Category:lebensmittel", "Das Limit fuer die Kategorie lebensmittel liegt bei 250.0 Euro.");
    // Reset the category lebensmittel (as it was before)
    List<Category> categories2 = DynamoDbMapper.getInstance().loadAll(Category.class);
    for (Category c : categories2) {
        DynamoDbMapper.getInstance().delete(c);
    }
    Predicate<Category> categoryPredicate = c -> c.getName().equals("lebensmittel");
    categories2.removeIf(categoryPredicate);
    LOGGER.info("Categories2: " + categories2);
    for (Category c : categories2) {
        DynamoDbMapper.getInstance().save(c);
    }
    DynamoDbMapper.getInstance().save(category);
}
Also used : AccountData(amosalexa.services.AccountData) DynamoDbMapper(api.aws.DynamoDbMapper) java.util(java.util) Spending(model.db.Spending) BeforeClass(org.junit.BeforeClass) LoggerFactory(org.slf4j.LoggerFactory) SimpleDateFormat(java.text.SimpleDateFormat) StringUtils(org.apache.commons.lang3.StringUtils) DynamoDbClient(api.aws.DynamoDbClient) Contact(model.db.Contact) Matcher(java.util.regex.Matcher) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) AccountAPI(api.banking.AccountAPI) Assert.fail(org.junit.Assert.fail) AffordabilityService(amosalexa.services.financing.AffordabilityService) Transaction(model.banking.Transaction) HelpService(amosalexa.services.help.HelpService) Server(org.eclipse.jetty.server.Server) Category(model.db.Category) DateFormat(java.text.DateFormat) TransactionDB(model.db.TransactionDB) Logger(org.slf4j.Logger) Launcher(amosalexa.server.Launcher) Predicate(java.util.function.Predicate) DateTime(org.joda.time.DateTime) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) IOException(java.io.IOException) Card(model.banking.Card) BudgetManager(amosalexa.services.budgettracker.BudgetManager) Ignore(org.junit.Ignore) StandingOrder(model.banking.StandingOrder) AreaOp(sun.awt.geom.AreaOp) TransactionForecastService(amosalexa.services.financing.TransactionForecastService) TransactionAPI(api.banking.TransactionAPI) ContactTransferService(amosalexa.services.bankaccount.ContactTransferService) Pattern(java.util.regex.Pattern) AccountBalanceForecastService(amosalexa.services.financing.AccountBalanceForecastService) Assert.assertEquals(org.junit.Assert.assertEquals) Category(model.db.Category) Ignore(org.junit.Ignore)

Example 40 with Predicate

use of java.util.function.Predicate in project LiveLessons by douglascraigschmidt.

the class TestDataFactory method getInput.

/**
     * Return the input data in the given @a filename as an array of
     * Strings.
     */
public static List<String> getInput(String filename, String splitter) {
    try {
        // Convert the filename into a pathname.
        URI uri = ClassLoader.getSystemResource(filename).toURI();
        // Open the file and get all the bytes.
        String bytes = new String(Files.readAllBytes(Paths.get(uri)));
        return // file into a list of strings.
        Pattern.compile(splitter).splitAsStream(bytes).filter(((Predicate<String>) String::isEmpty).negate()).collect(toList());
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}
Also used : URI(java.net.URI) Predicate(java.util.function.Predicate)

Aggregations

Predicate (java.util.function.Predicate)120 List (java.util.List)49 Map (java.util.Map)34 Collectors (java.util.stream.Collectors)31 Test (org.junit.Test)30 IOException (java.io.IOException)28 ArrayList (java.util.ArrayList)26 Arrays (java.util.Arrays)25 Collections (java.util.Collections)23 Set (java.util.Set)15 Function (java.util.function.Function)14 Assert.assertEquals (org.junit.Assert.assertEquals)14 java.util (java.util)13 Optional (java.util.Optional)13 Supplier (java.util.function.Supplier)13 HashMap (java.util.HashMap)12 Before (org.junit.Before)12 Objects (java.util.Objects)11 InputStream (java.io.InputStream)10 AssertExtensions (io.pravega.test.common.AssertExtensions)9