Java Code Examples for org.eclipse.collections.impl.map.mutable.UnifiedMap#put()

The following examples show how to use org.eclipse.collections.impl.map.mutable.UnifiedMap#put() . 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: OffHeapFreeThread.java    From reladomo with Apache License 2.0 6 votes vote down vote up
private Map<Thread, StackTraceElement[]> getStackTracesForRelevantThreads()
{
    UnifiedMap<Thread, StackTraceElement[]> result = UnifiedMap.newMap();
    for (int i = 0; i < toFree.size(); i++)
    {
        OffHeapThreadSnapShot snapShot = toFree.get(i);
        for (Iterator<Thread> it = snapShot.activeThreads.keySet().iterator(); it.hasNext(); )
        {
            Thread thread = it.next();
            if (!thread.getState().equals(State.RUNNABLE))
            {
                it.remove();
            }
            else if (!result.containsKey(thread))
            {
                result.put(thread, thread.getStackTrace());
            }
        }
    }
    return result;
}
 
Example 2
Source File: ExtractResult.java    From reladomo with Apache License 2.0 6 votes vote down vote up
public Map<Pair<RelatedFinder, Object>, List<MithraDataObject>> getDataObjectsByFinderAndSource()
{
    UnifiedMap<Pair<RelatedFinder, Object>, List<MithraDataObject>> result = UnifiedMap.newMap(this.dataObjectsByFinder.size());
    for (MithraObject key : this.dataObjectsByFinder.keySet())
    {
        FullUniqueIndex mithraObjects = this.dataObjectsByFinder.get(key);
        RelatedFinder finder = finder(key);
        Object source = source(key);
        List<MithraDataObject> mithraDataObjects = FastList.newList(mithraObjects.size());
        for (Object mithraObject : mithraObjects.getAll())
        {
            mithraDataObjects.add(((MithraObject) mithraObject).zGetCurrentData());
        }
        result.put(Pair.of(finder, source), mithraDataObjects);
    }
    return result;
}
 
Example 3
Source File: RemoteBatchInsertResult.java    From reladomo with Apache License 2.0 6 votes vote down vote up
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
{
    this.readRemoteTransactionId(in);
    int dbIdSize = in.readInt();
    databaseIdentifierMap = new UnifiedMap(dbIdSize);
    for(int i = 0; i < dbIdSize; i++)
    {
        String finderClassname = (String)in.readObject();
        RelatedFinder finderClass = this.instantiateRelatedFinder(finderClassname);
        Object sourceAttributeValue = in.readObject();
        String databaseIdentifier = (String) in.readObject();

        MithraDatabaseIdentifierExtractor.DatabaseIdentifierKey key =
                new MithraDatabaseIdentifierExtractor.DatabaseIdentifierKey(sourceAttributeValue, finderClass);
        databaseIdentifierMap.put(key, databaseIdentifier);
    }
}
 
Example 4
Source File: RemoteExtractListDatabaseIdentifiersResult.java    From reladomo with Apache License 2.0 6 votes vote down vote up
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
{
    int dbIdSize = in.readInt();
    databaseIdentifierMap = new UnifiedMap(dbIdSize);
    for(int i = 0; i < dbIdSize; i++)
    {
        String finderClassname = (String)in.readObject();
        RelatedFinder finderClass = instantiateRelatedFinder(finderClassname);
        Object sourceAttributeValue = in.readObject();
        String databaseIdentifier = (String) in.readObject();

        MithraDatabaseIdentifierExtractor.DatabaseIdentifierKey key =
                new MithraDatabaseIdentifierExtractor.DatabaseIdentifierKey(sourceAttributeValue, finderClass);
        databaseIdentifierMap.put(key, databaseIdentifier);
    }

}
 
Example 5
Source File: ForEachPatternUnitTest.java    From tutorials with MIT License 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
public void whenInstantiateAndChangeValues_thenCorrect() {
    Pair<Integer, String> pair1 = Tuples.pair(1, "One");
    Pair<Integer, String> pair2 = Tuples.pair(2, "Two");
    Pair<Integer, String> pair3 = Tuples.pair(3, "Three");

    UnifiedMap<Integer, String> map = UnifiedMap.newMapWith(pair1, pair2, pair3);

    for (int i = 0; i < map.size(); i++) {
        map.put(i + 1, "New Value");
    }

    for (int i = 0; i < map.size(); i++) {
        Assert.assertEquals("New Value", map.get(i + 1));
    }
}
 
Example 6
Source File: DbExtractor.java    From reladomo with Apache License 2.0 5 votes vote down vote up
private void indexDataObjects(RelatedFinder finder, List<MithraDataObject> dataObjects, UnifiedMap<RelatedFinder, NonUniqueIndex> indexByFinder)
{
    NonUniqueIndex index = indexByFinder.get(finder);
    if (index == null)
    {
        index = new NonUniqueIndex("", getSourcelessPrimaryKeyWithFromAttributes(finder), getPrimaryKeyAttributesWithNoSource(finder), DEFAULT_INDEX_SIZE);
        indexByFinder.put(finder, index);
    }
    for (MithraDataObject data : dataObjects)
    {
        index.put(data);
    }
}
 
Example 7
Source File: TransitivePropagator.java    From reladomo with Apache License 2.0 5 votes vote down vote up
private UnifiedMap<MapperStack, InternalList> createOperationsToInsert()
{
    UnifiedMap<MapperStack, InternalList> operationsWithMapperStackToInsert = new UnifiedMap<MapperStack, InternalList>();

    for(Iterator<ObjectWithMapperStack<Attribute>> it = equalityMap.keySet().iterator(); it.hasNext();)
    {
        ObjectWithMapperStack<Attribute> attributeWithStack = it.next();
        if (existingOperationsWithMapperStack.get(attributeWithStack) == null)
        {
            for(Iterator<ObjectWithMapperStack<Attribute>> candidateIt = equalityMap.get(attributeWithStack).iterator(); candidateIt.hasNext();)
            {
                AtomicOperation otherOp = existingOperationsWithMapperStack.get(candidateIt.next());
                if (otherOp != null)
                {
                    Operation toInsert = otherOp.susbtituteOtherAttribute(attributeWithStack.getObject());
                    if (toInsert != null)
                    {
                        InternalList insertList = operationsWithMapperStackToInsert.get(attributeWithStack.getMapperStack());
                        if (insertList == null)
                        {
                            insertList = new InternalList(2);
                            operationsWithMapperStackToInsert.put(attributeWithStack.getMapperStack(), insertList);
                        }
                        insertList.add(toInsert);
                        //todo: instead of breaking here, we could pick the best operation out of several possible
                        break;
                    }
                }
            }
        }
    }
    return operationsWithMapperStackToInsert;
}
 
Example 8
Source File: SimpleToOneDeepFetchStrategy.java    From reladomo with Apache License 2.0 5 votes vote down vote up
protected void populateOpToListMapWithEmptyList(List immediateParentList, HashMap<Operation, List> opToListMap, UnifiedMap<Operation, Object> opToParentMap)
{
    Map<Attribute, Object> tempOperationPool = new UnifiedMap();
    for (int i = 0; i < immediateParentList.size(); i++)
    {
        Object from = immediateParentList.get(i);
        Operation op = this.mapper.getOperationFromOriginal(from, tempOperationPool);
        op = addDefaultAsOfOp(op);
        if (opToListMap.put(op, ListFactory.EMPTY_LIST) == null)
        {
            opToParentMap.put(op, from);
        }
    }
}
 
Example 9
Source File: MultiEqualityOperation.java    From reladomo with Apache License 2.0 5 votes vote down vote up
private ShapeMatchResult complexShapeMatch(MultiEqualityOperation existingOp)
{
    UnifiedMap<Attribute, AtomicOperation> attrOpMap = new UnifiedMap(existingOp.getEqualityOpCount());
    for(AtomicOperation ao: existingOp.atomicOperations)
    {
        attrOpMap.put(ao.getAttribute(), ao);
    }
    int lookupCount = 0;
    AtomicOperation[] forLookup = new AtomicOperation[this.getEqualityOpCount()];
    for(AtomicOperation eo: this.atomicOperations)
    {
        AtomicOperation matching = attrOpMap.get(eo.getAttribute());
        if (matching != null)
        {
            ShapeMatchResult shapeMatchResult = eo.zShapeMatch(matching);
            if (shapeMatchResult.isExactMatch())
            {
                forLookup[lookupCount++] = eo;
            }
            else if (shapeMatchResult.isSuperMatch())
            {
                forLookup[lookupCount++] = (AtomicOperation) ((SuperMatchSmr)shapeMatchResult).getLookUpOperation();
            }
            else //NoMatch
            {
                return shapeMatchResult;
            }
        }
        else
        {
            return NoMatchSmr.INSTANCE;
        }
    }
    return new SuperMatchSmr(existingOp, this, new MultiEqualityOperation(forLookup), this); // todo: can optimize filterOperation

}
 
Example 10
Source File: OutgoingAsyncTopicTest.java    From reladomo with Apache License 2.0 5 votes vote down vote up
@Test
public void testSendSetsProperties() throws NamingException, JMSException, RollbackException, RestartTopicException, XAException
{
    mithraTransaction = topicResourcesWithTransactionXid.startTransaction();

    UnifiedMap<String, Object> msgProperties = UnifiedMap.<String, Object>newMap();
    msgProperties.put("Hello", "World");
    Future<Void> voidFuture = outTopic.asyncSendMessages(FastList.newListWith("msg1".getBytes()), msgProperties);
    topicResourcesWithTransactionXid.commit(mithraTransaction, FastList.<Future>newListWith(voidFuture), FastList.<JmsTopic>newList());

    Message messageRecvd = incomingTopic.receive(100);
    assertEquals("msg1", JmsUtil.getMessageBodyAsString(messageRecvd));
    assertEquals("World", messageRecvd.getStringProperty("Hello"));
}
 
Example 11
Source File: OutgoingAsyncTopicTest.java    From reladomo with Apache License 2.0 5 votes vote down vote up
@Test
public void testSendSetsPropertiesAsync() throws NamingException, JMSException, RollbackException, RestartTopicException, XAException
{
    mithraTransaction = topicResourcesWithTransactionXid.startTransaction();

    UnifiedMap<String, Object> msgProperties = UnifiedMap.<String, Object>newMap();
    msgProperties.put("Hello", "World");
    Future<Void> voidFuture = asyncOutTopic.asyncSendMessages(FastList.newListWith("msg1".getBytes()), msgProperties);
    topicResourcesWithTransactionXid.commit(mithraTransaction, FastList.<Future>newListWith(voidFuture), FastList.<JmsTopic>newList());

    Message messageRecvd = incomingTopic.receive(100);
    assertEquals("msg1", JmsUtil.getMessageBodyAsString(messageRecvd));
    assertEquals("World", messageRecvd.getStringProperty("Hello"));
}
 
Example 12
Source File: CachingRegistry.java    From camunda-bpm-reactor with Apache License 2.0 5 votes vote down vote up
@Override
public List<Registration<K, ? extends V>> select(K key) {
  // use a thread-local cache
  UnifiedMap<Object, List<Registration<K, ? extends V>>> allRegs = threadLocalRegs();

  // maybe pull Registrations from cache for this key
  List<Registration<K, ? extends V>> selectedRegs = null;
  if (useCache && (null != (selectedRegs = allRegs.get(key)))) {
    return selectedRegs;
  }

  // cache not used or cache miss
  cacheMiss(key);
  selectedRegs = FastList.newList();

  // find Registrations based on Selector
  for (Registration<K, ? extends V> reg : this) {
    if (reg.getSelector().matches(key)) {
      selectedRegs.add(reg);
    }
  }
  if (useCache && (!selectedRegs.isEmpty() || cacheNotFound)) {
    allRegs.put(key, selectedRegs);
  }

  // nothing found, maybe invoke handler
  if (selectedRegs.isEmpty() && (null != onNotFound)) {
    onNotFound.accept(key);
  }

  // return
  return selectedRegs;
}