org.eclipse.collections.api.block.predicate.Predicate Java Examples

The following examples show how to use org.eclipse.collections.api.block.predicate.Predicate. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HsqlReveng.java    From obevo with Apache License 2.0 6 votes vote down vote up
public HsqlReveng() {
    // Note - HSQL Export currently
    super(
            new HsqlDbPlatform(),
            null,
            Lists.immutable.<Predicate<String>>of(
                    StringPredicates.startsWith("SET DATABASE")
                    , StringPredicates.startsWith("SET FILES")
                    , StringPredicates.startsWith("SET SCHEMA")
                    , StringPredicates.startsWith("INSERT INTO")
                    , StringPredicates.startsWith("CREATE USER")
                    , StringPredicates.startsWith("ALTER USER")
                    , StringPredicates.startsWith("CREATE ROLE")
                    , StringPredicates.startsWith("CREATE SCHEMA")
                    , StringPredicates.startsWith("GRANT ")
                    , StringPredicates.startsWith("ALTER SEQUENCE SYSTEM_LOBS")
            ),
            getRevengPatterns(),
            null
    );
    setStartQuote(QUOTE);
    setEndQuote(QUOTE);
}
 
Example #2
Source File: DbDeployer.java    From obevo with Apache License 2.0 6 votes vote down vote up
private ChecksumEntryInclusionPredicate createLookupIndexForObjectType(DbEnvironment env, ImmutableList<Change> sourceChanges, final String changeTypeName) {
    LookupIndex objectTypeIndex = new LookupIndex(Sets.immutable.with(changeTypeName));
    ImmutableList<Change> objectTypeChanges = sourceChanges.select(new Predicate<Change>() {
        @Override
        public boolean accept(Change it) {
            return it.getChangeTypeName().equals(changeTypeName);
        }
    });
    MutableSet<String> objectNames = objectTypeChanges.collect(new Function<Change, String>() {
        @Override
        public String valueOf(Change change) {
            return change.getObjectName();
        }
    }).collect(env.getPlatform().convertDbObjectName()).toSet();
    LookupIndex objectNameIndex = new LookupIndex(objectNames.toImmutable());
    return new ChecksumEntryInclusionPredicate(
            Lists.immutable.with(objectTypeIndex),
            Lists.immutable.with(objectNameIndex)
    );
}
 
Example #3
Source File: DbDeployer.java    From obevo with Apache License 2.0 6 votes vote down vote up
private Predicate<? super ChecksumEntry> getPlatformInclusionPredicate(DbEnvironment env) {
    // 1) exclude those tables that are excluded by default from source code, e.g. explain tables or others that users configure
    ImmutableSet<Predicate<? super ChecksumEntry>> schemaObjectNamePredicates = env.getSchemas().collect(new Function<Schema, Predicate<? super ChecksumEntry>>() {
        @Override
        public Predicate<? super ChecksumEntry> valueOf(Schema schema) {
            return schema.getObjectExclusionPredicateBuilder().build(ChecksumEntry.TO_OBJECT_TYPE, ChecksumEntry.TO_NAME1);
        }
    });

    // 2) exclude the audit tables
    MutableMultimap<String, String> tablesToExclude = Multimaps.mutable.set.empty();

    tablesToExclude.putAll(ChangeType.TABLE_STR, Sets.immutable.with(
            env.getPlatform().convertDbObjectName().valueOf(getArtifactDeployerDao().getAuditContainerName()),
            env.getPlatform().convertDbObjectName().valueOf(dbChecksumManager.getChecksumContainerName()),
            env.getPlatform().convertDbObjectName().valueOf(getDeployExecutionDao().getExecutionContainerName()),
            env.getPlatform().convertDbObjectName().valueOf(getDeployExecutionDao().getExecutionAttributeContainerName())
    ));
    ObjectTypeAndNamePredicateBuilder auditTablePredicateBuilder = new ObjectTypeAndNamePredicateBuilder(tablesToExclude.toImmutable(), ObjectTypeAndNamePredicateBuilder.FilterType.EXCLUDE);
    Predicates<? super ChecksumEntry> auditTablePredicate = auditTablePredicateBuilder.build(ChecksumEntry.TO_OBJECT_TYPE, ChecksumEntry.TO_NAME1);

    return auditTablePredicate.and(schemaObjectNamePredicates);
}
 
Example #4
Source File: ChangeKeyPredicateBuilderTest.java    From obevo with Apache License 2.0 6 votes vote down vote up
@Test
public void testComboInFullPredicate() {
    Predicate<ChangeKey> singleComboPredicate1 =
            ChangeKeyPredicateBuilder.parseFullPredicate("sc%1~%~objA,mytableC~%");
    assertEquals(Sets.mutable.with(tableSch1ObjAChng1, tableSch1ObjAChng2, tableSch1ObjAChng3, tableSch1ObjCChng1),
            allChanges.select(singleComboPredicate1).toSet());

    Predicate<ChangeKey> pred2 =
            ChangeKeyPredicateBuilder.parseFullPredicate("%~%~%~CCCC%");
    assertEquals(Sets.mutable.with(tableSch1ObjBChng1, tableSch2ObjAChng1),
            allChanges.select(pred2).toSet());

    Predicate<ChangeKey> fullComboPredicate =
            ChangeKeyPredicateBuilder.parseFullPredicate("sc%1~%~objA,mytableC~%;%~%~%~CCCC%");
    assertEquals(Sets.mutable.with(tableSch1ObjAChng1, tableSch1ObjAChng2, tableSch1ObjAChng3, tableSch1ObjCChng1, tableSch1ObjBChng1, tableSch2ObjAChng1),
            allChanges.select(fullComboPredicate).toSet());
}
 
Example #5
Source File: DbDeployer.java    From obevo with Apache License 2.0 6 votes vote down vote up
@Override
public void validatePriorToDeployment(DbEnvironment env, DeployStrategy deployStrategy, ImmutableList<Change> sourceChanges, ImmutableCollection<Change> deployedChanges, Changeset artifactsToProcess) {

    if (env.isChecksumDetectionEnabled() && dbChecksumManager.isInitialized()) {
        Predicate<? super ChecksumEntry> platformInclusionPredicate = getPlatformInclusionPredicate(env);
        ImmutableCollection<ChecksumBreak> checksumBreaks = this.dbChecksumManager.determineChecksumDifferences(platformInclusionPredicate)
                .reject(ChecksumBreak.IS_EXPECTED_BREAK);

        if (checksumBreaks.notEmpty()) {
            LOG.info("*******************************************");
            LOG.info("WARNING: The following objects were modified or managed outside of {}.", PlatformConfiguration.getInstance().getToolName());
            LOG.info("Please revert these changes or incorporate into your {} codebase", PlatformConfiguration.getInstance().getToolName());

            for (ChecksumBreak checksumBreak : checksumBreaks) {
                LOG.info("\t" + checksumBreak.toDisplayString());
            }

            LOG.info("*******************************************");
            LOG.info("");
        }
    }
}
 
Example #6
Source File: PartitionPatternUnitTest.java    From tutorials with MIT License 6 votes vote down vote up
@Test
public void whenAnySatisfiesCondition_thenCorrect() {
    MutableList<Integer> numbers = list;
    PartitionMutableList<Integer> partitionedFolks = numbers.partition(new Predicate<Integer>() {

        /**
         * 
         */
        private static final long serialVersionUID = -1551138743683678406L;

        public boolean accept(Integer each) {
            return each > 30;
        }
    });
    MutableList<Integer> greaterThanThirty = partitionedFolks.getSelected().sortThis();
    MutableList<Integer> smallerThanThirty = partitionedFolks.getRejected().sortThis();

    Assertions.assertThat(smallerThanThirty).containsExactly(1, 5, 8, 17, 23);
    Assertions.assertThat(greaterThanThirty).containsExactly(31, 38, 41);
}
 
Example #7
Source File: FilterDataSourceTest.java    From obevo with Apache License 2.0 6 votes vote down vote up
@Test
@SuppressWarnings("unchecked")
public void testEmptyDataSource() {
    Predicate<CatoDataObject> disc = mock(Predicate.class);

    FilterDataSource filterDataSource = new FilterDataSource(new MockDataSource(), disc);

    filterDataSource.open();

    Assert.assertFalse(filterDataSource.hasNext());
    verify(disc, never()).accept(any(CatoDataObject.class));
    try {
        filterDataSource.next();
        Assert.fail();
    } catch (NoSuchElementException ex) {
    }
}
 
Example #8
Source File: BaselineValidatorMain.java    From obevo with Apache License 2.0 6 votes vote down vote up
private void validateNoBaselineBreaks(DbDeployerAppContext appContext, Predicate<? super CompareBreak> breakIgnorePredicate) {
    MutableList<CompareBreak> sortedCompareBreaks = this.calculateBaselineBreaks(appContext).toList().sortThis(
            Comparators.fromFunctions(
                    CompareBreak.TO_COMPARE_SUBJECT,
                    Functions.chain(CompareBreak.TO_CLAZZ, CLASS_TO_NAME),
                    Functions.chain(Functions.getToClass(), CLASS_TO_NAME)
            ));

    MutableList<CompareBreak> relevantBreaks = sortedCompareBreaks.reject(breakIgnorePredicate);

    LOG.info("Found " + relevantBreaks.size() + " breaks");

    if (!relevantBreaks.isEmpty()) {
        throw new IllegalArgumentException(
                "Found some mismatches between your change alters (LEFT) and your baseline files (RIGHT). Please review:\n"
                        + relevantBreaks.makeString("\n"));
    }
}
 
Example #9
Source File: UnitTestDbBuilder.java    From obevo with Apache License 2.0 6 votes vote down vote up
private MainDeployerArgs getMainDeployerArgs() {
    MainDeployerArgs args = new MainDeployerArgs();

    if (this.tables != null || this.views != null) {
        MutableList<Predicate<? super ChangeKey>> predicates = Lists.mutable.empty();
        if (this.tables != null) {
            predicates.add(ChangeKeyPredicateBuilder.newBuilder()
                    .setChangeTypes(ChangeType.TABLE_STR, ChangeType.FOREIGN_KEY_STR, ChangeType.TRIGGER_INCREMENTAL_OLD_STR, ChangeType.STATICDATA_STR)
                    .setObjectNames(Sets.immutable.withAll(this.tables))
                    .build());
        }
        if (this.views != null) {
            predicates.add(ChangeKeyPredicateBuilder.newBuilder()
                    .setChangeTypes(ChangeType.VIEW_STR)
                    .setObjectNames(Sets.immutable.withAll(this.views))
                    .build());
        }

        args.setChangeInclusionPredicate(Predicates.or(predicates));
    }

    args.setAllChangesets(true);  // for unit tests, we always want all changes to deploy
    return args;
}
 
Example #10
Source File: ChangeKeyPredicateBuilderTest.java    From obevo with Apache License 2.0 6 votes vote down vote up
@Test
public void testSchema() {
    Predicate<ChangeKey> allSchemaPredicate =
            ChangeKeyPredicateBuilder.parseSinglePredicate("sch%");
    assertEquals(allChanges.toSet(),
            allChanges.select(allSchemaPredicate).toSet());

    Predicate<ChangeKey> schema1Predicate =
            ChangeKeyPredicateBuilder.parseSinglePredicate("sch1%~%~%~%");

    assertEquals(Sets.mutable.with(tableSch1ObjAChng1, tableSch1ObjAChng2, tableSch1ObjAChng3, tableSch1ObjBChng1, tableSch1ObjCChng1, viewSch1ObjD, viewSch1ObjE),
            allChanges.select(schema1Predicate).toSet());

    Predicate<ChangeKey> schema2Predicate =
            ChangeKeyPredicateBuilder.parseSinglePredicate("%2~%~%~%");

    assertEquals(Sets.mutable.with(tableSch2ObjAChng1, viewSch2ObjF),
            allChanges.select(schema2Predicate).toSet());
}
 
Example #11
Source File: FilterDataSourceTest.java    From obevo with Apache License 2.0 6 votes vote down vote up
@Test
@SuppressWarnings("unchecked")
public void testFilteringDataSource() {
    MockDataSource dataSource = new MockDataSource();

    List<CatoDataObject> objs = new ArrayList<CatoDataObject>();
    for (int i = 0; i < 6; i++) {
        objs.add(TestUtil.createEmptyDataObject());
        dataSource.addData(objs.get(i));
    }

    Predicate<CatoDataObject> disc = mock(Predicate.class);
    when(disc.accept(any(CatoDataObject.class))).thenReturn(true, false, false, true, true, false);

    FilterDataSource filterDataSource = new FilterDataSource(dataSource, disc);
    filterDataSource.open();

    Assert.assertSame(objs.get(0), filterDataSource.next());
    Assert.assertSame(objs.get(3), filterDataSource.next());
    Assert.assertSame(objs.get(4), filterDataSource.next());

    Assert.assertFalse(filterDataSource.hasNext());

    verify(disc, times(6)).accept(any(CatoDataObject.class));
}
 
Example #12
Source File: IncrementalChangeTypeCommandCalculatorTest.java    From obevo with Apache License 2.0 6 votes vote down vote up
@Test
public void testBaselineException() {
    // In this use case, srcB is the baseline change w/ ch1 ch2 ch3 marked. However, we only see ch1 and ch2 deployed, so we throw an exception

    Change dep1 = new ChangeIncremental(tableChangeType, "schema", "tabB", "ch1", 0, "chng1", CONTENT);
    Change dep2 = new ChangeIncremental(tableChangeType, "schema", "tabB", "ch2", 0, "chng1", CONTENT);
    // hiding dep3 as to show the exception use case
    //Change dep3 = new ChangeIncremental(tableChangeType, "schema", "tabB", "ch3", 0, "chng1", CONTENT);
    Change srcB = new ChangeIncremental(tableChangeType, "schema", "tabB", "bas1", 0, "chng1", CONTENT)
            .withBaselines(Lists.mutable.with("ch1", "ch2", "ch3"));
    Change src4 = new ChangeIncremental(tableChangeType, "schema", "tabB", "ch4", 1, "chng1", CONTENT);

    ListIterable<ChangeCommand> changeset = cmdCalc.calculateCommands(tableChangeType, Lists.mutable.of(
            new ChangePair(srcB, null)
            , new ChangePair(src4, null)
            , new ChangePair(null, dep1)
            , new ChangePair(null, dep2)
    ), unusedChangesArg, false);

    assertEquals(2, changeset.size());
    Verify.assertAnySatisfy(changeset, assertValue(DeployChangeCommand.class, src4));
    Predicate<ChangeCommand> baselineWarningPredicate = assertValue(IncompleteBaselineWarning.class, srcB);
    Verify.assertAnySatisfy(changeset, baselineWarningPredicate);
    IncompleteBaselineWarning baselineWarning = (IncompleteBaselineWarning) changeset.detect(baselineWarningPredicate);
    assertEquals(Sets.mutable.with("ch3"), baselineWarning.getNonDeployedChanges());
}
 
Example #13
Source File: DaTableImpl.java    From obevo with Apache License 2.0 6 votes vote down vote up
@Override
public ImmutableCollection<DaIndex> getIndices() {
    return CollectionAdapter.adapt(table.getIndexes())
            .collect(new Function<Index, DaIndex>() {
                @Override
                public DaIndex valueOf(Index object) {
                    return new DaIndexImpl(object, schemaStrategy, extraIndexInfoMap.get(object.getName()));
                }
            })
            .reject(new Predicate<DaIndex>() {
                @Override
                public boolean accept(DaIndex index) {
                    ExtraIndexInfo extraIndexInfo = extraIndexInfoMap.get(index.getName());
                    return extraIndexInfo != null && extraIndexInfo.isConstraint();
                }
            })
            .toImmutable();
}
 
Example #14
Source File: PostgreSqlPgDumpReveng.java    From obevo with Apache License 2.0 6 votes vote down vote up
PostgreSqlPgDumpReveng() {
    super(
            new PostgreSqlDbPlatform(),
            new MultiLineStringSplitter("GO", true),  // the GO comes from a hack in AbstractReveng - should ideally be fixed
            Lists.immutable.<Predicate<String>>of(
                    StringPredicates.contains("-- PostgreSQL database dump").and(StringPredicates.contains("-- Dumped by pg_dump"))
            ),
            getRevengPatterns(),
            null
    );
    setSkipLinePredicates(Lists.immutable.<Predicate<String>>of(
            StringPredicates.startsWith("SET statement_timeout")
            , StringPredicates.startsWith("SET default_tablespace")
            , StringPredicates.startsWith("SET lock_timeout")
            , StringPredicates.startsWith("SET idle_in_transaction_session_timeout")
            , StringPredicates.startsWith("SET client_encoding")
            , StringPredicates.startsWith("SET standard_conforming_strings")
            , StringPredicates.startsWith("SET check_function_bodies")
            , StringPredicates.startsWith("SET client_min_messages")
            , StringPredicates.startsWith("SET row_security")
            , StringPredicates.startsWith("SET default_with_oids")
            , StringPredicates.startsWith("CREATE SCHEMA")
            , StringPredicates.startsWith("SET search_path")
    ));
}
 
Example #15
Source File: Db2lookReveng.java    From obevo with Apache License 2.0 6 votes vote down vote up
Db2lookReveng() {
    super(
            new Db2DbPlatform(),
            new MultiLineStringSplitter("~", false),
            Lists.immutable.<Predicate<String>>of(
                    StringPredicates.contains("CLP file was created using DB2LOOK")
                    , StringPredicates.startsWith("CREATE SCHEMA")
                    , StringPredicates.startsWith("SET CURRENT SCHEMA")
                    , StringPredicates.startsWith("SET CURRENT PATH")
                    , StringPredicates.startsWith("COMMIT WORK")
                    , StringPredicates.startsWith("CONNECT RESET")
                    , StringPredicates.startsWith("TERMINATE")
                    , StringPredicates.startsWith("SET NLS_STRING_UNITS = 'SYSTEM'")
            ),
            getRevengPatterns(),
            null
    );
    setStartQuote("\"");
    setEndQuote("\"");
}
 
Example #16
Source File: BaselineValidatorMainTest.java    From obevo with Apache License 2.0 6 votes vote down vote up
@Test
public void testBaselineMismatchScenario() {
    DbDeployerAppContext appContext = DbEnvironmentFactory.getInstance().readOneFromSourcePath("baselineutil/BaselineValidatorMain/uc1", "test")
            .buildAppContext();

    BaselineValidatorMain main = new BaselineValidatorMain();
    ImmutableSet<CompareBreak> compareBreaks = main.calculateBaselineBreaks(appContext);

    System.out.println("BREAKS\n" + compareBreaks.makeString("\n"));

    assertEquals(2, compareBreaks.size());
    ObjectCompareBreak objectBreak = (ObjectCompareBreak) compareBreaks.detect(Predicates
            .instanceOf(ObjectCompareBreak.class));

    FieldCompareBreak dataTypeBreak = (FieldCompareBreak) compareBreaks.select(
            Predicates.instanceOf(FieldCompareBreak.class)).detect(new Predicate<CompareBreak>() {
        @Override
        public boolean accept(CompareBreak each) {
            return ((FieldCompareBreak) each).getFieldName().equalsIgnoreCase("columnDataType");
        }
    });

    assertNotNull(objectBreak);
    assertNotNull(dataTypeBreak);
}
 
Example #17
Source File: MySqlDumpReveng.java    From obevo with Apache License 2.0 6 votes vote down vote up
MySqlDumpReveng() {
    super(
            new MySqlDbPlatform(),
            new MultiLineStringSplitter(";$", false),
            Lists.immutable.<Predicate<String>>of(
                    StringPredicates.contains("-- PostgreSQL database dump").and(StringPredicates.contains("-- Dumped by pg_dump"))
            ),
            getRevengPatterns(),
            null
    );
    setSkipLinePredicates(Lists.immutable.<Predicate<String>>of(
            str -> str.startsWith("/*!") && str.endsWith("*/;") && !str.startsWith("/*!50001 CREATE")
            , str -> str.startsWith("USE ")
            , str -> str.startsWith("SET ")
    ));
}
 
Example #18
Source File: DeepCompareUtil.java    From obevo with Apache License 2.0 6 votes vote down vote up
private MutableCollection<ClassCompareInfo> getClassCompareInfos(final Class clazz) {
    if (!this.classCompareInfoMap.containsKey(clazz)) {
        // We may have defined the comparison on a generalization (interface or superclass), so we check if there
        // are any compatible classes to check
        RichIterable<Class> realizedClasses = this.classCompareInfoMap.keysView().select(new Predicate<Class>() {
            @Override
            public boolean accept(Class each) {
                return each.isAssignableFrom(clazz);
            }
        });

        RichIterable<ClassCompareInfo> realizedClassCompareInfos = realizedClasses
                .flatCollect(new Function<Class, MutableCollection<ClassCompareInfo>>() {
                    @Override
                    public MutableCollection<ClassCompareInfo> valueOf(Class realizedClass) {
                        return DeepCompareUtil.this.classCompareInfoMap.get(realizedClass);
                    }
                });

        this.classCompareInfoMap.putAll(clazz, realizedClassCompareInfos.toList());
    }
    return this.classCompareInfoMap.get(clazz);
}
 
Example #19
Source File: ChangeKeyPredicateBuilderTest.java    From obevo with Apache License 2.0 5 votes vote down vote up
@Test
public void testComboInSinglePredicate() {
    Predicate<ChangeKey> comboPredicate =
            ChangeKeyPredicateBuilder.parseSinglePredicate("sc%1~%~objA,mytableC~%");
    assertEquals(Sets.mutable.with(tableSch1ObjAChng1, tableSch1ObjAChng2, tableSch1ObjAChng3, tableSch1ObjCChng1),
            allChanges.select(comboPredicate).toSet());
}
 
Example #20
Source File: ChangeKeyPredicateBuilderTest.java    From obevo with Apache License 2.0 5 votes vote down vote up
@Test
public void testFullWildcard() {
    Predicate<ChangeKey> allPredicate =
            ChangeKeyPredicateBuilder.parseSinglePredicate("%");

    assertEquals(allChanges.toSet(),
            allChanges.select(allPredicate).toSet());
}
 
Example #21
Source File: ChangeKeyPredicateBuilderTest.java    From obevo with Apache License 2.0 5 votes vote down vote up
@Test
public void testChangeName() {
    Predicate<ChangeKey> changeNamePredicate =
            ChangeKeyPredicateBuilder.parseSinglePredicate("%~%~%~CCCC%");
    assertEquals(Sets.mutable.with(tableSch1ObjBChng1, tableSch2ObjAChng1),
            allChanges.select(changeNamePredicate).toSet());
}
 
Example #22
Source File: AseDdlgenReveng.java    From obevo with Apache License 2.0 5 votes vote down vote up
public AseDdlgenReveng() {
    super(
            new AseDbPlatform(),
            MultiLineStringSplitter.createSplitterOnSpaceAndLine("go"),
            Lists.immutable.<Predicate<String>>of(
                    StringPredicates.startsWith("-- Sybase Adaptive Server Enterprise DDL Generator Utility"),
                    StringPredicates.startsWith("use "),
                    StringPredicates.startsWith("IF EXISTS ("),
                    StringPredicates.startsWith("create database"),
                    StringPredicates.startsWith("------------------------------------------------------------"),
                    StringPredicates.startsWith("Grant "),
                    StringPredicates.startsWith("exec sp_addgroup"),
                    StringPredicates.startsWith("exec sp_adduser"),
                    StringPredicates.startsWith("setuser"),
                    StringPredicates.startsWith("SETUSER"),
                    StringPredicates.startsWith("set quoted_identifier"),
                    StringPredicates.startsWith("sp_placeobject"),
                    StringPredicates.startsWith("exec sp_changedbowner"),
                    StringPredicates.startsWith("exec master.dbo.sp_dboption"),
                    StringPredicates.startsWith("checkpoint"),
                    StringPredicates.startsWith("sp_addthreshold"),
                    StringPredicates.startsWith("exec sp_addalias"),
                    StringPredicates.startsWith("-- DDLGen Completed")),
            getRevengPatterns(),
            new Procedure2<ChangeEntry, String>() {
                @Override
                public void value(ChangeEntry changeEntry, String sql) {
                    if (sql.contains("\"")) {
                        changeEntry.addMetadataAnnotation(TextMarkupDocumentReader.TOGGLE_DISABLE_QUOTED_IDENTIFIERS);
                    }
                }
            }
    );
}
 
Example #23
Source File: PlatformConfigReader.java    From obevo with Apache License 2.0 5 votes vote down vote up
private MutableList<PropertyInput> readConfigPackages(RichIterable<String> configPackages) {
    MutableSet<PropertyInput> prioritizedProperties = HashingStrategySets.mutable.of(HashingStrategies.fromFunction(new Function<PropertyInput, URL>() {
        @Override
        public URL valueOf(PropertyInput propertyInput) {
            return propertyInput.getPropertyFilePath();
        }
    }));

    for (String configPackage : configPackages) {
        ListIterable<FileObject> fileObjects = FileRetrievalMode.CLASSPATH.resolveFileObjects(configPackage)
                .flatCollect(new Function<FileObject, Iterable<FileObject>>() {
                    @Override
                    public Iterable<FileObject> valueOf(FileObject object) {
                        return ArrayAdapter.adapt(object.getChildren());
                    }
                });
        ListIterable<FileObject> propertyFiles = fileObjects
                .select(new Predicate<FileObject>() {
                    @Override
                    public boolean accept(FileObject it) {
                        return it.getName().getExtension().equals("yaml");
                    }
                });

        for (FileObject propertyFile : propertyFiles) {
            HierarchicalConfiguration<ImmutableNode> fileProps = loadPropertiesFromUrl(propertyFile);

            String configPriorityProp = fileProps.getString(PROP_CONFIG_PRIORITY);
            if (configPriorityProp != null) {
                int priority = Integer.parseInt(configPriorityProp);
                prioritizedProperties.add(new PropertyInput(propertyFile.getName().getBaseName(), propertyFile.getURLDa(), priority, fileProps));
            } else {
                LOG.warn("Property file {} was ignored as it did not contain {} property", propertyFile, PROP_CONFIG_PRIORITY);
            }
        }
    }
    return prioritizedProperties.toList();
}
 
Example #24
Source File: TestRevengDbPlatform.java    From obevo with Apache License 2.0 5 votes vote down vote up
@Override
public ChangeType getChangeType(final String name) {
    return getChangeTypes().detect(new Predicate<ChangeType>() {
        @Override
        public boolean accept(ChangeType each) {
            return name.equalsIgnoreCase(each.getName());
        }
    });
}
 
Example #25
Source File: ObjectTypeAndNamePredicateBuilder.java    From obevo with Apache License 2.0 5 votes vote down vote up
private static <T> Predicate<T> getObjectTypeAndNamePredicate(
        Function<? super T, String> typeFunction, ImmutableCollection<String> typePatterns,
        boolean negate, Function<? super T, String> nameFunction, ImmutableCollection<String> namePatterns) {
    Predicates<? super T> typePredicate = LookupPredicateBuilder.convert(typeFunction, typePatterns);
    Predicates<? super T> namePredicate = LookupPredicateBuilder.convert(nameFunction, namePatterns);

    if (negate) {
        namePredicate = Predicates.not(namePredicate);
    }

    return Predicates.or(Predicates.not(typePredicate), namePredicate);
}
 
Example #26
Source File: TestOffHeapDataVersion.java    From reladomo with Apache License 2.0 5 votes vote down vote up
private MithraRuntimeCacheController getMithraRuntimeCacheController(final String mithraClassName)
{
    Set<MithraRuntimeCacheController> controllers = MithraManagerProvider.getMithraManager().getRuntimeCacheControllerSet();
    return Iterate.select(controllers, new Predicate<MithraRuntimeCacheController>()
    {
        @Override
        public boolean accept(MithraRuntimeCacheController each)
        {
            return each.getClassName().equals(mithraClassName);
        }
    }).iterator().next();
}
 
Example #27
Source File: EclipseCollectionsCollectionFilter.java    From tutorials with MIT License 5 votes vote down vote up
static public Collection<Integer> findEvenNumbers(Collection<Integer> baseCollection) {
    Predicate<Integer> eclipsePredicate = item -> item % 2 == 0;
    Collection<Integer> filteredList = Lists.mutable.ofAll(baseCollection)
        .select(eclipsePredicate);

    return filteredList;
}
 
Example #28
Source File: ObjectTypeAndNamePredicateBuilder.java    From obevo with Apache License 2.0 5 votes vote down vote up
/**
 * Builds the predicate on object type and name based on the input functions passed in.
 */
public <T> Predicates<? super T> build(final Function<? super T, String> objectTypeFunction, final Function<? super T, String> objectNameFunction) {
    if (objectNamesByType.isEmpty()) {
        if (filterType == null || filterType.isEmptyInputResult()) {
            return Predicates.alwaysTrue();
        } else {
            return Predicates.alwaysFalse();
        }
    }

    RichIterable<Predicate<? super T>> typePredicates = objectNamesByType.keyMultiValuePairsView().toList().collect(new Function<Pair<String, RichIterable<String>>, Predicate<? super T>>() {
        @Override
        public Predicate<? super T> valueOf(Pair<String, RichIterable<String>> pair) {
            String objectType = pair.getOne();
            RichIterable<String> objectPatterns = pair.getTwo();
            boolean negatePredicate = filterType == FilterType.EXCLUDE;
            if (objectType.startsWith("-")) {
                objectType = objectType.substring(1);
                negatePredicate = true;
            }

            Predicate<T> objectTypeAndNamePredicate = getObjectTypeAndNamePredicate(
                    objectTypeFunction, Lists.immutable.with(objectType),
                    negatePredicate, objectNameFunction, objectPatterns.toList().toImmutable()
            );

            return objectTypeAndNamePredicate;
        }
    });

    if (filterType == null || filterType == FilterType.EXCLUDE) {
        return Predicates.and(typePredicates);
    } else {
        return Predicates.or(typePredicates);
    }
}
 
Example #29
Source File: EclipseCollectionsCollectionFilter.java    From tutorials with MIT License 5 votes vote down vote up
static public Collection<Integer> findEvenNumbersUsingIterate(Collection<Integer> baseCollection) {
    Predicate<Integer> eclipsePredicate = new Predicate<Integer>() {
        private static final long serialVersionUID = 1L;

        @Override
        public boolean accept(Integer arg0) {
            return arg0 % 2 == 0;
        }
    };
    Collection<Integer> filteredList = Iterate.select(baseCollection, eclipsePredicate);

    return filteredList;
}
 
Example #30
Source File: RerunnableChangeTypeCommandCalculator.java    From obevo with Apache License 2.0 5 votes vote down vote up
/**
 * TODO for rerunnable to support a better change group:
 * -add dependent changes where applicable (e.g. views, sps, functions, but not static data)
 * -group the related changes as needed
 * -create the change for each group
 */
private ImmutableList<ChangeCommand> processRerunnableChanges(ChangeType changeType,
        RerunnableObjectInfo rerunnableObjectInfo,
        RichIterable<Change> fromSourceList) {
    final MutableList<ChangeCommand> commands = Lists.mutable.empty();

    commands.addAll(rerunnableObjectInfo.getDroppedObjects().collect(new Function<Change, ExecuteChangeCommand>() {
        @Override
        public ExecuteChangeCommand valueOf(Change droppedObject) {
            return changeCommandFactory.createRemove(droppedObject).withDrop(true);
        }
    }));

    if (changeType.isDependentObjectRecalculationRequired()) {
        commands.addAll(getObjectChangesRequiringRecompilation(changeType, fromSourceList, rerunnableObjectInfo.getChangedObjects()
                .reject(new Predicate<Change>() {
                    @Override
                    public boolean accept(Change change1) {
                        return change1.isCreateOrReplace();
                    }
                }))
                .collect(new Function<Change, ExecuteChangeCommand>() {
                    @Override
                    public ExecuteChangeCommand valueOf(Change change) {
                        return changeCommandFactory.createDeployCommand(change, "Re-deploying this object due to change in dependent object [" + change.getObjectName() + "]");
                    }
                }));
    }

    commands.addAll(rerunnableObjectInfo.getChangedObjects().collect(new Function<Change, ExecuteChangeCommand>() {
        @Override
        public ExecuteChangeCommand valueOf(Change source) {
            return changeCommandFactory.createDeployCommand(source);
        }
    }));

    return commands.toImmutable();
}