/** @return the structure of a conversations in {@code wave}. */ public static ConversationStructure of(ConversationView wave) { IdentityMap<ConversationBlip, Collection<Conversation>> anchoring = null; Collection<Conversation> unanchored = null; Conversation mainConversation = getMainConversation(wave); for (Conversation conversation : wave.getConversations()) { if (conversation == mainConversation) { continue; } Anchor anchor = conversation.getAnchor(); ConversationBlip blip = anchor != null ? anchor.getBlip() : null; if (blip != null) { addLazily((anchoring = createIfNull(anchoring)), blip, conversation); } else { (unanchored = createIfNull(unanchored)).add(conversation); } } if (anchoring == null) { anchoring = CollectionUtils.emptyIdentityMap(); } if (unanchored == null) { unanchored = Collections.emptySet(); } return new ConversationStructure(anchoring, unanchored, mainConversation); }
@Override public void setAnchor(Anchor newAnchor) { checkIsUsable(); if (newAnchor != null) { Preconditions.checkArgument(newAnchor.getConversation().getClass() == getClass(), "Anchor must not refer to a different conversation class"); Preconditions.checkArgument(newAnchor.getConversation() != this, "Anchor must not refer to a different anchored conversation"); WaveletBasedConversation conv = (WaveletBasedConversation) newAnchor.getConversation(); String blipId = newAnchor.getBlip().getId(); manifest.setAnchor(new AnchorData(idFor(conv.getWaveletId()), blipId)); } else { manifest.setAnchor(new AnchorData(null, null)); } }
@Override public Anchor createAnchor(ConversationBlip blip) { checkIsUsable(); return new Anchor(this, blip); }
public void testCreateAnchor() { populate(alternate); ConversationBlip blip = getFirstBlip(alternate); Anchor anchor = alternate.createAnchor(blip); assertTrue(alternate == anchor.getConversation()); assertTrue(blip == anchor.getBlip()); }
/** * Builds an anchor if the wave has a specific wavelet and blip, else returns * null. */ private Anchor maybeMakeAnchor(WaveletId waveletId, String blipId) { Anchor anchor = null; if (isValidAnchor(waveletId, blipId)) { WaveletBasedConversation anchorConversation = wave.getConversation(waveletId); ConversationBlip anchorBlip = anchorConversation.getBlip(blipId); anchor = new Anchor(anchorConversation, anchorBlip); } return anchor; }
public void testCreateAnchor() { populate(alternate); ConversationBlip blip = getFirstBlip(alternate); Anchor anchor = alternate.createAnchor(blip); assertTrue(alternate == anchor.getConversation()); assertTrue(blip == anchor.getBlip()); }