void apply(ConversationThread thread) { for (ConversationBlip blip : thread.getBlips()) { apply(blip); } }
BlipIterator(ConversationThread thread, Predicate<ConversationBlip> acceptor) { this.acceptsBlip = acceptor; this.currentThreadItr = thread.getBlips().iterator(); this.nextBlip = findNextBlip(); }
/** * Finds the next sibling of a blip in a thread. The last blip in a thread has * no next sibling. * * @param blip the blip. * @return the next sibling of the blip, or {@code null} if blip is the last * blip in a thread. */ @VisibleForTesting static ConversationBlip findNextSibling(ConversationBlip blip) { ConversationThread thread = blip.getThread(); Iterator<? extends ConversationBlip> blips = thread.getBlips().iterator(); boolean foundBlip = false; while (!foundBlip && blips.hasNext()) { if (blips.next() == blip) { foundBlip = true; } } return blips.hasNext() ? blips.next() : null; }
/** * Finds the previous sibling of a blip in a thread. The first blip in a * thread has no previous sibling. * * @param blip the blip. * @return the previous sibling of the blip, or {@code null}. */ @VisibleForTesting static ConversationBlip findPreviousSibling(ConversationBlip blip) { ConversationThread thread = blip.getThread(); ConversationBlip previous = null; for (ConversationBlip sibling : thread.getBlips()) { if (sibling == blip) { break; } previous = sibling; } return previous; }
private ConversationBlip findNextBlip() { ConversationBlip next = null; while ((next == null) && currentThreadItr.hasNext()) { ConversationBlip maybeNext; maybeNext = currentThreadItr.next(); for (ConversationThread reply : maybeNext.getReplyThreads()) { threads.add(reply); } if (acceptsBlip.apply(maybeNext)) { next = maybeNext; } while (!currentThreadItr.hasNext() && (threads.peek() != null)) { currentThreadItr = threads.remove().getBlips().iterator(); } } return next; } }
/** * Finds the children of a blip, defined as all blips in all reply threads. * * @param blip the blip. * @return the children of the given blip. */ @Override public List<ConversationBlip> findBlipChildren(ConversationBlip blip) { List<ConversationBlip> children = Lists.newArrayList(); // Add all children from the inline reply threads. for (LocatedReplyThread<? extends ConversationThread> thread : blip.locateReplyThreads()) { for (ConversationBlip child : thread.getThread().getBlips()) { children.add(child); } } return children; }
/** * Adds all blips in the given conversation to the {@link EventMessageBundle}. * * @param eventMessageBundle to add the blips to * @param conversation {@link Conversation} to get all blips from * @param wavelet {@link Wavelet} that the {@link Conversation} is based on * @param eventDataConverter {@link EventDataConverter} used for conversion */ public static void addAllBlipsToEventMessages(EventMessageBundle eventMessageBundle, Conversation conversation, Wavelet wavelet, EventDataConverter eventDataConverter) { Queue<ConversationThread> threads = new LinkedList<ConversationThread>(); threads.add(conversation.getRootThread()); while (!threads.isEmpty()) { ConversationThread thread = threads.remove(); for (ConversationBlip blip : thread.getBlips()) { addBlipToEventMessages(eventMessageBundle, blip, wavelet, eventDataConverter); for (ConversationThread replyThread : blip.getReplyThreads()) { threads.add(replyThread); } } } } }
@Override public WaveletData toWaveletData(Wavelet wavelet, Conversation conversation, EventMessageBundle eventMessageBundle) { WaveletData waveletData = super.toWaveletData(wavelet, conversation, eventMessageBundle); List<String> blipIds = Lists.newLinkedList(); for (ConversationBlip conversationBlip : conversation.getRootThread().getBlips()) { blipIds.add(conversationBlip.getId()); } waveletData.setRootThread(new BlipThread("", -1 , blipIds, null)); return waveletData; }
/** * Convenience function that returns the blips in a thread as a List. */ protected static List<ConversationBlip> getBlipList(ConversationThread thread) { return CollectionUtils.newArrayList(thread.getBlips()); }
/** * Convenience function that returns the blips in a thread as a List. */ protected static List<ConversationBlip> getBlipList(ConversationThread thread) { return CollectionUtils.newArrayList(thread.getBlips()); }
@Override public String render(ConversationThread thread, IdentityMap<ConversationBlip, String> blips) { StringBuilder r = new StringBuilder("Thread ["); r.append(" id: " + thread.getId()); r.append("; blips: ["); for (ConversationBlip blip : thread.getBlips()) { r.append(" "); r.append(blips.get(blip)); } r.append(" ]"); return r.toString(); }
@Override public String render(ConversationThread thread, IdentityMap<ConversationBlip, String> blips) { StringBuilder r = new StringBuilder("Thread ["); r.append(" id: " + thread.getId()); r.append("; blips: ["); for (ConversationBlip blip : thread.getBlips()) { r.append(" "); r.append(blips.get(blip)); } r.append(" ]"); return r.toString(); }
public void testLiveRenderingCommutesOnBlipInsert() { ConversationThread root = wave.getRoot().getRootThread(); root.insertBlip(Iterables.get(root.getBlips(), 1)); assertEquals(render().toString(), rendering.toString()); }
public void testLiveRenderingCommutesOnBlipInsert() { ConversationThread root = wave.getRoot().getRootThread(); root.insertBlip(Iterables.get(root.getBlips(), 1)); assertEquals(render().toString(), rendering.toString()); }
private static void assertThreadsEquivalent(ConversationThread expected, ConversationThread actual) { assertEquals("Mismatched id in constructed conversation thread", expected.getId(), actual.getId()); assertEquals("Mismatched first blip in constructed conversation thread", expected.getFirstBlip() == null, actual.getFirstBlip() == null); Iterator<? extends ConversationBlip> expectedBlips = expected.getBlips().iterator(); Iterator<? extends ConversationBlip> actualBlips = actual.getBlips().iterator(); while (expectedBlips.hasNext()) { assertTrue("Missing blip in reconstructed conversation", actualBlips.hasNext()); ConversationBlip expectedBlip = expectedBlips.next(); ConversationBlip actualBlip = actualBlips.next(); assertBlipsEquivalent(expectedBlip, actualBlip); } assertFalse("Extra blip in reconstructed conversation", actualBlips.hasNext()); }
private static void assertThreadsEquivalent(ConversationThread expected, ConversationThread actual) { assertEquals("Mismatched id in constructed conversation thread", expected.getId(), actual.getId()); assertEquals("Mismatched first blip in constructed conversation thread", expected.getFirstBlip() == null, actual.getFirstBlip() == null); Iterator<? extends ConversationBlip> expectedBlips = expected.getBlips().iterator(); Iterator<? extends ConversationBlip> actualBlips = actual.getBlips().iterator(); while (expectedBlips.hasNext()) { assertTrue("Missing blip in reconstructed conversation", actualBlips.hasNext()); ConversationBlip expectedBlip = expectedBlips.next(); ConversationBlip actualBlip = actualBlips.next(); assertBlipsEquivalent(expectedBlip, actualBlip); } assertFalse("Extra blip in reconstructed conversation", actualBlips.hasNext()); }
/** * Asserts that the state-querying methods on a thread can be called. */ protected static void assertThreadAccessible(ConversationThread thread) { thread.getBlips(); thread.getConversation(); thread.getFirstBlip(); thread.getId(); thread.getParentBlip(); } }
/** * Asserts that the state-querying methods on a thread can be called. */ protected static void assertThreadAccessible(ConversationThread thread) { thread.getBlips(); thread.getConversation(); thread.getFirstBlip(); thread.getId(); thread.getParentBlip(); } }
public void testResolveContext() throws Exception { eventMessages.requireBlip( conversation.getRootThread().getFirstBlip().getId(), Lists.newArrayList(Context.CHILDREN)); ContextResolver.resolveContext( eventMessages, wavelet, conversation, new EventDataConverterV21()); Set<String> blips = eventMessages.getBlipData().keySet(); assertEquals(2, blips.size()); for (ConversationBlip blip : conversation.getRootThread().getBlips()) { assertTrue(blips.contains(blip.getId())); } }
public void testResolveContext() throws Exception { eventMessages.requireBlip( conversation.getRootThread().getFirstBlip().getId(), Lists.newArrayList(Context.CHILDREN)); ContextResolver.resolveContext( eventMessages, wavelet, conversation, new EventDataConverterV21()); Set<String> blips = eventMessages.getBlipData().keySet(); assertEquals(2, blips.size()); for (ConversationBlip blip : conversation.getRootThread().getBlips()) { assertTrue(blips.contains(blip.getId())); } }