/** * Static factory method to return a split index * * @param index * actual Index of an exchange in the corresponding collection of * sub exchanges * @param last * {@code true} if this index is the last in the corresponding * collection of sub exchanges * * @return A {@link SplitIndex} corresponding to the index information */ public static SplitIndex valueOf(int index, boolean last) { return new SplitIndex(index, last); }
@Test public void testHashCode() { SplitIndex index1a = SplitIndex.valueOf(4, false); SplitIndex index1b = SplitIndex.valueOf(4, false); SplitIndex index2 = SplitIndex.valueOf(5, false); SplitIndex index3 = SplitIndex.valueOf(4, true); assertEquals(index1a.hashCode(), index1b.hashCode()); // Not necessary, but hash code shouldn't be too weak assertTrue(index1a.hashCode() != index2.hashCode()); assertTrue(index1a.hashCode() != index3.hashCode()); }
@Test public void testEquals() { SplitIndex index1a = SplitIndex.valueOf(4, false); SplitIndex index1b = SplitIndex.valueOf(4, false); SplitIndex index2 = SplitIndex.valueOf(5, false); SplitIndex index3 = SplitIndex.valueOf(4, true); assertTrue("Should be equal", index1a.equals(index1b)); assertFalse("Should not be equal", index1a.equals(index2)); assertFalse("Should not be equal", index1a.equals(index3)); assertFalse("Null is never equal", index1a.equals(null)); assertFalse("Unrelated class is never equal", index1a.equals(this)); assertTrue("Same instances should be equal", index1a.equals(index1a)); }
private Exchange processAllResults(Exchange origExchange, Iterable splitResult) throws Exception { Exchange aggregate = null; Iterator iterator = splitResult.iterator(); int counter = 0; while (iterator.hasNext()) { Object splitPart = iterator.next(); SplitIndex idx = SplitIndex.valueOf(counter, !iterator.hasNext()); Exchange subExchange = processResult(origExchange, idx, splitPart); aggregate = doAggregate(aggregate, subExchange); ++counter; } return aggregate; }
@Override protected void finalizeSubExchange(Exchange origExchange, Exchange subExchange, SplitIndex index) { super.finalizeSubExchange(origExchange, subExchange, index); if (splitOnlyHasSingleResult(index)) { return; } ManagedMessage origMessage = new PlatformMessage(origExchange); SplitHistory origHistory = origMessage.getSplitHistory(); SplitHistory subHistory = origHistory.split(index.getIndex(), index.isLast()); ManagedMessage subMessage = new PlatformMessage(subExchange); subMessage.setSplitHistory(subHistory); }