Java Code Examples for org.eclipse.collections.impl.set.mutable.UnifiedSet#newSet()

The following examples show how to use org.eclipse.collections.impl.set.mutable.UnifiedSet#newSet() . 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: SimpleToOneDeepFetchStrategy.java    From reladomo with Apache License 2.0 6 votes vote down vote up
@Override
public List finishAdhocDeepFetch(DeepFetchNode node, DeepFetchResult resultSoFar)
{
    LocalInMemoryResult localResult = (LocalInMemoryResult) resultSoFar.getLocalResult();
    FastList parentList = localResult.notFound;
    MithraList simplifiedList = fetchSimplifiedJoinList(node, parentList, true);
    if (simplifiedList != null)
    {
        node.setResolvedList(localResult.fullResult.getAll(), chainPosition);
        node.addToResolvedList(simplifiedList, chainPosition);
        return populateQueryCache(parentList, simplifiedList, new CachedQueryPair(getCachedQueryFromList(simplifiedList)));
    }
    Extractor[] leftAttributesWithoutFilters = node.getRelatedFinder().zGetMapper().getLeftAttributesWithoutFilters();
    Set<Attribute> attrSet = UnifiedSet.newSet(leftAttributesWithoutFilters.length);
    for(Extractor e: leftAttributesWithoutFilters)
    {
        attrSet.add((Attribute) e);
    }
    node.createTempTableAndDeepFetchAdhoc(attrSet, node,
            parentList);
    node.addToResolvedList(localResult.fullResult.getAll(), chainPosition);
    return node.getCachedQueryList();
}
 
Example 2
Source File: TestStringLike.java    From reladomo with Apache License 2.0 6 votes vote down vote up
public void testStringWildIn() throws SQLException
{
    String sql = "select * from PARA_DESK where DESK_ID_STRING like 'g%' or DESK_ID_STRING like 'a%' or DESK_ID_STRING like 'b%'" +
            " or DESK_ID_STRING like 'a_' or DESK_ID_STRING like '%a%' or DESK_ID_STRING like '%b%' or DESK_ID_STRING like '%a'" +
            " or DESK_ID_STRING like '%b' or DESK_ID_STRING like '_a%' or DESK_ID_STRING like '_b%'";
    Set<String> patterns = UnifiedSet.newSet();
    patterns.add("g*");
    patterns.add("a*");
    patterns.add("b*");
    patterns.add("a?");
    patterns.add("*a*");
    patterns.add("*b*");
    patterns.add("*a");
    patterns.add("*b");
    patterns.add("?a*");
    patterns.add("?b*");
    ParaDeskList desks = new ParaDeskList(ParaDeskFinder.deskIdString().wildCardIn(patterns));
    this.genericRetrievalTest(sql, desks);
}
 
Example 3
Source File: AnalyzedWildcardPattern.java    From reladomo with Apache License 2.0 5 votes vote down vote up
public void addWildcard(String s)
{
    if (this.wildcard == null)
    {
        this.wildcard = UnifiedSet.newSet(); 
    }
    this.wildcard.add(s);
}
 
Example 4
Source File: TestIsNullOrLargeInOperation.java    From reladomo with Apache License 2.0 5 votes vote down vote up
private Set<String> createSet(int size)
{
    Set<String> values = UnifiedSet.newSet(size);
    for(int i = 0; i<=size; i++)
    {
        values.add(Integer.toString(i));
    }

    return values;
}
 
Example 5
Source File: ALSServingModel.java    From oryx with Apache License 2.0 5 votes vote down vote up
/**
 * Creates an empty model.
 *
 * @param features number of features expected for user/item feature vectors
 * @param implicit whether model implements implicit feedback
 * @param sampleRate consider only approximately this fraction of all items when making recommendations.
 *  Candidates are chosen intelligently with locality sensitive hashing.
 * @param rescorerProvider optional instance of a {@link RescorerProvider}
 */
ALSServingModel(int features, boolean implicit, double sampleRate, RescorerProvider rescorerProvider) {
  Preconditions.checkArgument(features > 0);
  Preconditions.checkArgument(sampleRate > 0.0 && sampleRate <= 1.0);

  lsh = new LocalitySensitiveHash(sampleRate, features);

  X = new FeatureVectorsPartition();
  Y = new PartitionedFeatureVectors(
      lsh.getNumPartitions(),
      executor,
      (String id, float[] vector) -> lsh.getIndexFor(vector));

  knownItems = UnifiedMap.newMap();
  knownItemsLock = new AutoReadWriteLock();

  expectedUserIDs = UnifiedSet.newSet();
  expectedUserIDsLock = new AutoReadWriteLock();
  expectedItemIDs = UnifiedSet.newSet();
  expectedItemIDsLock = new AutoReadWriteLock();

  cachedYTYSolver = new SolverCache(executor, Y);

  this.features = features;
  this.implicit = implicit;
  this.rescorerProvider = rescorerProvider;
}
 
Example 6
Source File: WhereClause.java    From reladomo with Apache License 2.0 5 votes vote down vote up
public void addReachableColumn(String fullyQualifiedColumn)
{
    if (this.reachableColumns == null)
    {
        this.reachableColumns = UnifiedSet.newSet(4);
    }
    this.reachableColumns.add(fullyQualifiedColumn);
}
 
Example 7
Source File: SerializationNode.java    From reladomo with Apache License 2.0 5 votes vote down vote up
protected SerializationNode withLinks(SerializationNode parent)
{
    SerializationNode result = new SerializationNode(parent, this.relatedFinder);
    result.attributes = this.attributes;

    Set<String> navigatedSet = UnifiedSet.newSet();
    for(int i=0;i<children.size();i++)
    {
        navigatedSet.add(children.get(i).getRelatedFinder().getRelationshipName());
    }

    List<RelatedFinder> allRelationships = this.relatedFinder.getRelationshipFinders();

    List<SerializationNode> newLinks = FastList.newList();

    for(int i=0;i<allRelationships.size();i++)
    {
        AbstractRelatedFinder rf = (AbstractRelatedFinder) allRelationships.get(i);
        if (!navigatedSet.contains(rf.getRelationshipName()))
        {
            SerializationNode link = new SerializationNode(result, rf, true);
            newLinks.add(link);
        }
    }
    List<SerializationNode> newChildren = FastList.newList(this.children.size());
    for(int i=0;i<children.size();i++)
    {
        newChildren.add(this.children.get(i).withLinks(result));
    }
    result.children = newChildren;
    result.links = newLinks;
    return result;
}
 
Example 8
Source File: TestDeDupedDualMessagingAdapter.java    From reladomo with Apache License 2.0 5 votes vote down vote up
@Test
public void testDeDupe()
{
    UnifiedSet<String> messageSet1 = UnifiedSet.newSetWith("msg1", "msg2", "msg3");
    UnifiedSet<String> messageSet2 = UnifiedSet.newSetWith("msg4");
    UnifiedSet<String> messageSet3 = UnifiedSet.newSetWith("msg5");

    //simulate message consumption by injecting messages into the adapter
    //set1 is consumed by both the the adapters
    factory1.getAdapter().inject(messageSet1);
    factory2.getAdapter().inject(messageSet1);

    //set2 is consumed just by adapter1
    factory1.getAdapter().inject(messageSet2);

    //set3 is consumed just by adapter2
    factory2.getAdapter().inject(messageSet3);

    //the actual event handler gets a unique set
    FastList<String> expectedMessages = FastList.newList();
    expectedMessages.addAll(messageSet1);
    expectedMessages.addAll(messageSet2);
    expectedMessages.addAll(messageSet3);

    List<MessageWithSubject> receivedMessages = recordingHandler.getMessages();
    UnifiedSet<String> receivedMessageSubjects = UnifiedSet.newSet();
    UnifiedSet<String> receivedMessageBodies = UnifiedSet.newSet();

    for (MessageWithSubject pair : receivedMessages)
    {
        receivedMessageSubjects.add(pair.getSubject());
        receivedMessageBodies.add(new String(pair.getMessage()));
    }

    assertTrue(receivedMessageBodies.containsAll(expectedMessages));
    assertEquals(1, receivedMessageSubjects.size());
    assertEquals(TEST_SUBJECT, receivedMessageSubjects.getFirst());
}
 
Example 9
Source File: BigDecimalUtil.java    From reladomo with Apache License 2.0 5 votes vote down vote up
public static Set<BigDecimal> createBigDecimalSetFromDoubleSet(DoubleSet doubleSet, int expectedScale, int expectedPrecision)
{
    Set<BigDecimal> bigDecimalSet = UnifiedSet.newSet(doubleSet.size());
    for (DoubleIterator it = doubleSet.doubleIterator(); it.hasNext();)
    {
        bigDecimalSet.add(createBigDecimalFromDouble(it.next(), expectedScale, expectedPrecision));
    }
    return bigDecimalSet;
}
 
Example 10
Source File: CacheLoaderManagerTest.java    From reladomo with Apache License 2.0 5 votes vote down vote up
private static <T> void assertListContainsAll(Collection<T> collection, T... items)
{
    UnifiedSet<T> set = UnifiedSet.newSet(collection);
    for (T item : items)
    {
        assertTrue("Expected to contain " + item + " but contains: " + collection.toString(), set.contains(item));
    }
}
 
Example 11
Source File: AnalyzedWildcardPattern.java    From reladomo with Apache License 2.0 5 votes vote down vote up
public void addSubstring(int length, String s)
{
    if (this.substring == null)
    {
        this.substring = new IntObjectHashMap<Set<String>>();
    }
    Set<String> stringSet = this.substring.get(length);
    if (stringSet == null)
    {
        stringSet = UnifiedSet.newSet();
        this.substring.put(length, stringSet);
    }
    stringSet.add(s);
}
 
Example 12
Source File: DbDataComparisonConfigFactory.java    From obevo with Apache License 2.0 5 votes vote down vote up
private static DbDataComparisonConfig createFromProperties(final Configuration config) {
    Properties propsView = ConfigurationConverter.getProperties(config);  // config.getString() automatically parses
    // for commas...would like to avoid this
    DbDataComparisonConfig compConfig = new DbDataComparisonConfig();
    compConfig.setInputTables(Lists.mutable.with(propsView.getProperty("tables.include").split(",")));
    compConfig.setExcludedTables(Lists.mutable.with(propsView.getProperty("tables.exclude").split(",")).toSet());
    String comparisonsStr = propsView.getProperty("comparisons");

    MutableList<Pair<String, String>> compCmdPairs = Lists.mutable.empty();
    MutableSet<String> dsNames = UnifiedSet.newSet();
    for (String compPairStr : comparisonsStr.split(";")) {
        String[] pairParts = compPairStr.split(",");
        compCmdPairs.add(Tuples.pair(pairParts[0], pairParts[1]));

        // note - if I knew where the Pair.TO_ONE TO_TWO selectors were, I'd use those
        dsNames.add(pairParts[0]);
        dsNames.add(pairParts[1]);
    }

    compConfig.setComparisonCommandNamePairs(compCmdPairs);

    MutableList<DbDataSource> dbDataSources = dsNames.toList().collect(new Function<String, DbDataSource>() {
        @Override
        public DbDataSource valueOf(String dsName) {
            Configuration dsConfig = config.subset(dsName);

            DbDataSource dbDataSource = new DbDataSource();
            dbDataSource.setName(dsName);
            dbDataSource.setUrl(dsConfig.getString("url"));
            dbDataSource.setSchema(dsConfig.getString("schema"));
            dbDataSource.setUsername(dsConfig.getString("username"));
            dbDataSource.setPassword(dsConfig.getString("password"));
            dbDataSource.setDriverClassName(dsConfig.getString("driverClass"));

            return dbDataSource;
        }
    });
    compConfig.setDbDataSources(dbDataSources);
    return compConfig;
}
 
Example 13
Source File: AnalyzedWildcardPattern.java    From reladomo with Apache License 2.0 5 votes vote down vote up
public void addContains(String s)
{
    if (this.contains == null)
    {
        this.contains = UnifiedSet.newSet(); 
    }
    this.contains.add(s);
}
 
Example 14
Source File: AbstractMithraTestConnectionManager.java    From reladomo with Apache License 2.0 5 votes vote down vote up
public Set<String> getCreatedTables()
{
    UnifiedSet<String> tables = UnifiedSet.newSet();
    for(TestDatabaseConfiguration configuration : this.testDbConfigurations)
    {
        tables.addAll(configuration.getCreatedTableNames());
    }

    return tables;
}
 
Example 15
Source File: TestTablePartitionManager.java    From reladomo with Apache License 2.0 5 votes vote down vote up
public void testExpectedTablesAreCreated() throws Exception
{
    Set<String> createdTables = ConnectionManagerForTestsWithTableManager.getInstance().getCreatedTables();

    UnifiedSet<String> expectedTables = UnifiedSet.newSet();

    for(MithraRuntimeCacheController controller : MithraManager.getInstance().getConfigManager().getRuntimeCacheControllerSet())
    {
        String table = controller.getFinderInstanceFromFinderClass().getMithraObjectPortal().getDatabaseObject().getDefaultTableName();

        if(controller.getFinderInstanceFromFinderClass().getSourceAttributeType() == null )
        {
            expectedTables.add(ConnectionManagerForTestsWithTableManager.getInstance().getTableName(table));
        }
        else if(controller.getFinderInstanceFromFinderClass().getSourceAttributeType().isIntSourceAttribute())
        {
            expectedTables.add(ConnectionManagerForTestsWithTableManager.getInstance().getTableName(table, 0));
            expectedTables.add(ConnectionManagerForTestsWithTableManager.getInstance().getTableName(table, 1));
        }
        else
        {
            expectedTables.add(ConnectionManagerForTestsWithTableManager.getInstance().getTableName(table, "A"));
            expectedTables.add(ConnectionManagerForTestsWithTableManager.getInstance().getTableName(table, "B"));
        }
    }

    assertEquals( expectedTables, createdTables );
}
 
Example 16
Source File: TestDetachedDatedListUsesCache.java    From reladomo with Apache License 2.0 5 votes vote down vote up
public static void assertSetsEqual(String setName, Set<?> expectedSet, Set<?> actualSet)
{
    try
    {
        if (null == expectedSet)
        {
            Assert.assertNull(setName + " should be null", actualSet);
            return;
        }

        assertObjectNotNull(setName, actualSet);
        assertSize(setName, expectedSet.size(), actualSet);

        if (!actualSet.equals(expectedSet))
        {
            Set<?> inExpectedOnlySet = UnifiedSet.newSet(expectedSet);
            inExpectedOnlySet.removeAll(actualSet);

            int numberDifferences = inExpectedOnlySet.size();
            String message =
                    setName + ": " + numberDifferences + " element(s) different.";

            if (numberDifferences > MAX_DIFFERENCES)
            {
                Assert.fail(message);
            }

            Set<?> inActualOnlySet = UnifiedSet.newSet(actualSet);
            inActualOnlySet.removeAll(expectedSet);

            failNotEquals(message, inExpectedOnlySet, inActualOnlySet);
        }
    }
    catch (AssertionError e)
    {
        throwMangledException(e);
    }
}
 
Example 17
Source File: DependentLoaderFactoryImpl.java    From reladomo with Apache License 2.0 5 votes vote down vote up
private Set<DependentLoadingTaskSpawner> findDependentTaskSpawners(CacheLoaderContext context, DateCluster dateCluster, Object sourceAttribute)
{
    Set<DependentLoadingTaskSpawner> dependentTaskSpawners = UnifiedSet.newSet();
    for (Timestamp businessDate : dateCluster.getBusinessDates())
    {
        DependentLoadingTaskSpawnerKey keyFromParentTask = new DependentLoadingTaskSpawnerKey(sourceAttribute, businessDate, this.helperFactory, this.relationshipAttributes, this.filteredMapperOperation);
        dependentTaskSpawners.add(context.getDependentLoadingTaskSpawnerMap().get(keyFromParentTask));
    }
    return dependentTaskSpawners;
}
 
Example 18
Source File: TestCalculatedString.java    From reladomo with Apache License 2.0 5 votes vote down vote up
public void testIntegerToString()
{
    StringAttribute orderIdAsString = OrderFinder.orderId().convertToStringAttribute();
    assertEquals(1, OrderFinder.findOne(orderIdAsString.eq("1")).getOrderId());
    Set<String> ids = UnifiedSet.newSet();
    ids.add("1");
    ids.add("2");
    ids.add("3");
    OrderList list = OrderFinder.findMany(orderIdAsString.in(ids));
    assertEquals(3, list.size());
}
 
Example 19
Source File: FeatureVectorsPartition.java    From oryx with Apache License 2.0 4 votes vote down vote up
public FeatureVectorsPartition() {
  vectors = UnifiedMap.newMap();
  recentIDs = UnifiedSet.newSet();
  lock = new AutoReadWriteLock();
}
 
Example 20
Source File: CacheIndexBasedFilter.java    From reladomo with Apache License 2.0 4 votes vote down vote up
private List<Pair<Extractor, Extractor>> setupIndexExtractors(Map<Attribute, Attribute> relationshipAttributes)
{
    List<Pair<Extractor, Extractor>> additionalKeyHolderAttributes = null;
    List orderedKeyHolderAttributes = FastList.newList();
    Attribute[] indexAttributes = cache.getIndexAttributes(this.indexReference.indexReference);
    List missingIndexAttributes = FastList.newList();
    Set<? extends Extractor> missingRelationshipAttributes = UnifiedSet.newSet(relationshipAttributes.keySet());

    for (Attribute indexAttribute : indexAttributes)
    {
        Attribute keyHolderAttribute = relationshipAttributes.get(indexAttribute);
        if (keyHolderAttribute == null)
        {
            if (indexAttribute.isAsOfAttribute())
            {
                orderedKeyHolderAttributes.add(new AlwaysTrueAsOfAttribute());
            }
            else
            {
                missingIndexAttributes.add(indexAttribute);
            }
        }
        else
        {
            orderedKeyHolderAttributes.add(keyHolderAttribute.isAsOfAttribute() ? new AlwaysTrueAsOfAttribute() : keyHolderAttribute);
            missingRelationshipAttributes.remove(indexAttribute);
        }
    }

    if (missingIndexAttributes.size() > 0)
    {
        throw new RuntimeException("Cannot use index since relationship " + this.description + " does not have these attributes mapped: " + missingIndexAttributes);
    }
    if (missingRelationshipAttributes.size() > 0)
    {
        logger.warn("Relationship " + this.description + "(" + relationshipAttributes + ") has to filter owners based on the additional attributes from keyHolder: " +
                missingRelationshipAttributes + " Not the most efficient relationship.");
        additionalKeyHolderAttributes = FastList.newList();
        for (Extractor each : missingRelationshipAttributes)
        {
            Attribute pairedAttribute = relationshipAttributes.get(each);
            if (each != null && pairedAttribute != null)
            {
                additionalKeyHolderAttributes.add(new Pair(each, pairedAttribute));
            }
        }
    }

    Extractor[] extractors = new Extractor[orderedKeyHolderAttributes.size()];
    orderedKeyHolderAttributes.toArray(extractors);
    this.keyHolderExtractors = extractors;

    return additionalKeyHolderAttributes;
}