org.eclipse.collections.impl.list.mutable.FastList Java Examples
The following examples show how to use
org.eclipse.collections.impl.list.mutable.FastList.
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: FlatCollectUnitTest.java From tutorials with MIT License | 6 votes |
@Before public void setup() { String address1 = "73 Pacific St., Forest Hills, NY 11375"; String address2 = "93 Bayport Ave., South Richmond Hill, NY 11419"; String address3 = "548 Market St, San Francisco, CA 94104"; String address4 = "8605 Santa Monica Blvd, West Hollywood, CA 90069"; this.addresses1 = FastList.newListWith(address1, address2); this.addresses2 = FastList.newListWith(address3, address4); Student student1 = new Student("John", "Hopkins", addresses1); Student student2 = new Student("George", "Adams", addresses2); this.addresses2 = FastList.newListWith(address3, address4); this.students = FastList.newListWith(student1, student2); this.expectedAddresses = new ArrayList<>(); this.expectedAddresses.add("73 Pacific St., Forest Hills, NY 11375"); this.expectedAddresses.add("93 Bayport Ave., South Richmond Hill, NY 11419"); this.expectedAddresses.add("548 Market St, San Francisco, CA 94104"); this.expectedAddresses.add("8605 Santa Monica Blvd, West Hollywood, CA 90069"); }
Example #2
Source File: AbstractNonDatedCache.java From reladomo with Apache License 2.0 | 6 votes |
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 #3
Source File: UniqueOffHeapIntIndex.java From reladomo with Apache License 2.0 | 6 votes |
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 #4
Source File: FullSemiUniqueDatedIndex.java From reladomo with Apache License 2.0 | 6 votes |
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 #5
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 #6
Source File: BusinessDateFilterTest.java From reladomo with Apache License 2.0 | 6 votes |
public void testFilter() { String testConfiguration = "<CacheLoader>\n" + " <TopLevelLoader classToLoad=\"" + LEWCOTRACT_CLASS + "\" sourceAttributes=\"NYK,LN2\"/>\n" + " <DependentLoader relationship=\"" + LEWCOTRACT_CLASS + ".scrp\"/>\n" + "</CacheLoader>"; CacheLoaderManagerImpl cacheLoaderManager = new CacheLoaderManagerImpl(); cacheLoaderManager.loadConfiguration(new ByteArrayInputStream(testConfiguration.getBytes())); Map<String, BooleanFilter> map = cacheLoaderManager.createCacheFilterOfDatesToKeep(FastList.newListWith(DATE1, DATE2)); Filter filter = map.get(LEWCOTRACT_CLASS); assertFalse(filter.matches(buildContract(DATE1, DATE2))); assertFalse(filter.matches(buildContract(DATE2, DATE3))); assertTrue(filter.matches(buildContract(DATE3, DATE4))); filter = map.get(SCRP_CLASS); assertFalse(filter.matches(buildScrp(DATE1, DATE2))); assertTrue(filter.matches(buildScrp(DATE3, DATE4))); }
Example #7
Source File: CacheLoaderManagerTest.java From reladomo with Apache License 2.0 | 6 votes |
public void testInitialLoadWithTwoDatesWithinRangeWithDependentAdditionalOperationBuilderThatIsDateVariant() { assertCacheEmpty(); CacheLoaderMonitor loaderMonitor = runInitialLoad("<CacheLoader>\n" + " <TopLevelLoader classToLoad=\"com.gs.fw.common.mithra.test.glew.LewContract\" sourceAttributes=\"LN1\"/>\n" + " <DependentLoader relationship=\"com.gs.fw.common.mithra.test.glew.LewContract.lewTransaction\">\n" + " <Param name=\"operationBuilder\" value=\"com.gs.fw.common.mithra.test.cacheloader.SmallInstrumentIdsOnlyBeforeMilestoneDateAdditionalOperationBuilder\"/>" + " </DependentLoader>\n" + "</CacheLoader>", FastList.newListWith(MULTI_DATE_1_IN_RANGE_A, MULTI_DATE_2_IN_RANGE_A)); assertListContainsExactly(LewContractFinder.findMany(allContractsOperation()), LewContractFinder.instrumentId(), 1, 7, 7); assertListContainsExactly(LewTransactionFinder.findMany(allTransactionsOperation()), LewTransactionFinder.tradeQty(), 20.0); assertNull(loaderMonitor.getException()); assertEquals("TopLevel should be loaded in date range config", 1, loaderMonitor.getLoadingTaskStates().size()); assertEquals("Dependent should be force loaded in single date config", 2, loaderMonitor.getDependentKeyIndexMonitors().size()); }
Example #8
Source File: MithraRuntimeConfigVerifier.java From reladomo with Apache License 2.0 | 6 votes |
public void verifyClasses() { List<String> errors = FastList.newList(); this.verifyConnectionManagers(this.mithraRuntime.getConnectionManagers(), errors); if (this.mithraRuntime.getPureObjects() != null) { this.verifyPureObjects(this.mithraRuntime.getPureObjects().getMithraObjectConfigurations(), errors); } this.verifyRemoteServers(this.mithraRuntime.getRemoteServers(), errors); if (errors.size() > 0) { StringBuilder allErrors = new StringBuilder(errors.size() * 20); for(String error: errors) { allErrors.append('\n').append(error); } Assert.fail("Runtime configuration failed with the following errors:"+allErrors); } }
Example #9
Source File: AbstractNonDatedCache.java From reladomo with Apache License 2.0 | 6 votes |
private List wrapObjectInList(Object o) { if (o == null) { return ListFactory.EMPTY_LIST; } if (o instanceof List) { return new FastList((List)o); // must copy so that if the underlying list is changed the previous result stays the same } if (o instanceof FullUniqueIndex) { return ((FullUniqueIndex) o).getAll(); } return ListFactory.create(o); }
Example #10
Source File: CacheReplicationTestCase.java From reladomo with Apache License 2.0 | 6 votes |
public List<Long> getPageVersionList(Class finderClass) throws Exception { MithraRuntimeCacheController cc = new MithraRuntimeCacheController(finderClass); AbstractDatedCache cache = (AbstractDatedCache) cc.getFinderInstance().getMithraObjectPortal().getCache(); // This is a hack to access private methods to get at the off-heap storage and page version list which we need for this test. // On balance this is less bad than making these internals public to the entire world. Method zGetDataStorage = AbstractDatedCache.class.getDeclaredMethod("zGetDataStorage"); zGetDataStorage.setAccessible(true); FastUnsafeOffHeapDataStorage storage = (FastUnsafeOffHeapDataStorage) zGetDataStorage.invoke(cache); Method zGetPageVersionList = FastUnsafeOffHeapDataStorage.class.getDeclaredMethod("zGetPageVersionList"); zGetPageVersionList.setAccessible(true); FastUnsafeOffHeapLongList pageVersionList = (FastUnsafeOffHeapLongList) zGetPageVersionList.invoke(storage); List<Long> listCopy = FastList.newList(pageVersionList.size()); for (int i = 0; i < pageVersionList.size(); i++) { listCopy.add(pageVersionList.get(i)); } return listCopy; }
Example #11
Source File: ChainedDeepFetchStrategy.java From reladomo with Apache License 2.0 | 6 votes |
@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 #12
Source File: MithraObjectGraphExtractor.java From reladomo with Apache License 2.0 | 6 votes |
private List<RelatedFinder> getRelationships(RelatedFinder relatedFinder, Set<RelatedFinder> toManyRelationships) { List allRelationships = relatedFinder.getRelationshipFinders(); List<RelatedFinder> interestingRelationships = FastList.newList(allRelationships.size()); for (Object object : allRelationships) { AbstractRelatedFinder relationship = AbstractRelatedFinder.class.cast(object); boolean notIgnored = !ignored.contains(relationship); boolean isToOneOrFirstToMany = relationship.isToOne() || toManyRelationships.isEmpty(); if (notIgnored && isToOneOrFirstToMany) { interestingRelationships.add(relationship); } } return interestingRelationships; }
Example #13
Source File: MilestoneRectangle.java From reladomo with Apache License 2.0 | 6 votes |
public static List<MilestoneRectangle> fromMithraData(RelatedFinder finder, List mithraData) { AsOfAttribute[] asOfAttributes = finder.getAsOfAttributes(); List<MilestoneRectangle> rectangles = FastList.newList(); for (Object data : mithraData) { rectangles.add(new MilestoneRectangle(data, asOfAttributes)); } if (MilestoneRectangle.merge(rectangles).size() != rectangles.size()) { MithraDataObject dataObject = (MithraDataObject) rectangles.get(0).data; LOGGER.warn("Invalid milestoning of " + dataObject.getClass().getSimpleName() + '[' + dataObject.zGetPrintablePrimaryKey() + ']'); } return rectangles; }
Example #14
Source File: CacheReplicationTestCase.java From reladomo with Apache License 2.0 | 6 votes |
public void serverTestDeleteInsert() { forceGC(); List<BitemporalOrderData> insertList = FastList.newList(11111); for(int i=0;i<11111;i++) { insertList.add(createBigOrder(i + 300000)); } List<BitemporalOrderData> deleteList = FastList.newList(11111); for(int i=1503;i<102000;i+=2048) { BitemporalOrderData order = createBigOrder(i); deleteList.add(order); } MithraRuntimeCacheController cc = new MithraRuntimeCacheController(BitemporalOrderFinder.class); cc.getMithraObjectPortal().getCache().updateCache(insertList, Collections.EMPTY_LIST, deleteList); System.out.println("deleted/inserted objects on master"); }
Example #15
Source File: AbstractLoaderFactory.java From reladomo with Apache License 2.0 | 6 votes |
protected List<AdditionalOperationBuilder> getAdditionalOperationBuilders(String classToLoad, CacheLoaderContext context) { List<AdditionalOperationBuilder> builders = FastList.newList(); AdditionalOperationBuilder limitedOperationBuilder = context.getQualifiedLoadContext().getAdditionalOperationBuilder(classToLoad); if (limitedOperationBuilder != null) { builders.add(limitedOperationBuilder); } List<String> operationBuilderClassNames = this.getParamValuesNamed("operationBuilder"); if (operationBuilderClassNames == null || operationBuilderClassNames.size() == 0) { return builders; } for (String name : operationBuilderClassNames) { builders.add((AdditionalOperationBuilder) CacheLoaderConfig.newInstance(name)); } return builders; }
Example #16
Source File: LoadingTaskImpl.java From reladomo with Apache License 2.0 | 6 votes |
public void putOnDependentQueues(MithraObject keyHolder) { this.newOrChangedCount++; if (this.dependentKeyIndices.isEmpty() || !this.needDependentLoaders) { return; } this.stripe.add(keyHolder.zGetCurrentData()); this.dependentKeyIndices.get(0).getCacheLoaderEngine().changeStripedCount(this.dependentKeyIndices.size()); if (this.stripe.size() == QUEUE_STRIPE_SIZE) { for (int i = 0; i < this.dependentKeyIndices.size(); i++) { this.dependentKeyIndices.get(i).putStripeOnQueue(this.stripe); } this.stripe = FastList.newList(QUEUE_STRIPE_SIZE); } }
Example #17
Source File: MappedOperation.java From reladomo with Apache License 2.0 | 6 votes |
public List applyOperationToFullCache() { if (this.zIsNone()) { return new FastList(0); } //List joinedList = op.applyOperationToFullCache(); // we choose to find here (instead of op.applyOperationToFullCache()) because it allows us // finer control over how sub-queries are resolved (for example, this sub-query may be // resolved from the query cache) // this can backfire when there are multiple sub-queries // todo: rezaem: in a transaction (with full cache), this results in going to the database on the partial query CachedQuery cachedQuery = op.getResultObjectPortal().zFindInMemory(getCombinedOp(), null); if (cachedQuery != null) { List joinedList = cachedQuery.getResult(); return mapper.map(joinedList); } return null; }
Example #18
Source File: InMemoryTopicState.java From reladomo with Apache License 2.0 | 6 votes |
public void send(InMemoryXaResource xaResource, Message message) { xaResource.registerCallback(this); List<Message> list = uncommittedMessages.getIfAbsentPut(xaResource.getCurrentXid(), new Function0<List<Message>>() { @Override public List<Message> value() { return FastList.newList(); } }); synchronized (list) { list.add(message); } }
Example #19
Source File: MithraAbstractDatedDatabaseObject.java From reladomo with Apache License 2.0 | 6 votes |
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); deserializeAsOfAttributes(in, asOfDates); if (weak) { result.add(cache.getObjectFromDataWithoutCaching(data, asOfDates)); } else { result.add(cache.getObjectFromData(data, asOfDates)); } } return result; }
Example #20
Source File: MultiThreadedBatchProcessorTest.java From reladomo with Apache License 2.0 | 6 votes |
public void testShards() { List deepFetches = FastList.newListWith(TeamFinder.players()); TeamConsumer teamConsumer = new TeamConsumer(); Set shards = Sets.mutable.with("A", "B"); MultiThreadedBatchProcessor<Team, TeamList> mtbp = new MultiThreadedBatchProcessor<Team, TeamList>( TeamFinder.getFinderInstance(), TeamFinder.teamId().greaterThanEquals(1000), (List<Navigation<Team>>) deepFetches, teamConsumer, shards); mtbp.setBatchSize(77); mtbp.process(); assertEquals(1100, teamConsumer.countA.get()); assertEquals(1100, teamConsumer.countB.get()); }
Example #21
Source File: TestTupleIn.java From reladomo with Apache License 2.0 | 5 votes |
public void testMediumTupleInWithAsOfAttributeAndNull() { //todo: fullcache: implement MultiEquality + MultiIn as one operation if (PositionQuantityFinder.getMithraObjectPortal().isPartiallyCached()) { List drivers = FastList.newList(PositionAdjustmentHistoryFinder.findMany(PositionAdjustmentHistoryFinder.acmapCode().eq("A"))); PositionAdjustmentHistory history = new PositionAdjustmentHistory(); history.setAcmapCode("A"); drivers.add(0, history); // nulls Operation op = PositionQuantityFinder.accountId().tupleWith(PositionQuantityFinder.productId()).tupleWith(PositionQuantityFinder.businessDate()).tupleWith(PositionQuantityFinder.acmapCode()). inIgnoreNulls(drivers, new Extractor[]{PositionAdjustmentHistoryFinder.accountId(), PositionAdjustmentHistoryFinder.productId(), PositionAdjustmentHistoryFinder.businessDate(), PositionAdjustmentHistoryFinder.acmapCode()}); PositionQuantityList pqList = new PositionQuantityList(op); assertEquals(6, pqList.size()); } }
Example #22
Source File: FullSemiUniqueDatedIndex.java From reladomo with Apache License 2.0 | 5 votes |
public List removeOldEntryForRange(Object data) { int hash = this.nonDatedHashStrategy.computeHashCode(data); int index = indexFor(hash, this.nonDatedTable.length, this.nonDatedRightShift); Object e = this.nonDatedTable[index]; if (e == null) return null; if (e instanceof ChainedBucket) { return removeOldEntryForRangeChained((ChainedBucket)e, data, index); } if (e instanceof MultiEntry) { MultiEntry multiEntry = (MultiEntry) e; if (this.nonDatedHashStrategy.equals(multiEntry.getFirst(), data)) { FastList result = removeOldEntryForRangeMulti(data, multiEntry); if (multiEntry.size == 0) { this.nonDatedTable[index] = null; this.nonDatedSize--; } return result; } } else if (this.nonDatedHashStrategy.equals(e, data)) { if (hasOverlap(e, data)) { this.nonDatedTable[index] = null; this.nonDatedSize--; removeFromDatedTable(e); return ListFactory.create(e); } } return null; }
Example #23
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 #24
Source File: ConnectionManagerWrapper.java From reladomo with Apache License 2.0 | 5 votes |
public void cleanupDeadConnection(final MithraDatabaseException dbe, final Connection deadConnection) { if (this.tempContextMap.size() > 0) { synchronized (this.tempContextMap) { final List<ConnectionKey> toRemove = FastList.newList(); this.tempContextMap.forEachKeyValue(new Procedure2<ConnectionKey, WrappedConnectionIgnoreClose>() { @Override public void value(ConnectionKey connectionKey, WrappedConnectionIgnoreClose wrappedConnectionIgnoreClose) { if (connectionKey.thread == Thread.currentThread() && wrappedConnectionIgnoreClose == deadConnection) { toRemove.add(connectionKey); dbe.addContextsForRetry(wrappedConnectionIgnoreClose.contexts); try { wrappedConnectionIgnoreClose.reallyClose(); } catch (SQLException e) { //ignore } } } }); for(int i=0;i<toRemove.size();i++) { this.tempContextMap.remove(toRemove.get(i)); } } } }
Example #25
Source File: CacheLoaderManagerTest.java From reladomo with Apache License 2.0 | 5 votes |
public void testInitialLoad() { assertCacheEmpty(); CacheLoaderMonitor loaderMonitor = runInitialLoad(NYK_TEST_CONFIG, FastList.newListWith(BUSINESS_DATE)); assertListContainsExactly(LewContractFinder.findMany(allContractsOperation()), LewContractFinder.instrumentId(), 1, 2, 3); assertListContainsExactly(LewTransactionFinder.findMany(allTransactionsOperation()), LewTransactionFinder.tradeQty(), 10.0, 20.0, 30.0, 40.0, 50.0); assertLoaderMonitorTaskSizes(loaderMonitor, 1); final List<LoadingTaskThreadPoolMonitor> threadPoolMonitors = loaderMonitor.getThreadPoolMonitors(); assertEquals(1, threadPoolMonitors.size()); assertEquals("localhost:nystlew", threadPoolMonitors.get(0).getPoolName()); }
Example #26
Source File: SerializationNode.java From reladomo with Apache License 2.0 | 5 votes |
private void addChild(SerializationNode child) { if (this.children.isEmpty()) { this.children = FastList.newList(); } this.children.add(child); }
Example #27
Source File: MergeBuffer.java From reladomo with Apache License 2.0 | 5 votes |
private void wireUpChildren(List<MergeOptionNode> children) { if (children != null) { this.children = FastList.newList(children.size()); for(int i=0;i<children.size();i++) { MergeOptionNode mergeOptionNode = children.get(i); this.children.add(new MergeBuffer(mergeOptionNode, this.detached)); } } }
Example #28
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 #29
Source File: LinkedMapper.java From reladomo with Apache License 2.0 | 5 votes |
public List<String> getRelationshipPathAsList() { List<String> list = FastList.newList(); for(Mapper mapper : this.mappers) { if (mapper instanceof AbstractMapper) { AbstractMapper aMapper = (AbstractMapper) mapper; list.add(aMapper.getRawName()); } } return list; }
Example #30
Source File: MilestoneRectangle.java From reladomo with Apache License 2.0 | 5 votes |
public static List<MilestoneRectangle> merge(List<MilestoneRectangle> input) { Stack<MilestoneRectangle> mergeStack = new Stack<MilestoneRectangle>(); for (MilestoneRectangle rectangle : input) { if (rectangle.isValid()) { mergeStack.push(rectangle); } else { MithraDataObject dataObject = (MithraDataObject) rectangle.data; LOGGER.warn("Invalid milestoning of " + dataObject.getClass().getSimpleName() + '[' + dataObject.zGetPrintablePrimaryKey() + ']'); } } List<MilestoneRectangle> merged = FastList.newList(input.size()); while (!mergeStack.isEmpty()) { MilestoneRectangle next = mergeStack.pop(); boolean fragmented = false; for(int i = mergeStack.size() - 1; !fragmented && i >=0; i--) { MilestoneRectangle rect = mergeStack.get(i); if (next.intersects(rect)) { next.fragment(rect, mergeStack); fragmented = true; } } if (!fragmented) { merged.add(next); } } return merged; }