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

The following examples show how to use java.util.TreeMap#floorEntry() . These examples are extracted from open source projects. 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
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 2
public Date getExpirationDate(String algoToSearch, Integer keyLength) {
	TreeMap<Integer, Date> dates = new TreeMap<>();
	AlgoExpirationDate expirations = constraint.getAlgoExpirationDate();
	if (expirations == null) {
		return null;
	}
	SimpleDateFormat dateFormat = new SimpleDateFormat(Utils.isStringEmpty(expirations.getFormat()) ? DEFAULT_DATE_FORMAT : expirations.getFormat());

	for (Algo algo : expirations.getAlgo()) {
		if (algo.getValue().equals(algoToSearch)) {
			String expirationDate = algo.getDate();
			try {
				dates.put(algo.getSize(), dateFormat.parse(expirationDate));
			} catch (ParseException e) {
				LOG.warn("Unable to parse '{}' with format '{}'", expirationDate, dateFormat);
			}
		}
	}

	Entry<Integer, Date> floorEntry = dates.floorEntry(keyLength);
	if (floorEntry == null) {
		return null;
	} else {
		return floorEntry.getValue();
	}
}
 
Example 3
@Override
public Location getLocation(int deviceId, double time) {
	TreeMap<Double, Location> treeMap = treeMapArray.get(deviceId);
	
	Entry<Double, Location> e = treeMap.floorEntry(time);
    
    if(e == null){
    	SimLogger.printLine("impossible is occured! no location is found for the device '" + deviceId + "' at " + time);
    	System.exit(0);
    }
    
	return e.getValue();
}
 
Example 4
/**
 * floorEntry returns preceding entry.
 */
public void testFloorEntry() {
    TreeMap map = map5();
    Map.Entry e1 = map.floorEntry(three);
    assertEquals(three, e1.getKey());

    Map.Entry e2 = map.floorEntry(six);
    assertEquals(five, e2.getKey());

    Map.Entry e3 = map.floorEntry(one);
    assertEquals(one, e3.getKey());

    Map.Entry e4 = map.floorEntry(zero);
    assertNull(e4);
}
 
Example 5
Source Project: j2objc   File: TreeMapTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * floorEntry returns preceding entry.
 */
public void testFloorEntry() {
    TreeMap map = map5();
    Map.Entry e1 = map.floorEntry(three);
    assertEquals(three, e1.getKey());

    Map.Entry e2 = map.floorEntry(six);
    assertEquals(five, e2.getKey());

    Map.Entry e3 = map.floorEntry(one);
    assertEquals(one, e3.getKey());

    Map.Entry e4 = map.floorEntry(zero);
    assertNull(e4);
}
 
Example 6
Source Project: render   File: ChannelSpec.java    License: GNU General Public License v2.0 5 votes vote down vote up
public Map.Entry<Integer, ImageAndMask> getFloorMipmapEntry(final Integer mipmapLevel,
                                                            final TreeMap<Integer, ImageAndMask> levelToImageMap) {

    Map.Entry<Integer, ImageAndMask> floorEntry = levelToImageMap.floorEntry(mipmapLevel);

    if (floorEntry == null) {
        floorEntry = levelToImageMap.firstEntry();
    } else if ((floorEntry.getKey() < mipmapLevel) && (mipmapPathBuilder != null)) {
        floorEntry = mipmapPathBuilder.deriveImageAndMask(mipmapLevel,
                                                          levelToImageMap.firstEntry(),
                                                          true);
    }

    return floorEntry;
}
 
Example 7
Source Project: pumpernickel   File: MemoryBranch.java    License: MIT License 4 votes vote down vote up
@Override
public BeanState getState(K beanId, Revision revision) {
	if (beanId == null)
		throw new NullPointerException();
	if (revision != null && revision.getBranch() != this)
		throw new IllegalRevisionBranchException(
				"The revision provided relates to branch \""
						+ revision.getBranch().getName() + "\" (not \""
						+ getName() + "\"", this, revision);

	Lock lock = acquireReadLock();
	try {
		Map<String, TreeMap<Revision, Object>> beanData = dataByBeanId
				.get(beanId);
		TreeMap<Revision, Object> deletedField = beanData == null ? null
				: beanData.get(FIELD_DELETED.toString());
		TreeMap<Revision, Object> createdField = beanData == null ? null
				: beanData.get(FIELD_CREATED.toString());

		if (revision == null)
			revision = currentRevision;

		int thresholdSize = beanData == null ? 0 : beanData.size();
		if (deletedField != null)
			thresholdSize--;
		if (createdField != null)
			thresholdSize--;
		boolean exists = beanData != null
				&& beanData.size() > thresholdSize;

		Entry<Revision, Object> deletedFloor = deletedField == null ? null
				: deletedField.floorEntry(revision);
		Entry<Revision, Object> createdFloor = createdField == null ? null
				: createdField.floorEntry(revision);

		if (deletedFloor == null && createdFloor == null) {
			// this branch neither created nor deleted this bean
			if (exists)
				return BeanState.EXISTS;
			if (parent != null) {
				BeanState returnValue = parent.getState(beanId,
						parentRevision);
				if (returnValue == BeanState.CREATED)
					returnValue = BeanState.EXISTS;
				return returnValue;
			} else {
				return BeanState.UNDEFINED;
			}
		} else if (deletedFloor == null && createdFloor != null) {
			return BeanState.CREATED;
		} else if (deletedFloor != null && createdFloor == null) {
			return BeanState.DELETED;
		} else {
			if (deletedFloor.getKey().compareTo(createdFloor.getKey()) < 0) {
				return BeanState.CREATED;
			}
			return BeanState.DELETED;
		}

	} finally {
		releaseLock(lock);
	}
}
 
Example 8
Source Project: gpx-animator   File: Renderer.java    License: 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;
}
 
Example 9
Source Project: consulo   File: LineNumberConvertor.java    License: Apache License 2.0 4 votes vote down vote up
private static int convert(@Nonnull final TreeMap<Integer, Integer> fragments, int value) {
  Map.Entry<Integer, Integer> floor = fragments.floorEntry(value);
  if (floor == null || floor.getValue() == -1) return -1;
  return floor.getValue() - floor.getKey() + value;
}
 
Example 10
/**
 * This method returns a Boundary object from a chromosome at a specific position.
 * 
 * @param chromosome
 * @param position
 * @return 
 */
public GenomicBoundary getBoundary(String chromosome, int position, int listIndex){

	/*
	if(!removedSubBoundaries){
		throw new IllegalStateException("Can not get boundary is sub boundaries not removed.");
	}
	*/
	
       if(isChromosomeInBoundary(chromosome)){

		TreeMap<Integer, ArrayList<GenomicBoundary<V>>> chromosomeBoudaries = genomicsBoundaries.get(chromosome);
		//if(position >= (chromosomeBoudaries.firstKey() - margin) && position <= (chromosomeBoudaries.lastKey() + margin)){
		Entry<Integer, ArrayList<GenomicBoundary<V>>> boundaryEntry = chromosomeBoudaries.floorEntry(position + margin);

		if(boundaryEntry != null){
			ArrayList<GenomicBoundary<V>> boundary = boundaryEntry.getValue();
			if (boundary.get(listIndex).isInBoundarie(position,margin)){
				return boundary.get(listIndex);
			}
		}
		

		

       }

       return null;

   }