java.util.concurrent.ConcurrentSkipListMap#put ( )源码实例Demo

下面列出了java.util.concurrent.ConcurrentSkipListMap#put ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: openjdk-jdk9   文件: ConcurrentSkipListMapTest.java
/**
 * 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);
}
 
源代码2 项目: hbase   文件: TestByteBufferKeyValue.java
@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);
}
 
源代码3 项目: audiveris   文件: BasicIndex.java
@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;
}
 
源代码4 项目: heroic   文件: MemoryBackend.java
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);
    }
}
 
源代码5 项目: j2objc   文件: ConcurrentSkipListMapTest.java
/**
 * 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);
}
 
源代码6 项目: j2objc   文件: ConcurrentSkipListMapTest.java
/**
 * 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);
}
 
源代码7 项目: qmq   文件: SortedPullLogTable.java
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;
}
 
源代码8 项目: openjdk-jdk9   文件: ConcurrentSkipListMapTest.java
/**
 * 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;
}
 
源代码9 项目: j2objc   文件: ConcurrentSkipListMapTest.java
/**
 * 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) {}
}
 
源代码10 项目: jmeter-plugins   文件: CompositeModel.java
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();
}
 
源代码11 项目: openjdk-jdk9   文件: ConcurrentSkipListMapTest.java
/**
 * 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) {}
}
 
源代码12 项目: j2objc   文件: ConcurrentSkipListSubMapTest.java
/**
 * 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);
}
 
/**
 * 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);
}
 
/**
 * 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();
}
 
源代码15 项目: j2objc   文件: ConcurrentSkipListMapTest.java
/**
 * put(null,x) throws NPE
 */
public void testPut1_NullPointerException() {
    ConcurrentSkipListMap c = map5();
    try {
        c.put(null, "whatever");
        shouldThrow();
    } catch (NullPointerException success) {}
}
 
源代码16 项目: jmeter-plugins   文件: GraphPanelChartTest.java
/**
 * 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);
}
 
源代码17 项目: vertexium   文件: PropertyCollection.java
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);
}
 
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;
}
 
源代码19 项目: freeinternals   文件: ICCProfile.java
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);
    }
}
 
源代码20 项目: freeinternals   文件: TIFF.java
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);
    }
}