Java Code Examples for java.util.concurrent.ConcurrentSkipListMap#put()

The following examples show how to use java.util.concurrent.ConcurrentSkipListMap#put() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BasicIndex.java    From audiveris with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public ConcurrentSkipListMap<Integer, E> unmarshal (IndexValue<E> value)
        throws Exception
{
    // TODO: is sorting needed?
    Collections.sort(value.list, new Comparator<E>()
             {
                 @Override
                 public int compare (E e1,
                                     E e2)
                 {
                     return Integer.compare(e1.getId(), e2.getId());
                 }
             });

    ConcurrentSkipListMap<Integer, E> map = new ConcurrentSkipListMap<>();

    for (E entity : value.list) {
        map.put(entity.getId(), entity);
    }

    return map;
}
 
Example 2
Source File: ConcurrentSkipListMapTest.java    From j2objc with Apache License 2.0 6 votes vote down vote up
/**
 * pollLastEntry returns entries in order
 */
public void testPollLastEntry() {
    ConcurrentSkipListMap map = map5();
    Map.Entry e = map.pollLastEntry();
    assertEquals(five, e.getKey());
    assertEquals("E", e.getValue());
    e = map.pollLastEntry();
    assertEquals(four, e.getKey());
    map.put(five, "E");
    e = map.pollLastEntry();
    assertEquals(five, e.getKey());
    assertEquals("E", e.getValue());
    e = map.pollLastEntry();
    assertEquals(three, e.getKey());
    map.remove(two);
    e = map.pollLastEntry();
    assertEquals(one, e.getKey());
    try {
        e.setValue("E");
        shouldThrow();
    } catch (UnsupportedOperationException success) {}
    e = map.pollLastEntry();
    assertNull(e);
}
 
Example 3
Source File: ConcurrentSkipListMapTest.java    From j2objc with Apache License 2.0 6 votes vote down vote up
/**
 * pollFirstEntry returns entries in order
 */
public void testPollFirstEntry() {
    ConcurrentSkipListMap map = map5();
    Map.Entry e = map.pollFirstEntry();
    assertEquals(one, e.getKey());
    assertEquals("A", e.getValue());
    e = map.pollFirstEntry();
    assertEquals(two, e.getKey());
    map.put(one, "A");
    e = map.pollFirstEntry();
    assertEquals(one, e.getKey());
    assertEquals("A", e.getValue());
    e = map.pollFirstEntry();
    assertEquals(three, e.getKey());
    map.remove(four);
    e = map.pollFirstEntry();
    assertEquals(five, e.getKey());
    try {
        e.setValue("A");
        shouldThrow();
    } catch (UnsupportedOperationException success) {}
    e = map.pollFirstEntry();
    assertNull(e);
}
 
Example 4
Source File: MemoryBackend.java    From heroic with Apache License 2.0 6 votes vote down vote up
private void writeOne(final WriteMetric.Request request) {
    final MetricCollection g = request.getData();

    final MemoryKey key = new MemoryKey(g.getType(), request.getSeries().getTags());

    final MemoryCell cell =
        storage.computeIfAbsent(key, k -> new MemoryCell(new ConcurrentHashMap<>()));

    final ConcurrentSkipListMap<Long, Metric> metrics = cell.getEntries()
        .computeIfAbsent(request.getSeries().getResource(),
            k -> new MemoryEntry(new ConcurrentSkipListMap<>()))
        .getMetrics();

    for (final Metric d : g.data()) {
        metrics.put(d.getTimestamp(), d);
    }
}
 
Example 5
Source File: TestByteBufferKeyValue.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Test
public void testCompare() {
  Cell cell1 = getOffheapCell(row1, fam1, qual1);
  Cell cell2 = getOffheapCell(row1, fam1, qual2);
  assertTrue(CellComparatorImpl.COMPARATOR.compare(cell1, cell2) < 0);
  Cell cell3 = getOffheapCell(row1, Bytes.toBytes("wide_family"), qual2);
  assertTrue(CellComparatorImpl.COMPARATOR.compare(cell1, cell3) < 0);
  Cell cell4 = getOffheapCell(row1, Bytes.toBytes("f"), qual2);
  assertTrue(CellComparatorImpl.COMPARATOR.compare(cell1, cell4) > 0);
  BBKVComparator comparator = new BBKVComparator(null);
  assertTrue(comparator.compare(cell1, cell2) < 0);
  assertTrue(comparator.compare(cell1, cell3) < 0);
  assertTrue(comparator.compare(cell1, cell4) > 0);
  ByteBuffer buf = ByteBuffer.allocate(row1.length);
  ByteBufferUtils.copyFromArrayToBuffer(buf, row1, 0, row1.length);

  ConcurrentSkipListMap<ByteBufferKeyValue, ByteBufferKeyValue> map =
      new ConcurrentSkipListMap<>(comparator);
  map.put((ByteBufferKeyValue)cell1, (ByteBufferKeyValue)cell1);
  map.put((ByteBufferKeyValue)cell2, (ByteBufferKeyValue)cell2);
  map.put((ByteBufferKeyValue)cell3, (ByteBufferKeyValue)cell3);
  map.put((ByteBufferKeyValue)cell1, (ByteBufferKeyValue)cell1);
  map.put((ByteBufferKeyValue)cell1, (ByteBufferKeyValue)cell1);
}
 
Example 6
Source File: ConcurrentSkipListMapTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * pollFirstEntry returns entries in order
 */
public void testPollFirstEntry() {
    ConcurrentSkipListMap map = map5();
    Map.Entry e = map.pollFirstEntry();
    assertEquals(one, e.getKey());
    assertEquals("A", e.getValue());
    e = map.pollFirstEntry();
    assertEquals(two, e.getKey());
    map.put(one, "A");
    e = map.pollFirstEntry();
    assertEquals(one, e.getKey());
    assertEquals("A", e.getValue());
    e = map.pollFirstEntry();
    assertEquals(three, e.getKey());
    map.remove(four);
    e = map.pollFirstEntry();
    assertEquals(five, e.getKey());
    try {
        e.setValue("A");
        shouldThrow();
    } catch (UnsupportedOperationException success) {}
    e = map.pollFirstEntry();
    assertNull(e);
}
 
Example 7
Source File: CompositeModel.java    From jmeter-plugins with Apache License 2.0 5 votes vote down vote up
public void addRow(String vizualizerName, AbstractGraphRow row) {
    ConcurrentSkipListMap<String, AbstractGraphRow> rows = models.get(vizualizerName);
    if (rows == null) {
        rows = getRowsMap(vizualizerName);
    }
    rows.put(row.getLabel(), row);
    notifier.refresh();
}
 
Example 8
Source File: ConcurrentSkipListMapTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * remove(null, x) throws NPE
 */
public void testRemove2_NullPointerException() {
    ConcurrentSkipListMap c = new ConcurrentSkipListMap();
    c.put("sadsdf", "asdads");
    try {
        c.remove(null, "whatever");
        shouldThrow();
    } catch (NullPointerException success) {}
}
 
Example 9
Source File: ConcurrentSkipListSubMapTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a new map from Integers 1-5 to Strings "A"-"E".
 */
private static ConcurrentNavigableMap map5() {
    ConcurrentSkipListMap map = new ConcurrentSkipListMap();
    assertTrue(map.isEmpty());
    map.put(zero, "Z");
    map.put(one, "A");
    map.put(five, "E");
    map.put(three, "C");
    map.put(two, "B");
    map.put(four, "D");
    map.put(seven, "F");
    assertFalse(map.isEmpty());
    assertEquals(7, map.size());
    return map.subMap(one, true, seven, false);
}
 
Example 10
Source File: ConcurrentSkipListSubMapTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns a new map from Integers 1-5 to Strings "A"-"E".
 */
private static ConcurrentNavigableMap map5() {
    ConcurrentSkipListMap map = new ConcurrentSkipListMap();
    assertTrue(map.isEmpty());
    map.put(zero, "Z");
    map.put(one, "A");
    map.put(five, "E");
    map.put(three, "C");
    map.put(two, "B");
    map.put(four, "D");
    map.put(seven, "F");
    assertFalse(map.isEmpty());
    assertEquals(7, map.size());
    return map.subMap(one, true, seven, false);
}
 
Example 11
Source File: ConcurrentSkipListSubMapTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns a new map from Integers -5 to -1 to Strings "A"-"E".
 */
private static ConcurrentNavigableMap dmap5() {
    ConcurrentSkipListMap map = new ConcurrentSkipListMap();
    assertTrue(map.isEmpty());
    map.put(m1, "A");
    map.put(m5, "E");
    map.put(m3, "C");
    map.put(m2, "B");
    map.put(m4, "D");
    assertFalse(map.isEmpty());
    assertEquals(5, map.size());
    return map.descendingMap();
}
 
Example 12
Source File: SortedPullLogTable.java    From qmq with Apache License 2.0 5 votes vote down vote up
public boolean appendIndex(Map<String, PullLogIndexEntry> indexMap) {
    positionOfIndex = tablet.getWrotePosition();

    for (Map.Entry<String, PullLogIndexEntry> entry : indexMap.entrySet()) {
        final byte[] consumerBytes = entry.getKey().getBytes(StandardCharsets.UTF_8);
        int size = Integer.BYTES + Short.BYTES + consumerBytes.length + Long.BYTES + Long.BYTES + Integer.BYTES + Integer.BYTES;
        PullLogIndexEntry indexEntry = entry.getValue();

        ByteBuf buffer = ByteBufAllocator.DEFAULT.ioBuffer(size);
        try {
            buffer.writeInt(MagicCode.PULL_LOG_MAGIC_V1);
            buffer.writeShort((short) consumerBytes.length);
            buffer.writeBytes(consumerBytes);
            buffer.writeLong(indexEntry.startOfPullLogSequence);
            buffer.writeLong(indexEntry.baseOfMessageSequence);
            buffer.writeInt(indexEntry.position);
            buffer.writeInt(indexEntry.num);
            ByteBuffer nioBuffer = buffer.nioBuffer();
            Checksums.update(crc, nioBuffer, nioBuffer.limit());
            boolean result = tablet.appendData(nioBuffer);
            if (!result) return false;
        } finally {
            ReferenceCountUtil.safeRelease(buffer);
        }

        ConcurrentSkipListMap<PullLogSequence, SegmentLocation> index = sortedPullLogTable.index;
        index.put(new PullLogSequence(entry.getKey(), indexEntry.startOfPullLogSequence), new SegmentLocation(indexEntry.baseOfMessageSequence, indexEntry.position, indexEntry.num, tablet));
        tablet.retain();
    }
    return true;
}
 
Example 13
Source File: ConcurrentSkipListMapTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * put(null,x) throws NPE
 */
public void testPut1_NullPointerException() {
    ConcurrentSkipListMap c = map5();
    try {
        c.put(null, "whatever");
        shouldThrow();
    } catch (NullPointerException success) {}
}
 
Example 14
Source File: GraphPanelChartTest.java    From jmeter-plugins with Apache License 2.0 5 votes vote down vote up
/**
 * Test of paintComponent method, of class GraphPanelChart.
 */
@Test
public void testPaintComponent() {
    System.out.println("paintComponent");
    Graphics g = new TestGraphics();
    GraphPanelChart instance = new GraphPanelChart();
    instance.setSize(500, 500);
    instance.getChartSettings().setDrawFinalZeroingLines(true);
    instance.getChartSettings().setDrawCurrentX(true);
    instance.getChartSettings().setExpendRows(true);

    final ConcurrentSkipListMap<String, AbstractGraphRow> rows = new ConcurrentSkipListMap<String, AbstractGraphRow>();
    instance.setRows(rows);
    final GraphRowAverages row1 = new GraphRowAverages();
    row1.setDrawThickLines(true);
    row1.setDrawLine(true);
    row1.setDrawBar(true);
    row1.setDrawValueLabel(true);
    row1.setMarkerSize(AbstractGraphRow.MARKER_SIZE_BIG);
    rows.put("test 1", row1);
    row1.add(System.currentTimeMillis(), 20);

    instance.paintComponent(g);

    row1.add(System.currentTimeMillis(), 540);
    instance.setxAxisLabelRenderer(new DateTimeRenderer("HH:mm:ss"));
    instance.paintComponent(g);

    row1.add(System.currentTimeMillis(), 8530);
    instance.paintComponent(g);
}
 
Example 15
Source File: PropertyCollection.java    From vertexium with Apache License 2.0 5 votes vote down vote up
public synchronized void addProperty(Property property) {
    ConcurrentSkipListMap<String, ConcurrentSkipListSet<Property>> propertiesByKey = propertiesByNameAndKey.get(property.getName());
    if (propertiesByKey == null) {
        propertiesByKey = new ConcurrentSkipListMap<>();
        this.propertiesByNameAndKey.put(property.getName(), propertiesByKey);
    }
    ConcurrentSkipListSet<Property> properties = propertiesByKey.get(property.getKey());
    if (properties == null) {
        properties = new ConcurrentSkipListSet<>();
        propertiesByKey.put(property.getKey(), properties);
    }
    properties.add(property);
    this.propertiesList.add(property);
}
 
Example 16
Source File: ConcurrentSkipListMapTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * remove(null, x) throws NPE
 */
public void testRemove2_NullPointerException() {
    ConcurrentSkipListMap c = new ConcurrentSkipListMap();
    c.put("sadsdf", "asdads");
    try {
        c.remove(null, "whatever");
        shouldThrow();
    } catch (NullPointerException success) {}
}
 
Example 17
Source File: GraphModelToCsvExporterTest.java    From jmeter-plugins with Apache License 2.0 5 votes vote down vote up
private ConcurrentSkipListMap<String, AbstractGraphRow> createTestModel() {
    ConcurrentSkipListMap<String, AbstractGraphRow> testModel = new ConcurrentSkipListMap<>();
    Calendar now = Calendar.getInstance();
    now.set(Calendar.HOUR_OF_DAY, 10);
    now.set(Calendar.MINUTE, 30);
    now.set(Calendar.SECOND, 0);
    now.set(Calendar.MILLISECOND, 500);

    GraphRowAverages row1 = new GraphRowAverages();
    GraphRowAverages row2 = new GraphRowAverages();
    GraphRowAverages row3 = new GraphRowAverages();

    testModel.put("row1", row1);
    testModel.put("row2", row2);
    testModel.put("row3", row3);

    row1.add(now.getTimeInMillis(), 10);
    row2.add(now.getTimeInMillis(), 20);

    now.set(Calendar.SECOND, 10);

    row1.add(now.getTimeInMillis(), 20);
    row2.add(now.getTimeInMillis(), 30);

    now.set(Calendar.SECOND, 25);

    row3.add(now.getTimeInMillis(), 50);

    return testModel;
}
 
Example 18
Source File: ConcurrentSkipListMapTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns a new map from Integers 1-5 to Strings "A"-"E".
 */
private static ConcurrentSkipListMap map5() {
    ConcurrentSkipListMap map = new ConcurrentSkipListMap();
    assertTrue(map.isEmpty());
    map.put(one, "A");
    map.put(five, "E");
    map.put(three, "C");
    map.put(two, "B");
    map.put(four, "D");
    assertFalse(map.isEmpty());
    assertEquals(5, map.size());
    return map;
}
 
Example 19
Source File: ICCProfile.java    From freeinternals with Apache License 2.0 4 votes vote down vote up
public void generateTreeNode(DefaultMutableTreeNode parentNode) {
    DefaultMutableTreeNode nodeHeader;
    DefaultMutableTreeNode nodeTagTable;
    int lastPos;
    int diff;

    parentNode.add(nodeHeader = new DefaultMutableTreeNode(new JTreeNodeFileComponent(
            this.header.getStartPos(),
            this.header.getLength(),
            "Profile header")));
    this.header.generateTreeNode(nodeHeader);

    parentNode.add(nodeHeader = new DefaultMutableTreeNode(new JTreeNodeFileComponent(
            lastPos = this.header.getStartPos() + this.header.getLength(),
            4,
            String.format("Tag count = %d", this.tagCount))));

    lastPos = lastPos + 4;

    ConcurrentSkipListMap<Long, RefItem> sortedMap = new ConcurrentSkipListMap<Long, RefItem>();
    for (int i = 0; i < this.tagTable.length; i++) {
        parentNode.add(nodeTagTable = new DefaultMutableTreeNode(new JTreeNodeFileComponent(
                lastPos + Tag.LENGTH * i,
                Tag.LENGTH,
                String.format("Tag[%d]", i))));
        this.tagTable[i].generateTreeNode(nodeTagTable);

        if (sortedMap.get(this.tagTable[i].Offset) == null) {
            RefItem refItem = new RefItem();
            refItem.i = i;
            refItem.tag = this.tagTable[i];
            sortedMap.put(refItem.tag.Offset, refItem);
        }
    }

    lastPos = lastPos + this.tagTable.length * Tag.LENGTH;
    for (RefItem ref : sortedMap.values()) {
        diff = (int) ((this.startPos + ref.tag.Offset) - lastPos);
        if (diff > 0) {
            UITool.generateTreeNodeDiff(
                    parentNode, lastPos, diff,
                    this.rawData, this.startPos);
        }

        parentNode.add(new DefaultMutableTreeNode(new JTreeNodeFileComponent(
                this.startPos + (int) ref.tag.Offset,
                (int) ref.tag.Size,
                String.format("Data of Tag [%d]", ref.i))));
        lastPos = this.startPos + (int) ref.tag.Offset + (int) ref.tag.Size;
    }

    diff = (this.startPos + this.rawData.length) - lastPos;
    if (diff > 0) {
        UITool.generateTreeNodeDiff(
                parentNode, lastPos, diff,
                this.rawData, this.startPos);
    }
}
 
Example 20
Source File: TIFF.java    From freeinternals with Apache License 2.0 4 votes vote down vote up
public void generateTreeNode(DefaultMutableTreeNode parentNode) {
    JTreeNodeFileComponent comp;
    DefaultMutableTreeNode nodeTiffHeader;

    // TIFF Header
    comp = new JTreeNodeFileComponent(
            this.startPos,
            TIFFHeader.SIZE,
            "TIFF Header");
    comp.setDescription("A TIFF file begins with an 8-byte image file header that points to an image file directory (IFD).");
    parentNode.add(nodeTiffHeader = new DefaultMutableTreeNode(comp));
    this.tiffHeader.generateTreeNode(nodeTiffHeader);

    // TIFF Data
    ConcurrentSkipListMap<Integer, RefItem> sortedMap = new ConcurrentSkipListMap<Integer, RefItem>();
    int lastEnd = this.tiffHeader.getStartPos() + TIFFHeader.SIZE;          // Absolute position
    int diff;

    for (IFDGroup group : this.exifGroup) {
        RefItem refItem = new RefItem();
        refItem.offset = group.offset;
        refItem.length = group.length;
        refItem.ifdgroup = group;
        sortedMap.put(refItem.offset, refItem);

        this.loadRefItem(group.ifd, sortedMap);
    }

    for (RefItem ref : sortedMap.values()) {
        diff = (this.startPos + ref.offset) - lastEnd;
        if (diff > 0) {
            UITool.generateTreeNodeDiff(
                    parentNode, lastEnd, diff,
                    this.tiffByteArray, this.startPos);
        }

        if (ref.ifdgroup != null) {
            ref.ifdgroup.generateTreeNode(parentNode);
        } else {
            parentNode.add(new DefaultMutableTreeNode(new JTreeNodeFileComponent(
                    this.tiffHeader.getStartPos() + ref.offset,
                    ref.length,
                    String.format("Reference of tag [%s] %04X.H (%d, %s)",
                            ref.ifd.getTagSpace().toString(),
                            ref.ifd.ifd_tag,
                            ref.ifd.ifd_tag,
                            ref.ifd.getTagName()))));
        }

        lastEnd = this.startPos + ref.offset + ref.length;
    }

    // In case, there is some extra space in the end
    diff = (this.tiffHeader.getStartPos() + this.tiffByteArray.length) - lastEnd;
    if (diff > 0) {
        UITool.generateTreeNodeDiff(
                parentNode, lastEnd, diff,
                this.tiffByteArray, this.startPos);
    }
}