@Override public void addWantedEvaluation(WantedEvaluation evaluation) { // Could check for duplicates at this point. In actual use, however, // duplicates are likely to be rare, and it is unclear whether scanning the // list of duplicates would be a win. list.add(evaluation); }
/** Constructor. */ private DocumentBasedAbuseStore( ObservableElementList<WantedEvaluation, WantedEvaluation> list) { this.list = list; this.list.addListener(new ObservableElementList.Listener<WantedEvaluation>() { @Override public void onValueAdded(WantedEvaluation entry) { triggerEvaluationAdded(entry); } @Override public void onValueRemoved(WantedEvaluation entry) { // This never happens, and, when it does, is safe to ignore. } }); }
@Override public ObservableManifestBlip getBlip(int index) { return blips.get(index); }
verify(blips).addListener(blipsListener.capture()); verify(blip).detachListeners(); when(blips.add("b+1")).thenReturn(blip); when(blips.add(1, "b+2")).thenReturn(blip); when(blips.get(2)).thenReturn(blip); when(blips.getValues()).thenReturn(iterator); when(blips.indexOf(same(blip))).thenReturn(1); when(blips.remove(same(blip))).thenReturn(true); when(blips.size()).thenReturn(2);
public void testIndexOf() { for (int i = 0; i < PREPOPULATED_SIZE; ++i) { BasicValue<String> child = prepopulatedList.get(i); assertEquals(i, prepopulatedList.indexOf(child)); } BasicValue<String> last = prepopulatedList.add(null); assertEquals(prepopulatedList.size() - 1, prepopulatedList.indexOf(last)); assertEquals(-1, freshList.indexOf(last)); }
public void testCanObserveChanges() { ListChangeObserver bob = new ListChangeObserver("bob"); ListChangeObserver ann = new ListChangeObserver("ann"); assertEquals("bob", bob.toString()); assertEquals("ann", ann.toString()); freshList.addListener(bob); BasicValue<String> one = freshList.add(null); assertEquals("boba", bob.toString()); assertEquals("ann", ann.toString()); freshList.addListener(ann); BasicValue<String> two = freshList.add(null); assertEquals("bobaa", bob.toString()); assertEquals("anna", ann.toString()); freshList.remove(two); assertEquals("bobaar", bob.toString()); assertEquals("annar", ann.toString()); freshList.removeListener(bob); BasicValue<String> three = freshList.add(null); assertEquals("bobaar", bob.toString()); assertEquals("annara", ann.toString()); freshList.removeListener(ann); BasicValue<String> four = freshList.add(null); assertEquals("bobaar", bob.toString()); assertEquals("annara", ann.toString()); }
public void testAdd() { for (int index = 0; index < WORD.length; ++index) { BasicValue<String> value = freshList.add(null); value.set(WORD[index]); assertEquals("The list should have " + (index + 1) + " elements", index + 1, freshList.size()); assertEquals("The " + (index + 1) + "th value should be " + WORD[index], WORD[index], freshList.get(index).get()); } }
public void testAddAtIndex() { BasicValue<String> last = freshList.add(0, null); assertSame(last, freshList.get(0)); BasicValue<String> oldSecond = prepopulatedList.get(1); BasicValue<String> newSecond = prepopulatedList.add(1, null); assertSame(newSecond, prepopulatedList.get(1)); assertSame(oldSecond, prepopulatedList.get(2)); BasicValue<String> oldFirst = prepopulatedList.get(0); BasicValue<String> newFirst = prepopulatedList.add(0, null); assertSame(newFirst, prepopulatedList.get(0)); assertSame(oldFirst, prepopulatedList.get(1)); } }
public void testAddAtInvalidIndex() { try { prepopulatedList.add(-1, null); fail("Adding at negative index should fail"); } catch (IndexOutOfBoundsException e) { // success } try { prepopulatedList.add(prepopulatedList.size() + 1,null); fail("Adding after the end of the list should fail"); } catch (IndexOutOfBoundsException e) { // success } }
private DocumentBasedRoles(ObservableElementList< ObservableAssignment, DocumentBasedAssignment.AssignmentInitializer> assignments) { this.assignments = assignments; this.assignmentListener = new ObservableAssignment.Listener() { @Override public void onChanged() { fireOnChanged(); } }; for (ObservableAssignment a : assignments.getValues()) { a.addListener(assignmentListener); } this.assignmentListListener = new ObservableElementList.Listener<ObservableAssignment>() { @Override public void onValueAdded(ObservableAssignment entry) { entry.addListener(assignmentListener); fireOnChanged(); } @Override public void onValueRemoved(ObservableAssignment entry) { entry.removeListener(assignmentListener); fireOnChanged(); } }; assignments.addListener(assignmentListListener); }
public void testClear() { assertEquals(0, freshList.size()); freshList.clear(); assertEquals(0, freshList.size()); // TODO(user): Should we have isEmpty? assertFalse(prepopulatedList.size() == 0); prepopulatedList.clear(); assertEquals(0, prepopulatedList.size()); // TODO(user): Add test with parallel removals and additions to cleared list. }
@Override public Iterable<? extends Assignment> getAssignments() { return assignments.getValues(); } }
@Override public int numReplies() { return replies.size(); }
@Override public boolean removeBlip(ManifestBlip blip) { return (blip instanceof ObservableManifestBlip) ? blips.remove((ObservableManifestBlip) blip) : false; }
@Override public int indexOf(ManifestThread reply) { return (reply instanceof ObservableManifestThread) ? replies.indexOf((ObservableManifestThread) reply) : -1; }
verify(threads).addListener(threadsListener.capture()); verify(thread).detachListeners(); when(threads.add(new DocumentBasedManifestBlip.ThreadInitialiser("t1", false))).thenReturn(thread); when(threads.add(1, new DocumentBasedManifestBlip.ThreadInitialiser("t2", true))).thenReturn(thread); when(threads.get(2)).thenReturn(thread); when(threads.getValues()).thenReturn(iterator); when(threads.indexOf(same(thread))).thenReturn(1); when(threads.remove(same(thread))).thenReturn(true); when(threads.size()).thenReturn(2);
public void testIndexOf() { for (int i = 0; i < PREPOPULATED_SIZE; ++i) { BasicValue<String> child = prepopulatedList.get(i); assertEquals(i, prepopulatedList.indexOf(child)); } BasicValue<String> last = prepopulatedList.add(null); assertEquals(prepopulatedList.size() - 1, prepopulatedList.indexOf(last)); assertEquals(-1, freshList.indexOf(last)); }