Java Code Examples for org.eclipse.collections.impl.list.mutable.FastList#size()
The following examples show how to use
org.eclipse.collections.impl.list.mutable.FastList#size() .
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: MithraCompositeList.java From reladomo with Apache License 2.0 | 6 votes |
/** * convert multiple contained lists into one list and replace the contained lists with that list. * Synchronize to prevent changes to this list whilst this process is happening */ private void convertMultipleListsToFastList() { FastList<MithraFastList<E>> localLists = this.lists; if (localLists.size() > 1) { final MithraFastList<E> newList = new MithraFastList<E>(this.size()); for (int i = 0; i < localLists.size(); i++) { newList.addAll(localLists.get(i)); } FastList<MithraFastList<E>> newLists = new FastList<MithraFastList<E>>(2); newLists.add(newList); this.lists = newLists; } }
Example 2
Source File: AbstractTransactionalOperationBasedList.java From reladomo with Apache License 2.0 | 6 votes |
@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 3
Source File: MithraAbstractDatedDatabaseObject.java From reladomo with Apache License 2.0 | 6 votes |
private boolean processResultSetOneByOne(ResultSet res, FastList result, Object source, ObjectWithMapperStack[] asOfOpWithStacks, Cache cache, DatabaseType dt, int rowcount, TimeZone timeZone) throws SQLException { Timestamp[] asOfDates = this.getAsOfDates(); boolean reachedMaxRowCount = false; while (res.next()) { MithraDataObject newData = inflateDataGenericSource(res, source, dt); inflateAsOfDatesGenericSource(newData, res, getTotalColumnsInResultSet() + 1, asOfDates, asOfOpWithStacks, dt, timeZone); result.add(cache.getObjectFromData(newData, asOfDates)); if (rowcount > 0 && result.size() >= rowcount) { reachedMaxRowCount = true; break; } } return reachedMaxRowCount; }
Example 4
Source File: MultiEqualityOperation.java From reladomo with Apache License 2.0 | 6 votes |
private void parallelFilter(final boolean[] applied, MithraCompositeList mithraCompositeList) { final FastList<FastList> lists = mithraCompositeList.getLists(); CpuBoundTask[] tasks = new CpuBoundTask[lists.size()]; for(int i=0;i<lists.size();i++) { final FastList toFilter = lists.get(i); tasks[i] = new CpuBoundTask() { @Override public void execute() { filterResultsInPlace(applied, toFilter); } }; } new FixedCountTaskFactory(tasks).startAndWorkUntilFinished(); }
Example 5
Source File: FastUnsafeOffHeapDataStorage.java From reladomo with Apache License 2.0 | 6 votes |
private void bucketAllIncomingData(int currentMaxPage, FastList<FastUnsafeOffHeapPageBuffer> buffers, FastUnsafeOffHeapIntList toInsert, FastUnsafeOffHeapIntList toRemove, FastUnsafeOffHeapIntList toUpdate, FastUnsafeOffHeapIntList toNukeAndInsert, SyncLog syncLog) { for (int i = 0; i < buffers.size(); i++) { FastUnsafeOffHeapPageBuffer buffer = buffers.get(i); FastUnsafeOffHeapIntList masterPageIndicies = buffer.getMasterPageIndicies(); for (int bufferPageIndex = 0; bufferPageIndex < masterPageIndicies.size(); bufferPageIndex++) { int page = masterPageIndicies.get(bufferPageIndex); if (page <= currentMaxPage) { for (int pageDataIndex = 0; pageDataIndex < (1 << PAGE_POWER_OF_TWO); pageDataIndex++) { bucketIncomingData(toInsert, toRemove, toUpdate, toNukeAndInsert, buffer, bufferPageIndex, page, pageDataIndex); } } } } syncLog.setToInsertInExistingPages(toInsert.size()); syncLog.setToUpdateExisting(toUpdate.size()); syncLog.setToRemoveExisting(toRemove.size()); syncLog.setToNukeAndInsert(toNukeAndInsert.size()); }
Example 6
Source File: OrOperation.java From reladomo with Apache License 2.0 | 6 votes |
private List applyAtomicInPlace(FastList result, Operation[] atomic) { int currentFilledIndex = 0; for (int i = 0; i < result.size(); i++) { Object o = result.get(i); if (matches(o, atomic)) { // keep it if (currentFilledIndex != i) { result.set(currentFilledIndex, o); } currentFilledIndex++; } } this.resetTheEnd(result, currentFilledIndex); return result; }
Example 7
Source File: AndOperation.java From reladomo with Apache License 2.0 | 6 votes |
private static List applyAtomicInPlace(FastList result, Operation[] atomic) { int currentFilledIndex = 0; for (int i = 0; i < result.size(); i++) { Object o = result.get(i); Boolean matched = Boolean.TRUE; for (int j = 0; j < atomic.length && matched; j++) { Operation op = atomic[j]; matched = op.matches(o); if (matched == null) return null; } if (matched) { // keep it if (currentFilledIndex != i) { result.set(currentFilledIndex, o); } currentFilledIndex++; } } resetTheEnd(result, currentFilledIndex); return result; }
Example 8
Source File: RelationshipMultiEqualityOperation.java From reladomo with Apache License 2.0 | 6 votes |
private void parallelFilter(final boolean[] applied, MithraCompositeList mithraCompositeList) { final FastList<FastList> lists = mithraCompositeList.getLists(); CpuBoundTask[] tasks = new CpuBoundTask[lists.size()]; for(int i=0;i<lists.size();i++) { final FastList toFilter = lists.get(i); tasks[i] = new CpuBoundTask() { @Override public void execute() { filterResultsInPlace(applied, toFilter); } }; } new FixedCountTaskFactory(tasks).startAndWorkUntilFinished(); }
Example 9
Source File: MithraCompositeList.java From reladomo with Apache License 2.0 | 6 votes |
public void add(int index, E element) { int max = 0; FastList<MithraFastList<E>> localLists = this.lists; for (int i = 0; i < localLists.size(); i++) { List<E> list = localLists.get(i); int previousMax = max; max += list.size(); if (index <= max) { list.add(index - previousMax, element); return; } } throw new IndexOutOfBoundsException("No such element " + index + " size: " + this.size()); }
Example 10
Source File: TestCollections.java From reladomo with Apache License 2.0 | 6 votes |
public void testRebalance() { MithraFastList<Integer>[] lists = new MithraFastList[24]; int pos = 0; int totalSize = 1500000; for(int i=0;i<24;i++) { int size = i* 10000; lists[i] = new MithraFastList(size); for(; size > 0 && pos < totalSize; pos++, size--) { lists[i].add(pos); } } MithraCompositeList compositeList = new MithraCompositeList(lists); assertEquals(totalSize, compositeList.size()); FastList<MithraFastList<Integer>> balancedLists = compositeList.getLists(); assertEquals(totalSize, compositeList.size()); int maxIdealSize = (int) (totalSize*1.1/24); for(int i=0;i<balancedLists.size();i++) { assertTrue(balancedLists.get(i).size() <= maxIdealSize); } UnifiedSet<Integer> integers = new UnifiedSet<Integer>(compositeList); assertEquals(totalSize, integers.size()); }
Example 11
Source File: MithraCompositeList.java From reladomo with Apache License 2.0 | 5 votes |
public boolean add(final E object) { FastList<MithraFastList<E>> localLists = this.lists; if (localLists.size() == 0) { localLists.add(new MithraFastList<E>()); } Collection<E> list = localLists.getLast(); return list.add(object); }
Example 12
Source File: MithraCompositeList.java From reladomo with Apache License 2.0 | 5 votes |
/** * a llst iterator is a problem for a composite list as going back in the order of the list is an issue, * as are the other methods like set() and add() (and especially, remove). * Convert the internal lists to one list (if not already just one list) * and return that list's list iterator. * <p/> * AFAIK list iterator is only commonly used in sorting. * * @return a ListIterator for this, with internal state convertedto one list if needed. */ public ListIterator<E> listIterator(int index) { FastList<MithraFastList<E>> localLists = this.lists; if (localLists.size() == 1) { return localLists.getFirst().listIterator(index); } if (localLists.isEmpty()) { return Collections.EMPTY_LIST.listIterator(index); } this.convertMultipleListsToFastList(); return this.lists.getFirst().listIterator(index); }
Example 13
Source File: MithraCompositeList.java From reladomo with Apache License 2.0 | 5 votes |
public boolean retainAll(final Collection collection) { boolean changed = false; FastList<MithraFastList<E>> localLists = this.lists; for (int i = localLists.size() - 1; i >= 0; i--) { changed = (localLists.get(i).retainAll(collection) || changed); } return changed; }
Example 14
Source File: MithraCompositeList.java From reladomo with Apache License 2.0 | 5 votes |
public boolean remove(final Object object) { FastList<MithraFastList<E>> localLists = lists; for (int i = 0; i < localLists.size(); i++) { if (localLists.get(i).remove(object)) return true; } return false; }
Example 15
Source File: MultiThreadedTx.java From reladomo with Apache License 2.0 | 5 votes |
private boolean containsByCommitter(FastList all, XAResource res) { for(int i=0;i<all.size();i++) { XAResource other = ((TxGroup) all.get(i)).getResource(); if (res == other || res.equals(other)) return true; } return false; }
Example 16
Source File: MithraCompositeList.java From reladomo with Apache License 2.0 | 5 votes |
public boolean contains(final Object object) { FastList<MithraFastList<E>> localLists = lists; for (int i = 0; i < localLists.size(); i++) { if (localLists.get(i).contains(object)) return true; } return false; }
Example 17
Source File: OffHeapSemiUniqueDatedIndex.java From reladomo with Apache License 2.0 | 5 votes |
public List removeAll(Filter filter) { FastList result = new FastList(); int length = getDatedTableLength(); for (int i = 0; i < length; i++) { int cur = getDatedTableAt(i); if (isChainedBucket(cur)) { int chainRef = cur & ~UPPER_BIT_MASK; int sizeBefore = result.size(); ChainedBucket.removeDatedByFilter(storage, chainRef, dataStorage, filter, result, this); datedSize -= (result.size() - sizeBefore); if (ChainedBucket.getSize(storage, chainRef) == 0) { storage.free(chainRef); setDatedTableAt(i, FREE); } } else if (cur != FREE && filter.matches(dataStorage.getDataAsObject(cur))) { result.add(dataStorage.getDataAsObject(cur)); datedSize--; setDatedTableAt(i, FREE); removeNonDatedEntry(cur); } } return result; }
Example 18
Source File: TopLevelMergeOptions.java From reladomo with Apache License 2.0 | 5 votes |
private void ensureDependent(AbstractRelatedFinder arf) { DeepRelationshipAttribute parentAttribute = arf.getParentDeepRelationshipAttribute(); RelatedFinder finderInstance = this.getMetaData().getFinderInstance(); if (parentAttribute == null) { if (!finderInstance.getDependentRelationshipFinders().contains(arf)) { throw new MithraBusinessException("Can only navigate to dependent relationships! "+arf.getRelationshipName()+" is not a dependent"); } } FastList<AbstractRelatedFinder> list = FastList.newList(4); list.add(arf); while(parentAttribute != null) { list.add((AbstractRelatedFinder) parentAttribute); parentAttribute = parentAttribute.getParentDeepRelationshipAttribute(); } for(int i=list.size() - 1; i >=0; i--) { AbstractRelatedFinder child = list.get(i); if (!finderInstance.getDependentRelationshipFinders().contains(child)) { throw new MithraBusinessException("Can only navigate to dependent relationships! "+ child.getRelationshipName()+" is not a dependent"); } finderInstance = child; } }
Example 19
Source File: SimpleToOneDeepFetchStrategy.java From reladomo with Apache License 2.0 | 4 votes |
@Override public DeepFetchResult deepFetchFirstLinkInMemory(DeepFetchNode node) { List immediateParentList = getImmediateParentList(node); if (immediateParentList.size() == 0) { node.setResolvedList(ListFactory.EMPTY_LIST, chainPosition); return DeepFetchResult.nothingToDo(); } DeepFetchResult deepFetchResult = new DeepFetchResult(immediateParentList); MithraObjectPortal portal = this.getMapper().getFromPortal(); if (portal.isCacheDisabled()) { deepFetchResult.setPercentComplete(0); return deepFetchResult; } FullUniqueIndex fullResult = new FullUniqueIndex("identity", IDENTITY_EXTRACTORS); FastList notFound = new FastList(); 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 = this.addDefaultAsOfOp(op); CachedQuery oneResult = portal.zFindInMemory(op, null); if (oneResult == null) { notFound.add(from); } else { List result = oneResult.getResult(); for(int j=0;j<result.size();j++) { Object obj = result.get(j); fullResult.putUsingUnderlying(obj, obj); } } } LocalInMemoryResult localInMemoryResult = new LocalInMemoryResult(); localInMemoryResult.fullResult = fullResult; localInMemoryResult.notFound = notFound; deepFetchResult.setLocalResult(localInMemoryResult); int percentComplete = (immediateParentList.size() - notFound.size()) * 100 / immediateParentList.size(); if (notFound.size() > 0 && percentComplete == 100) { percentComplete = 99; } deepFetchResult.setPercentComplete(percentComplete); if (notFound.isEmpty()) { deepFetchResult.setResult(copyToList(fullResult)); if (deepFetchResult.hasNothingToDo()) { node.setResolvedList(ListFactory.EMPTY_LIST, chainPosition); } FastList parentList = localInMemoryResult.notFound; if (parentList.isEmpty()) { node.setResolvedList(localInMemoryResult.fullResult.getAll(), chainPosition); } } return deepFetchResult; }
Example 20
Source File: AbstractNonDatedCache.java From reladomo with Apache License 2.0 | 4 votes |
public void updateCache(List newDataList, List updatedDataList, List deletedData) { long start = 0; if (logger.isDebugEnabled()) { start = System.currentTimeMillis(); } Boolean lock = null; try { this.readWriteLock.acquireWriteLock(); lock = Boolean.TRUE; FastList checkToReindexList = new FastList(updatedDataList.size()); for (int i = 0; i < deletedData.size(); i++) { MithraObject object = (MithraObject) primaryKeyIndex.removeUsingUnderlying(deletedData.get(i)); if (object != null) { for (int j = 1; j < this.indices.length; j++) { Index index = this.indices[j]; index.remove(object); } this.markObjectAsDeleted(object); } } for (int i = 0; i < updatedDataList.size(); i++) { Object data = updatedDataList.get(i); MithraObject updatedObject = (MithraObject) primaryKeyIndex.getFromData(data); checkToReindexList.add(updatedObject); } ensureCapacity(primaryKeyIndex.size() + newDataList.size()); updateCacheForNewObjects(newDataList, updatedDataList, checkToReindexList); this.readWriteLock.release(); lock = null; for (int i = 0; i < checkToReindexList.size(); i++) { MithraObject obj = (MithraObject) checkToReindexList.get(i); obj.zReindexAndSetDataIfChanged((MithraDataObject) updatedDataList.get(i), this); } } finally { if (lock != null) { this.readWriteLock.release(); } } if (logger.isDebugEnabled()) { logger.debug("Cache update took "+(System.currentTimeMillis()-start)+" ms"); } }