BlipThread thread = entry.getValue(); threads.put(entry.getKey(), new BlipThread(thread.getId(), thread.getLocation(), thread.getBlipIds(), blips));
/** * Removes a blip from this wavelet. * * @param blipId the id of the blip to be removed. */ public void delete(String blipId) { operationQueue.deleteBlip(this, blipId); Blip removed = blips.remove(blipId); if (removed != null) { // Remove the blip from the parent blip. Blip parentBlip = removed.getParentBlip(); if (parentBlip != null) { parentBlip.deleteChildBlipId(blipId); } // Remove the blip from the containing thread. BlipThread thread = removed.getThread(); if (thread != null) { thread.removeBlip(removed); } // If the containing thread is now empty, remove it from the parent blip // and from the wavelet. if (thread != null && parentBlip != null && thread.isEmpty()) { parentBlip.removeThread(thread); threads.remove(thread.getId()); } } }
/** * Moves all elements and annotations after the given position by * {@code shiftAmount}. * * @param position the anchor position. * @param shiftAmount the amount to shift the annotations range and elements * position. */ protected void shift(int position, int shiftAmount) { SortedMap<Integer, Element> newElements = new TreeMap<Integer, Element>(elements.headMap(position)); for (Entry<Integer, Element> element : elements.tailMap(position).entrySet()) { newElements.put(element.getKey() + shiftAmount, element.getValue()); } this.elements = newElements; SortedMap<Integer, BlipThread> newInlineReplyThreads = new TreeMap<Integer, BlipThread>(inlineReplyThreads.headMap(position)); for (Entry<Integer, BlipThread> entry : inlineReplyThreads.tailMap(position).entrySet()) { BlipThread thread = entry.getValue(); thread.setLocation(thread.getLocation() + shiftAmount); newInlineReplyThreads.put(thread.getLocation(), thread); } this.inlineReplyThreads = newInlineReplyThreads; this.annotations.shift(position, shiftAmount); }
@Override public BlipThread createInstance(Type type) { return new BlipThread(null, -1, null, null); } }
/** * Removes the given {@link BlipThread} from the reply or inline reply thread. * * @param thread the new thread to remove. */ protected void removeThread(BlipThread thread) { if (thread.getLocation() == -1) { this.replyThreads.remove(thread); } else { this.inlineReplyThreads.remove(thread.getLocation()); } }
/** * Creates a child blip of another blip. * * @param blip the parent blip. * @return an instance of {@link Blip} that represents the new child blip. */ public Blip createChildOfBlip(Blip blip) { // Create a new thread. String tempBlipId = generateTempBlipId(blip.getWavelet()); Wavelet wavelet = blip.getWavelet(); BlipThread thread = new BlipThread(tempBlipId, -1, new ArrayList<String>(), wavelet.getBlips()); // Add the new thread to the blip and wavelet. blip.addThread(thread); wavelet.addThread(thread); // Create a new blip in the new thread. Blip newBlip = newBlip(blip.getWavelet(), "", blip.getBlipId(), tempBlipId, thread.getId()); appendOperation(OperationType.BLIP_CREATE_CHILD, blip, Parameter.of(ParamsProperty.BLIP_DATA, newBlip.serialize())); return newBlip; }
List<String> rootThreadBlipIds = originalRootThread == null ? new ArrayList<String>() : new ArrayList<String>(originalRootThread.getBlipIds()); BlipThread rootThread = new BlipThread("", -1, rootThreadBlipIds, blips);
/** * Adds a thread to this wavelet. * * @param thread the thread to add. */ protected void addThread(BlipThread thread) { threads.put(thread.getId(), thread); }
/** * Creates a new {@code Blip} object used for this session. A temporary * id will be assigned to the newly created {@code Blip} object. * * @param wavelet the wavelet that owns this blip. * @param initialContent the initial content of the new blip. * @param parentBlipId the parent of this blip. * @return an instance of new {@code Blip} object used for this session. */ private static Blip newBlip(Wavelet wavelet, String initialContent, String parentBlipId, String blipId, String threadId) { Blip newBlip = new Blip(blipId, initialContent, parentBlipId, threadId, wavelet); if (parentBlipId != null) { Blip parentBlip = wavelet.getBlips().get(parentBlipId); if (parentBlip != null) { parentBlip.getChildBlipIds().add(newBlip.getBlipId()); } } wavelet.getBlips().put(newBlip.getBlipId(), newBlip); BlipThread thread = wavelet.getThread(threadId); if (thread != null) { thread.appendBlip(newBlip); } return newBlip; }
/** * @see #blindWavelet(WaveId, WaveletId, String, Map) * * @param threads a collection of threads that belong to this wavelet. */ public Wavelet blindWavelet(WaveId waveId, WaveletId waveletId, String proxyForId, Map<String, Blip> blips, Map<String, BlipThread> threads) { Util.checkIsValidProxyForId(proxyForId); Map<String, String> roles = new HashMap<String, String>(); return new Wavelet(waveId, waveletId, null, new BlipThread("", -1, new ArrayList<String>(), blips), Collections.<String>emptySet(), roles, blips, threads, new OperationQueue(proxyForId)); }
/** * Adds the given {@link BlipThread} as a reply or inline reply thread. * * @param thread the new thread to add. */ protected void addThread(BlipThread thread) { if (thread.getLocation() == -1) { this.replyThreads.add(thread); } else { this.inlineReplyThreads.put(thread.getLocation(), thread); } }
/** * Inserts a new inline blip at a specified location. * * @param blip the blip to anchor this inline blip from. * @param position the position in the given blip to insert this new inline * blip. * @return an instance of {@link Blip} that represents the inline blip. */ public Blip insertInlineBlipToDocument(Blip blip, int position) { // Create a new thread. String tempBlipId = generateTempBlipId(blip.getWavelet()); Wavelet wavelet = blip.getWavelet(); BlipThread thread = new BlipThread(tempBlipId, position, new ArrayList<String>(), wavelet.getBlips()); // Add the new thread to the blip and wavelet. blip.addThread(thread); wavelet.addThread(thread); // Create a new blip in the new thread. Blip inlineBlip = newBlip(blip.getWavelet(), "", blip.getBlipId(), tempBlipId, thread.getId()); appendOperation(OperationType.DOCUMENT_INSERT_INLINE_BLIP, blip, Parameter.of(ParamsProperty.INDEX, position), Parameter.of(ParamsProperty.BLIP_DATA, inlineBlip.serialize())); return inlineBlip; }
blipData.setWaveletId(ApiIdSerializer.instance().serialiseWaveletId(wavelet.getWaveletId())); blipData.setParentBlipId(parentBlipId); blipData.setThreadId(thread.getId()); blipData.setCreator(creator); blipData.setLastModifiedTime(lastModifiedTime); replyThreads.size()); for (BlipThread thread : inlineReplyThreads.values()) { replyThreadIds.add(thread.getId()); replyThreadIds.add(thread.getId());
for (Entry<String, BlipThread> entry : tempThreads.entrySet()) { BlipThread thread = entry.getValue(); threads.put(entry.getKey(), new BlipThread(thread.getId(), thread.getLocation(), thread.getBlipIds(), blips));
@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; }
for (String replyThreadId : replyThreadIds) { BlipThread thread = wavelet.getThread(replyThreadId); if (thread.getLocation() != -1) { inlineReplyThreads.put(thread.getLocation(), thread); } else { replyThreads.add(thread);
/** * Appends a blip to a wavelet. * * @param wavelet the wavelet to append the new blip to. * @param initialContent the initial content of the new blip. * @return an instance of {@link Blip} that represents the new blip. */ public Blip appendBlipToWavelet(Wavelet wavelet, String initialContent) { Blip newBlip = newBlip(wavelet, initialContent, null, generateTempBlipId(wavelet), wavelet.getRootThread().getId()); appendOperation(OperationType.WAVELET_APPEND_BLIP, wavelet, Parameter.of(ParamsProperty.BLIP_DATA, newBlip.serialize())); return newBlip; }
BlipThread rootThread = new BlipThread("", -1, blipIds, blips);
public void testToBlipData() throws Exception { Wavelet wavelet = mock(Wavelet.class); when(wavelet.getWaveId()).thenReturn(WAVE_ID); when(wavelet.getId()).thenReturn(WAVELET_ID); ConversationBlip blip = conversation.getRootThread().getFirstBlip(); String replyThreadId = blip.addReplyThread(3).getId(); EventDataConverterV22 converter = new EventDataConverterV22(); EventMessageBundle eventMessageBundle = new EventMessageBundle(null, null); BlipData blipData = converter.toBlipData(blip, wavelet, eventMessageBundle); assertEquals(blip.getThread().getId(), blipData.getThreadId()); assertEquals(Lists.newArrayList(replyThreadId), blipData.getReplyThreadIds()); Map<String, BlipThread> threads = eventMessageBundle.getThreads(); assertEquals(1, threads.size()); assertEquals(1, threads.get(replyThreadId).getLocation()); }
/** * Appends a new blip to the end of the thread of the given blip. * * @param blip the blip whose thread will be appended. * @return an instance of {@link Blip} that represents the new blip. */ public Blip continueThreadOfBlip(Blip blip) { Blip newBlip = newBlip(blip.getWavelet(), "", blip.getParentBlipId(), generateTempBlipId(blip.getWavelet()), blip.getThread().getId()); appendOperation(OperationType.BLIP_CONTINUE_THREAD, blip, Parameter.of(ParamsProperty.BLIP_DATA, newBlip.serialize())); return newBlip; }