Java Code Examples for java.util.TreeMap#ceilingEntry()

The following examples show how to use java.util.TreeMap#ceilingEntry() . 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: Solution2.java    From LeetCode-Solution-in-Good-Style with Apache License 2.0 6 votes vote down vote up
public int[] findRightInterval(int[][] intervals) {
    int len = intervals.length;
    if (len == 0) {
        return new int[0];
    }

    TreeMap<Integer, Integer> treeMap = new TreeMap<>();
    int[] res = new int[len];
    for (int i = 0; i < len; i++) {
        treeMap.put(intervals[i][0], i);
    }
    for (int i = 0; i < len; i++) {
        Map.Entry<Integer, Integer> entry = treeMap.ceilingEntry(intervals[i][1]);
        if (entry == null) {
            res[i] = -1;
        } else {
            res[i] = entry.getValue();
        }
    }
    return res;
}
 
Example 2
Source File: DremioORCRecordUtils.java    From dremio-oss with Apache License 2.0 6 votes vote down vote up
@Override
public ByteBuffer getBuffer(boolean direct, int length) {
  if (direct) {
    ArrowBuf buf = allocator.buffer(length);
    ByteBuffer retBuf = buf.nioBuffer(0, length);
    directBufMap.put(new ByteBufferWrapper(retBuf), buf);
    return retBuf;
  } else {
    TreeMap<DremioORCRecordUtils.ByteBufferAllocatorPool.Key, ByteBuffer> tree = getBufferTree();
    Map.Entry<DremioORCRecordUtils.ByteBufferAllocatorPool.Key, ByteBuffer> entry = tree.ceilingEntry(new DremioORCRecordUtils.ByteBufferAllocatorPool.Key(length, 0));
    if (entry == null) {
      return ByteBuffer.allocate(length);
    }
    tree.remove(entry.getKey());
    return entry.getValue();
  }
}
 
Example 3
Source File: DremioORCRecordUtils.java    From dremio-oss with Apache License 2.0 6 votes vote down vote up
@Override
public ByteBuffer getBuffer(boolean direct, int length) {
  if (direct) {
    ArrowBuf buf = allocator.buffer(length);
    ByteBuffer retBuf = buf.nioBuffer(0, length);
    directBufMap.put(new ByteBufferWrapper(retBuf), buf);
    return retBuf;
  } else {
    TreeMap<DremioORCRecordUtils.ByteBufferAllocatorPool.Key, ByteBuffer> tree = getBufferTree();
    Map.Entry<DremioORCRecordUtils.ByteBufferAllocatorPool.Key, ByteBuffer> entry = tree.ceilingEntry(new DremioORCRecordUtils.ByteBufferAllocatorPool.Key(length, 0));
    if (entry == null) {
      return ByteBuffer.allocate(length);
    }
    tree.remove(entry.getKey());
    return entry.getValue();
  }
}
 
Example 4
Source File: TimeShiftingSink.java    From clearvolume with GNU Lesser General Public License v3.0 6 votes vote down vote up
private Volume getVolumeToSend(int pVolumeChannelID)
{
	synchronized (mLock)
	{
		final TreeMap<Long, SwitchableSoftReference<Volume>> lTimePointIndexToVolumeMap = mChannelToVolumeListsMap.get(pVolumeChannelID);

		if (lTimePointIndexToVolumeMap.isEmpty())
			return null;

		Entry<Long, SwitchableSoftReference<Volume>> lIndexVolumeEntry = lTimePointIndexToVolumeMap.floorEntry(mHighestTimePointIndexSeen + mTimeShift);
		if (lIndexVolumeEntry == null)
			lIndexVolumeEntry = lTimePointIndexToVolumeMap.ceilingEntry(mHighestTimePointIndexSeen + mTimeShift);

		if (lIndexVolumeEntry == null)
			return null;

		final Volume lVolume = lIndexVolumeEntry.getValue().get();
		if (lVolume == null)
		{
			lTimePointIndexToVolumeMap.remove(lIndexVolumeEntry.getKey());
			return getVolumeToSend(pVolumeChannelID);
		}
		return lVolume;
	}
}
 
Example 5
Source File: DefaultLongPollingService.java    From hermes with Apache License 2.0 5 votes vote down vote up
private void logSelecotrMetric(Tpg tpg, CallbackContext callbackCtx, int count) {
	TreeMap<Integer, String> metricNames = null;

	if (callbackCtx.getSlotMatchResults()[PullMessageSelectorManager.SLOT_PRIORITY_INDEX].isMatch()) {
		metricNames = m_catSelectorByPriorityMetrics;
	} else if (callbackCtx.getSlotMatchResults()[PullMessageSelectorManager.SLOT_NONPRIORITY_INDEX].isMatch()) {
		metricNames = m_catSelectorByNonPriorityMetrics;
	} else {
		metricNames = m_catSelectorBySafeTriggerMetrics;
	}

	Entry<Integer, String> ceilingEntry = metricNames.ceilingEntry(count);

	Cat.logEvent(ceilingEntry.getValue(), tpg.getTopic() + "-" + tpg.getPartition());
}
 
Example 6
Source File: MySQLMessageQueueStorage.java    From hermes with Apache License 2.0 5 votes vote down vote up
private void logSelecotrMetric(String topic, int partition, boolean priority, int count) {
	TreeMap<Integer, String> metricNames = priority ? m_catSelectorByPriorityMetrics
	      : m_catSelectorByNonPriorityMetrics;

	Entry<Integer, String> ceilingEntry = metricNames.ceilingEntry(count);

	Cat.logEvent(ceilingEntry.getValue(), topic + "-" + partition);
}
 
Example 7
Source File: TreeMapTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * ceilingEntry returns next entry.
 */
public void testCeilingEntry() {
    TreeMap map = map5();
    Map.Entry e1 = map.ceilingEntry(three);
    assertEquals(three, e1.getKey());

    Map.Entry e2 = map.ceilingEntry(zero);
    assertEquals(one, e2.getKey());

    Map.Entry e3 = map.ceilingEntry(five);
    assertEquals(five, e3.getKey());

    Map.Entry e4 = map.ceilingEntry(six);
    assertNull(e4);
}
 
Example 8
Source File: ElasticByteBufferPool.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Override
public synchronized ByteBuffer getBuffer(boolean direct, int length) {
  TreeMap<Key, ByteBuffer> tree = getBufferTree(direct);
  Map.Entry<Key, ByteBuffer> entry =
      tree.ceilingEntry(new Key(length, 0));
  if (entry == null) {
    return direct ? ByteBuffer.allocateDirect(length) :
                    ByteBuffer.allocate(length);
  }
  tree.remove(entry.getKey());
  return entry.getValue();
}
 
Example 9
Source File: ElasticByteBufferPool.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Override
public synchronized ByteBuffer getBuffer(boolean direct, int length) {
  TreeMap<Key, ByteBuffer> tree = getBufferTree(direct);
  Map.Entry<Key, ByteBuffer> entry =
      tree.ceilingEntry(new Key(length, 0));
  if (entry == null) {
    return direct ? ByteBuffer.allocateDirect(length) :
                    ByteBuffer.allocate(length);
  }
  tree.remove(entry.getKey());
  return entry.getValue();
}
 
Example 10
Source File: ByteBufferAllocatorPool.java    From tajo with Apache License 2.0 5 votes vote down vote up
public ByteBuffer getBuffer(boolean direct, int length) {
  TreeMap<Key, ByteBuffer> tree = getBufferTree(direct);
  Map.Entry<Key, ByteBuffer> entry = tree.ceilingEntry(new Key(length, 0));
  if (entry == null) {
    return direct ? ByteBuffer.allocateDirect(length) : ByteBuffer
        .allocate(length);
  }
  tree.remove(entry.getKey());
  return entry.getValue();
}
 
Example 11
Source File: TreeMapTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * ceilingEntry returns next entry.
 */
public void testCeilingEntry() {
    TreeMap map = map5();
    Map.Entry e1 = map.ceilingEntry(three);
    assertEquals(three, e1.getKey());

    Map.Entry e2 = map.ceilingEntry(zero);
    assertEquals(one, e2.getKey());

    Map.Entry e3 = map.ceilingEntry(five);
    assertEquals(five, e3.getKey());

    Map.Entry e4 = map.ceilingEntry(six);
    assertNull(e4);
}
 
Example 12
Source File: CephFileSystem.java    From cephfs-hadoop with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Select a data pool given the requested replication factor.
 */
private String selectDataPool(Path path, int repl_wanted) throws IOException {
  /* map pool size -> pool name */
  TreeMap<Integer, String> pools = new TreeMap<Integer, String>();

  /*
   * Start with a mapping for the default pool. An error here would indicate
   * something bad, so we throw any exceptions. For configured pools we
   * ignore some errors.
   */
  int fd = ceph.__open(new Path("/"), CephMount.O_RDONLY, 0);
  String pool_name = ceph.get_file_pool_name(fd);
  ceph.close(fd);
  int replication = getPoolReplication(pool_name);
  pools.put(new Integer(replication), pool_name);

  /*
   * Insert extra data pools from configuration. Errors are logged (most
   * likely a non-existant pool), and a configured pool will override the
   * default pool.
   */
  String[] conf_pools = getConfiguredDataPools();
  for (String name : conf_pools) {
    try {
      replication = getPoolReplication(name);
      pools.put(new Integer(replication), name);
    } catch (IOException e) {
      LOG.warn("Error looking up replication of pool: " + name + ", " + e);
    }
  }

  /* Choose smallest entry >= target, or largest in map. */
  Map.Entry<Integer, String> entry = pools.ceilingEntry(new Integer(repl_wanted));
  if (entry == null)
    entry = pools.lastEntry();

  /* should always contain default pool */
  assert(entry != null);

  replication = entry.getKey().intValue();
  pool_name = entry.getValue();

  /* log non-exact match cases */
  if (replication != repl_wanted) {
    LOG.info("selectDataPool path=" + path + " pool:repl=" +
        pool_name + ":" + replication + " wanted=" + repl_wanted);
  }

  return pool_name;
}
 
Example 13
Source File: Renderer.java    From gpx-animator with Apache License 2.0 4 votes vote down vote up
private Point2D drawMarker(final BufferedImage bi, final int frame) {
    if (cfg.getMarkerSize() == null || cfg.getMarkerSize() == 0.0) {
        return null;
    }

    Point2D point = null;

    final Graphics2D g2 = getGraphics(bi);
    final long t2 = getTime(frame);
    final List<TrackConfiguration> trackConfigurationList = cfg.getTrackConfigurationList();

    int i = 0;
    outer:
    for (final List<TreeMap<Long, Point2D>> timePointMapList : timePointMapListList) {
        final TrackConfiguration trackConfiguration = trackConfigurationList.get(i++);
        for (final TreeMap<Long, Point2D> timePointMap : timePointMapList) {
            final Entry<Long, Point2D> ceilingEntry = timePointMap.ceilingEntry(t2);
            final Entry<Long, Point2D> floorEntry = timePointMap.floorEntry(t2);
            if (floorEntry == null) {
                continue;
            }

            point = floorEntry.getValue();
            if (t2 - floorEntry.getKey() <= cfg.getTailDuration()) {

                g2.setColor(ceilingEntry == null ? Color.white : trackConfiguration.getColor());

                final TrackIcon trackIcon = trackConfiguration.getTrackIcon();
                if (trackIcon == null || trackIcon.getKey().isEmpty()) {
                    drawSimpleCircleOnGraphics2D(point, g2);
                } else {
                    try {
                        drawIconOnGraphics2D(point, g2, trackIcon);
                    } catch (final IOException e) {
                        drawSimpleCircleOnGraphics2D(point, g2);
                    }
                }

                final String label = trackConfiguration.getLabel();
                if (!label.isEmpty()) {
                    printText(g2, label, (float) point.getX() + 8f, (float) point.getY() + 4f);
                }
            }

            continue outer; // NOPMD -- Continue the outer loop, not the inner one
        }
    }
    return point;
}