Java Code Examples for org.eclipse.collections.impl.list.mutable.FastList#add()

The following examples show how to use org.eclipse.collections.impl.list.mutable.FastList#add() . 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: MithraAbstractPureObjectFactory.java    From reladomo with Apache License 2.0 6 votes vote down vote up
public List deserializeList(Operation op, ObjectInput in, boolean weak) throws IOException, ClassNotFoundException
{
    Cache cache = this.getMithraObjectPortal().getCache();
    int size = in.readInt();
    FastList result = new FastList(size);
    for(int i=0;i < size;i++)
    {
        MithraDataObject data = this.deserializeFullData(in);
        if (weak)
        {
            result.add(cache.getObjectFromDataWithoutCaching(data));
        }
        else
        {
            result.add(cache.getObjectFromData(data));
        }
    }
    return result;
}
 
Example 2
Source File: MithraAbstractPureDatedObjectFactory.java    From reladomo with Apache License 2.0 6 votes vote down vote up
public List deserializeList(Operation op, ObjectInput in, boolean weak) throws IOException, ClassNotFoundException
{
    Cache cache = this.getMithraObjectPortal().getCache();
    int size = in.readInt();
    FastList result = new FastList(size);
    Timestamp[] asOfDates = this.getAsOfDates();
    for(int i=0;i < size;i++)
    {
        MithraDataObject data = this.deserializeFullData(in);
        this.deserializeAsOfAttributes(in, asOfDates);
        if (weak)
        {
            result.add(cache.getObjectFromDataWithoutCaching(data, asOfDates));
        }
        else
        {
            result.add(cache.getObjectFromData(data, asOfDates));
        }
    }
    return result;
}
 
Example 3
Source File: AbstractTransactionalOperationBasedList.java    From reladomo with Apache License 2.0 6 votes vote down vote up
@Override
public boolean retainAll(DelegatingList<E> delegatingList, Collection<?> c)
{
    List list = resolveOperationAndCopy(delegatingList);
    FastList newList = FastList.newList(list.size());
    for(int i=0;i<list.size();i++)
    {
        Object item = list.get(i);
        if (c.contains(item))
        {
            newList.add(item);
        }
        else
        {
            this.removeHandler.removeRelatedObject((MithraObject) item);
        }
    }
    if (newList.size() < list.size())
    {
        getResolved(delegatingList).setResult(newList);
        return true;
    }
    return false;
}
 
Example 4
Source File: UniqueOffHeapIntIndex.java    From reladomo with Apache License 2.0 6 votes vote down vote up
public static List getAllAsList(OffHeapIntArrayStorage storage, int arrayRef, OffHeapDataStorage dataStorage)
{
    FastList result = FastList.newList(getSize(storage, arrayRef));
    int tableLength = getTableLength(storage, arrayRef);
    for (int i = 0; i < tableLength; i++)
    {
        int cur = getTableAt(storage, arrayRef, i);
        if (cur != FREE)
        {
            if ((cur & UPPER_BIT_MASK) == 0)
            {
                result.add(dataStorage.getDataAsObject(cur));
            }
            else
            {
                int chain = cur & ~UPPER_BIT_MASK;
                ChainedBucket.getAllAsListFromChain(storage, chain, result, dataStorage);
            }
        }
    }
    return result;

}
 
Example 5
Source File: AbstractDatedCache.java    From reladomo with Apache License 2.0 6 votes vote down vote up
private boolean getManyFromUniqueSequential(Extractor[] extractors, boolean abortIfNotFound, Timestamp[] asOfDates,
        MithraTransaction tx, FastList results, Iterator dataHolders, DatedSemiUniqueDataIndex uniqueIndex)
{
    CommonExtractorBasedHashingStrategy hashStrategy = uniqueIndex.getNonDatedPkHashStrategy();
    while(dataHolders.hasNext())
    {
        Object dataHolder = dataHolders.next();
        populateAsOfDates(extractors, dataHolder, asOfDates);
        MithraDataObject data = (MithraDataObject) uniqueIndex.getSemiUniqueAsOneWithDates(dataHolder,
                extractors, asOfDates, hashStrategy.computeHashCode(dataHolder, extractors));
        if (data != null)
        {
            MithraDatedObject businessObject = this.getBusinessObjectFromData(data, asOfDates, getNonDatedPkHashCode(data), false, tx, true);
            if (businessObject == null)
            {
                return true;
            }
            results.add(businessObject);
        }
        else
        {
            if (abortIfNotFound) return true;
        }
    }
    return false;
}
 
Example 6
Source File: AbstractNonDatedTransactionalCache.java    From reladomo with Apache License 2.0 6 votes vote down vote up
@Override
protected void updateCacheForNewObjects(List newDataList, List updatedDataList, FastList checkToReindexList)
{
    NonNullMutableBoolean isDirty = new NonNullMutableBoolean();
    for (int i = 0; i < newDataList.size(); i++)
    {
        MithraDataObject data = (MithraDataObject) newDataList.get(i);
        MithraObject newObject = this.getFromDataByPrimaryKeyForCreation(data, isDirty);
        if (newObject == null)
        {
            newObject = this.getFactory().createObject(data);
            addToIndicesUnderLockAfterCreate(newObject, false);
        }
        else
        {
            if (isDirty.value)
            {
                addToIndicesUnderLockAfterCreate(newObject, false);
            }
            updatedDataList.add(data);
            checkToReindexList.add(newObject);
        }
    }
}
 
Example 7
Source File: ChainedDeepFetchStrategy.java    From reladomo with Apache License 2.0 6 votes vote down vote up
@Override
public List deepFetchAdhocUsingTempContext(DeepFetchNode node, TupleTempContext tempContext, Object parentPrototype, List immediateParentList)
{
    //todo: make sure allocation doesn't happen twice!!!
    node.allocatedChainedResults(chainedStrategies.size());
    FastList result = new FastList(chainedStrategies.size());
    for(int i=0;i<chainedStrategies.size();i++)
    {
        List list = ((DeepFetchStrategy) chainedStrategies.get(i)).deepFetchAdhocUsingTempContext(node, tempContext, parentPrototype, immediateParentList);
        if (list == null)
        {
            node.setResolvedList(ListFactory.EMPTY_LIST, i);
        }
        else
        {
            result.add(list);
        }
    }
    return result;
}
 
Example 8
Source File: FullSemiUniqueDatedIndex.java    From reladomo with Apache License 2.0 6 votes vote down vote up
public List removeAll(Filter filter)
{
    FastList result = new FastList();
    Object[] tab = this.datedTable;
    for (int i = 0; i < tab.length; i++)
    {
        Object e = tab[i];
        if (e instanceof ChainedBucket)
        {
            removeAllFromChained((ChainedBucket)e, i, result, filter);
        }
        else if (e != null && filter.matches(e))
        {
            result.add(e);
            datedSize--;
            tab[i] = null;
            removeNonDatedEntry(e);
        }
    }
    return result;
}
 
Example 9
Source File: AbstractNonDatedCache.java    From reladomo with Apache License 2.0 6 votes vote down vote up
private void updateCacheForNewObjectAsDataObject(List newDataList, List updatedDataList, FastList checkToReindexList)
{
    NonNullMutableBoolean isDirty = new NonNullMutableBoolean();
    for (int i = 0; i < newDataList.size(); i++)
    {
        MithraDataObject dataObject = (MithraDataObject) newDataList.get(i);
        MithraObject oldObject = (MithraObject) this.primaryKeyIndex.getFromDataEvenIfDirty(dataObject, isDirty);
        if (oldObject == null)
        {
            addToIndicesUnderLockAfterCreate(this.getFactory().createObject(dataObject), false);
        }
        else
        {
            if (isDirty.value)
            {
                addToIndicesUnderLockAfterCreate(oldObject, false);
            }
            updatedDataList.add(dataObject);
            checkToReindexList.add(oldObject);
        }
    }
}
 
Example 10
Source File: AbstractDatedCache.java    From reladomo with Apache License 2.0 5 votes vote down vote up
private List matchAsOfDatesForList(Timestamp[] asOfDates, List list, Extractor[] extractors, int startIndex)
{
    // this is not parallelized because if an index keeps a list, it's guaranteed to be tiny
    FastList result = FastList.newList(list.size());
    for (int i = 0; i < list.size(); i++)
    {
        Object o = list.get(i);
        if (matchesAsOfAttributes(asOfDates, o, extractors, startIndex))
        {
            result.add(o);
        }
    }
    return result;
}
 
Example 11
Source File: SerializationNode.java    From reladomo with Apache License 2.0 5 votes vote down vote up
private static FastList<Attribute> unwrapAttributes(Attribute[] persistentAttributes)
{
    FastList<Attribute> list = FastList.newList(persistentAttributes.length);
    for(Attribute a: persistentAttributes)
    {
        list.add(unwrapAttribute(a));
    }
    return list;
}
 
Example 12
Source File: SerializationNode.java    From reladomo with Apache License 2.0 5 votes vote down vote up
private static void fillDefaultAttributes(RelatedFinder finder, SerializationNode result)
{
    FastList<Attribute> attributes = unwrapAttributes(finder.getPersistentAttributes());
    AsOfAttribute[] asOfAttributes = finder.getAsOfAttributes();
    if (asOfAttributes != null)
    {
        for(AsOfAttribute a: asOfAttributes)
        {
            attributes.add(unwrapAttribute(a));
        }
    }
    result.attributes = attributes;
}
 
Example 13
Source File: RemoteCursorResult.java    From reladomo with Apache License 2.0 5 votes vote down vote up
public void doWork()
{
    if (closed) return;
    try
    {
        if (markedForClosure)
        {
            forceClose();
            return;
        }
        FastList list = new FastList();
        for (int i = 0; i < BATCH_SIZE && cursor.hasNext() && !markedForClosure; i++)
        {
            list.add(cursor.next());
        }
        queueResult(list);
        if (!cursor.hasNext() || markedForClosure)
        {
            forceClose();
        }
    }
    catch (Throwable e)
    {
        this.error = e;
        forceClose();
    }
}
 
Example 14
Source File: PartialUniqueIndex.java    From reladomo with Apache License 2.0 5 votes vote down vote up
public List removeAll(Filter filter)
{
    FastList result = new FastList();
    for (int i = 0; i < table.length; i++)
    {
        Entry prev = table[i];
        Entry e = prev;
        while (e != null)
        {
            Entry next = e.next;
            Object candidate = e.get();
            if (candidate == null || filter.matches(candidate))
            {
                if (candidate != null)
                {
                    result.add(candidate);
                }
                size--;
                if (prev == e)
                {
                    table[i] = next;
                    prev = next;
                }
                else
                    prev.next = next;
            }
            else
            {
                prev = e;
            }
            e = next;
        }
    }
    return result;
}
 
Example 15
Source File: AbstractDatedCache.java    From reladomo with Apache License 2.0 5 votes vote down vote up
private boolean getManyPerDataFromUnique(Extractor[] extractors, boolean abortIfNotFound, Timestamp[] asOfDates, MithraTransaction tx, Index index, FastList results, Iterator dataHolders)
{
    while(dataHolders.hasNext())
    {
        Object dataHolder = dataHolders.next();
        populateAsOfDates(extractors, dataHolder, asOfDates);
        MithraDataObject data = (MithraDataObject) index.get(dataHolder, extractors);
        if (data == null)
        {
            if (abortIfNotFound) return true;
        }
        else
        {
            this.extractTimestampsFromData(data, extractors, asOfDates);
            if (this.matchesAsOfDates(data, asOfDates))
            {
                MithraDatedObject businessObject = this.getBusinessObjectFromData(data, asOfDates, getNonDatedPkHashCode(data), false, tx, true);
                if (businessObject == null)
                {
                    return true;
                }
                results.add(businessObject);
            }
            else
            {
                if (abortIfNotFound) return true;
            }
        }
    }
    return false;
}
 
Example 16
Source File: PartialPrimaryKeyIndex.java    From reladomo with Apache License 2.0 5 votes vote down vote up
public List getAll()
{
    FastList result = new FastList(this.size());
    for (int i = 0; i < table.length; i++)
    {
        Entry e = table[i];
        while (e != null)
        {
            Object candidate = e.get();
            if (candidate != null && !e.getState().isDirty(timeToLive)) result.add(candidate);
            e = e.getState().next;
        }
    }
    return result;
}
 
Example 17
Source File: SerializableMethodCache.java    From reladomo with Apache License 2.0 5 votes vote down vote up
private List<Method> findMethods(Class clazz, Set<Class> contextNames)
{
    Method[] allMethods = clazz.getMethods();
    FastList<Method> result = FastList.newList();
    for(Method method: allMethods)
    {
        ReladomoSerialize annotation = method.getAnnotation(ReladomoSerialize.class);
        if (annotation != null)
        {
            Class[] names = annotation.serialViews();
            for (Class name : names)
            {
                if (contextNames.contains(name))
                {
                    if (method.getParameterTypes().length == 0)
                    {
                        if (method.getReturnType().equals(Void.TYPE))
                        {
                            logger.warn("Incorrect method annotation in class " + clazz.getName() + " method " + method.getName() + " @ReladomoSerialize can only be used with methods that return something");
                        }
                        else
                        {
                            result.add(method);
                            break;
                        }
                    }
                    else
                    {
                        logger.warn("Incorrect method annotation in class " + clazz.getName() + " method " + method.getName() + " @ReladomoSerialize can only be used with methods that have no parameters");
                    }
                }
            }
        }
    }
    result.trimToSize();
    result.sortThis(METHOD_NAME_COMPARATOR);
    return result;
}
 
Example 18
Source File: PartialWeakUniqueIndex.java    From reladomo with Apache License 2.0 5 votes vote down vote up
public List getAll()
{
    FastList result = new FastList(this.size());
    for (int i = 0; i < table.length; i++)
    {
        Entry e = table[i];
        while (e != null)
        {
            Object candidate = e.get();
            if (candidate != null && (timeToLive == 0 || !((TimedEntry)e).isExpired(timeToLive))) result.add(candidate);
            e = e.next;
        }
    }
    return result;
}
 
Example 19
Source File: FullSemiUniqueDatedIndex.java    From reladomo with Apache License 2.0 4 votes vote down vote up
private void removeAllFromChained(ChainedBucket chainedBucket, int index, FastList result, Filter filter)
{
    ChainedBucket bucket = chainedBucket;
    int pos = 0;
    do
    {
        while (bucket.zero != null && filter.matches(bucket.zero))
        {
            datedSize--;
            result.add(bucket.zero);
            removeNonDatedEntry(bucket.zero);
            chainedBucket.remove(pos);
        }
        if (bucket.one == null) break;
        pos++;
        while (bucket.one != null && filter.matches(bucket.one))
        {
            datedSize--;
            result.add(bucket.one);
            removeNonDatedEntry(bucket.one);
            chainedBucket.remove(pos);
        }
        if (bucket.two == null) break;
        pos++;
        while (bucket.two != null && filter.matches(bucket.two))
        {
            datedSize--;
            result.add(bucket.two);
            removeNonDatedEntry(bucket.two);
            chainedBucket.remove(pos);
        }
        if (bucket.three == null) break;
        pos++;
        if (bucket.three instanceof ChainedBucket)
        {
            bucket = (ChainedBucket) bucket.three;
            continue;
        }
        while (bucket.three != null && filter.matches(bucket.three))
        {
            datedSize--;
            result.add(bucket.three);
            removeNonDatedEntry(bucket.three);
            chainedBucket.remove(pos);
        }
        break;
    } while(true);
    if (chainedBucket.zero == null)
    {
        this.datedTable[index] = null;
    }
}
 
Example 20
Source File: UpdateOperation.java    From reladomo with Apache License 2.0 4 votes vote down vote up
public UpdateOperation(MithraTransactionalObject mithraObject, AttributeUpdateWrapper first)
{
    super(mithraObject, first.getAttribute().getOwnerPortal());
    updates = new FastList(3);
    updates.add(first);
}