@Override protected int getNextIndex() { int index = -1; for (Entry<Integer, Element> entry : blip.getElements().tailMap(position + 1).entrySet()) { if (match(entry.getValue())) { index = entry.getKey(); break; } } return index; }
/** * Returns the offset of this blip if it is inline, or -1 if it's not. If the * parent is not in the offset, this method will always return -1 since it * can't determine the inline blip status. * * @return the offset of this blip if it is inline, or -1 if it's not inline * or if the parent is not in the context. * @deprecated please use {@code getThread().getLocation()} to get the offset * of the inline reply thread that contains this blip. */ @Deprecated public int getInlineBlipOffset() { Blip parent = getParentBlip(); if (parent == null) { return -1; } for (Entry<Integer, Element> entry : parent.getElements().entrySet()) { Element element = entry.getValue(); if (element.getType() == ElementType.INLINE_BLIP && blipId.equals(element.getProperty(INLINE_BLIP_ELEMENT_ID_KEY))) { return entry.getKey(); } } return -1; }
/** * Returns all matches. * * @return a list of {@link BlipContent} that represents the hits. */ public List<BlipContent> values() { List<BlipContent> result = new ArrayList<BlipContent>(); while (iterator.hasNext()) { Range range = iterator.next(); if (range.getEnd() - range.getStart() == 1 && blip.getElements().containsKey(range.getStart())) { result.add(blip.getElements().get(range.getStart())); } else { result.add(Plaintext.of(blip.getContent().substring(range.getStart(), range.getEnd()))); } } iterator.reset(); return result; }
/** * Returns the first hit. * * @return an instance of {@link BlipContent}, that represents the first hit. */ public BlipContent value() { BlipContent result = null; if (iterator.hasNext()) { Range range = iterator.next(); if (range.getEnd() - range.getStart() == 1 && blip.getElements().containsKey(range.getStart())) { result = blip.getElements().get(range.getStart()); } else { result = Plaintext.of(blip.getContent().substring(range.getStart(), range.getEnd())); } } iterator.reset(); return result; }
if (end - start == 1 && blip.getElements().containsKey(start)) { source = blip.getElements().get(start); } else { source = Plaintext.of(blip.getContent().substring(start, end)); blip.getElements().subMap(start, end).keySet().iterator(); while(elementIterator.hasNext()) { elementIterator.next(); break; case UPDATE_ELEMENT: Element existingElement = blip.getElements().get(start); if (existingElement == null) { throw new IllegalArgumentException("No element found at index " + start + "."); blip.getElements().put(start, Element.class.cast(next)); } else if (bundledAnnotations != null) { for (BundledAnnotation bundled : bundledAnnotations) {
public void testInlineBlip() throws Exception { Blip blip = newBlip("\n1234", Collections.<Annotation>emptyList()); assertEquals(-1, blip.getInlineBlipOffset()); Blip inlineBlip = blip.insertInlineBlip(3); assertTrue(blip.getChildBlipIds().contains(inlineBlip.getBlipId())); assertEquals(3, inlineBlip.getInlineBlipOffset()); assertEquals("\n12 34", blip.getContent()); assertEquals(ElementType.INLINE_BLIP, blip.getElements().get(3).getType()); }
public void testInlineBlip() throws Exception { Blip blip = newBlip("\n1234", Collections.<Annotation>emptyList()); assertEquals(-1, blip.getInlineBlipOffset()); Blip inlineBlip = blip.insertInlineBlip(3); assertTrue(blip.getChildBlipIds().contains(inlineBlip.getBlipId())); assertEquals(3, inlineBlip.getInlineBlipOffset()); assertEquals("\n12 34", blip.getContent()); assertEquals(ElementType.INLINE_BLIP, blip.getElements().get(3).getType()); }
public void testUpdateElement() throws Exception { Blip blip = newBlip(ROOT_BLIP_ID, Arrays.asList(CHILD_BLIP_ID), null); String url = "http://www.test.com/image.png"; blip.append(new Image(url, 100, 100, "Cool pix.")); assertEquals(2, blip.getElements().size()); // Update the image by appending a query param to the URL. blip.first(ElementType.IMAGE).updateElement(new MapFunction() { @Override public Map<String, String> call(BlipContent source) { Image matchedImage = (Image) source; Map<String, String> properties = new HashMap<String, String>(); properties.put("url", matchedImage.getUrl() + "?version=newversion"); return properties; } }); Image image = (Image) blip.first(ElementType.IMAGE).value(); assertEquals(url + "?version=newversion", image.getUrl()); }
public void testUpdateElement() throws Exception { Blip blip = newBlip(ROOT_BLIP_ID, Arrays.asList(CHILD_BLIP_ID), null); String url = "http://www.test.com/image.png"; blip.append(new Image(url, 100, 100, "Cool pix.")); assertEquals(2, blip.getElements().size()); // Update the image by appending a query param to the URL. blip.first(ElementType.IMAGE).updateElement(new MapFunction() { @Override public Map<String, String> call(BlipContent source) { Image matchedImage = (Image) source; Map<String, String> properties = new HashMap<String, String>(); properties.put("url", matchedImage.getUrl() + "?version=newversion"); return properties; } }); Image image = (Image) blip.first(ElementType.IMAGE).value(); assertEquals(url + "?version=newversion", image.getUrl()); }
public void testSerializeAndDeserialize() throws Exception { SortedMap<Integer, Element> elements = new TreeMap<Integer, Element>(); elements.put(14, new Gadget("http://a/b.xml")); Blip expectedBlip = new Blip("blip1", Arrays.asList("blip2", "blip3"), "\nhello world!\n another line", Arrays.asList("robot@test.com", "user@test.com"), "user@test.com", 1000l, 123l, null, null, Arrays.asList(new Annotation("key", "val", 2, 3)), elements, new ArrayList<String>(), wavelet); Blip actualBlip = Blip.deserialize(wavelet.getOperationQueue(), wavelet, expectedBlip.serialize()); assertEquals(expectedBlip.getWaveId(), actualBlip.getWaveId()); assertEquals(expectedBlip.getWaveletId(), actualBlip.getWaveletId()); assertEquals(expectedBlip.getBlipId(), actualBlip.getBlipId()); assertEquals(expectedBlip.getContent(), actualBlip.getContent()); assertEquals(expectedBlip.getCreator(), actualBlip.getCreator()); assertEquals(expectedBlip.getLastModifiedTime(), actualBlip.getLastModifiedTime()); assertEquals(expectedBlip.getParentBlipId(), actualBlip.getParentBlipId()); assertEquals(expectedBlip.getVersion(), actualBlip.getVersion()); assertEquals(expectedBlip.getContributors(), actualBlip.getContributors()); assertEquals(expectedBlip.getChildBlipIds(), actualBlip.getChildBlipIds()); assertEquals(expectedBlip.getElements().keySet(), actualBlip.getElements().keySet()); assertEquals(expectedBlip.getAnnotations().size(), actualBlip.getAnnotations().size()); }
public void testSerializeAndDeserialize() throws Exception { SortedMap<Integer, Element> elements = new TreeMap<Integer, Element>(); elements.put(14, new Gadget("http://a/b.xml")); Blip expectedBlip = new Blip("blip1", Arrays.asList("blip2", "blip3"), "\nhello world!\n another line", Arrays.asList("robot@test.com", "user@test.com"), "user@test.com", 1000l, 123l, null, "<some string>", Arrays.asList(new Annotation("key", "val", 2, 3)), elements, new ArrayList<String>(), wavelet); Blip actualBlip = Blip.deserialize(wavelet.getOperationQueue(), wavelet, expectedBlip.serialize()); assertEquals(expectedBlip.getWaveId(), actualBlip.getWaveId()); assertEquals(expectedBlip.getWaveletId(), actualBlip.getWaveletId()); assertEquals(expectedBlip.getBlipId(), actualBlip.getBlipId()); assertEquals(expectedBlip.getContent(), actualBlip.getContent()); assertEquals(expectedBlip.getCreator(), actualBlip.getCreator()); assertEquals(expectedBlip.getLastModifiedTime(), actualBlip.getLastModifiedTime()); assertEquals(expectedBlip.getParentBlipId(), actualBlip.getParentBlipId()); assertEquals(expectedBlip.getVersion(), actualBlip.getVersion()); assertEquals(expectedBlip.getContributors(), actualBlip.getContributors()); assertEquals(expectedBlip.getChildBlipIds(), actualBlip.getChildBlipIds()); assertEquals(expectedBlip.getElements().keySet(), actualBlip.getElements().keySet()); assertEquals(expectedBlip.getAnnotations().size(), actualBlip.getAnnotations().size()); }
assertEquals(2, blip.getElements().size()); assertEquals(3, blip.getElements().size()); assertTrue(blip.getContent().startsWith("\n hello")); element = blip.at(1).value().asElement();
assertEquals(2, blip.getElements().size()); assertEquals(3, blip.getElements().size()); assertTrue(blip.getContent().startsWith("\n hello")); element = blip.at(1).value().asElement();