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

The following examples show how to use java.util.TreeMap#floorKey() . 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
Source Project: DataLink   File: HdfsFilePathGenerator.java    License: Apache License 2.0 6 votes vote down vote up
public FileSplitMode getFileSplitMode(MediaMappingInfo mappingInfo) {
    HdfsMappingParameter hdfsMappingParameter = JSONObject.toJavaObject(mappingInfo.getParameterObj(), HdfsMappingParameter.class);
    if (hdfsMappingParameter != null) {
        List<FileSplitStrategy> fileSplitStrategieList = hdfsMappingParameter.getFileSplitStrategieList();
        if (fileSplitStrategieList != null && fileSplitStrategieList.size() > 0) {
            Date current = new Date();
            TreeMap<Date, FileSplitMode> treeMap = new TreeMap<>();
            for (FileSplitStrategy fileSplitStrategy : fileSplitStrategieList) {
                treeMap.put(fileSplitStrategy.getEffectiveDate(), fileSplitStrategy.getFileSplitMode());
            }
            Date greatest = treeMap.floorKey(current);
            if (greatest != null) {
                return treeMap.get(greatest);
            } else {
                return FileSplitMode.DAY;
            }
        } else {
            return FileSplitMode.DAY;
        }
    } else {
        return FileSplitMode.DAY;// 没有明确配置的话,一天一个文件
    }
}
 
Example 2
public int maxProfitAssignment(int[] difficulty, int[] profit, int[] worker) {
    Pair[] combo = new Pair[difficulty.length];
    for (int i = 0; i < combo.length; i++) combo[i] = new Pair(difficulty[i], profit[i]);
    Arrays.sort(combo, (a, b) -> (a.diff - b.diff)); // 以难度排序
    TreeMap<Integer, Integer> preMax = new TreeMap<>();
    int max = 0;
    for (Pair pair : combo) {
        max = Math.max(max, pair.prof);
        preMax.put(pair.diff, max); // 难度m的最大利润n
    }
    int result = 0;
    for (int w : worker) {
        Integer lower = preMax.floorKey(w); // floorKey用于返回的最大键小于或等于给定的键,或null
        if (lower != null) result += preMax.get(lower);
    }
    return result;
}
 
Example 3
/** @return the matching root location for a set of root locations and a resource or project */
static final public FileURI getRootLocationForResource(Collection<FileURI> rootLocations,
		SafeURI<?> nestedLocation) {

	if (nestedLocation == null || nestedLocation.isEmpty() || !nestedLocation.exists()) {
		return null;
	}

	TreeMap<String, FileURI> rootLocationMap = new TreeMap<>();
	for (FileURI loc : rootLocations) {
		String locStr = loc.toString();
		rootLocationMap.put(locStr, loc);
	}

	String nestedLocStr = nestedLocation.toString();
	String rootLocStr = rootLocationMap.floorKey(nestedLocStr);
	if (rootLocStr != null && nestedLocStr.startsWith(rootLocStr)) {
		return rootLocationMap.get(rootLocStr);
	}
	return null;
}
 
Example 4
/**
 * floorKey returns preceding element
 */
public void testFloorKey() {
    TreeMap q = map5();
    Object e1 = q.floorKey(three);
    assertEquals(three, e1);

    Object e2 = q.floorKey(six);
    assertEquals(five, e2);

    Object e3 = q.floorKey(one);
    assertEquals(one, e3);

    Object e4 = q.floorKey(zero);
    assertNull(e4);
}
 
Example 5
Source Project: tracecompass   File: PcapFile.java    License: Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Method that moves the position to the specified rank.
 *
 * @param rank
 *            The rank of the packet.
 *
 * @throws IOException
 *             Thrown when there is an error while reading the file.
 * @throws BadPcapFileException
 *             Thrown when a packet header is invalid.
 */
public void seekPacket(long rank) throws IOException, BadPcapFileException {
    // Verify argument
    if (rank < 0) {
        throw new IllegalArgumentException();
    }

    TreeMap<Long, Long> fileIndex = getFileIndex();
    Long positionInBytes = fileIndex.get(rank);

    if (positionInBytes != null) {
        // Index is known. Move to position.
        getFileChannel().position(positionInBytes.longValue());
        setCurrentRank(rank);
    } else {
        // Index is unknown. Find the corresponding position.
        // Find closest index
        long floorRank = fileIndex.floorKey(rank);
        setCurrentRank(floorRank);
        positionInBytes = fileIndex.get(floorRank);
        if (positionInBytes != null) {
            getFileChannel().position(positionInBytes);
            // skip until wanted packet is found
            while (getCurrentRank() < rank && skipNextPacket()) {
                // Do nothing
            }
        }
    }
}
 
Example 6
Source Project: j2objc   File: TreeMapTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * floorKey returns preceding element
 */
public void testFloorKey() {
    TreeMap q = map5();
    Object e1 = q.floorKey(three);
    assertEquals(three, e1);

    Object e2 = q.floorKey(six);
    assertEquals(five, e2);

    Object e3 = q.floorKey(one);
    assertEquals(one, e3);

    Object e4 = q.floorKey(zero);
    assertNull(e4);
}
 
Example 7
Source Project: siddhi   File: IndexEventHolder.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public boolean containsEventSet(String attribute, Compare.Operator operator, Object value) {
    if (primaryKeyData != null && attribute.equals(primaryKeyAttributes)) {
        switch (operator) {
            case LESS_THAN:
                return ((TreeMap<Object, StreamEvent>) primaryKeyData).lowerKey(value) != null;
            case GREATER_THAN:
                return ((TreeMap<Object, StreamEvent>) primaryKeyData).higherKey(value) != null;
            case LESS_THAN_EQUAL:
                return ((TreeMap<Object, StreamEvent>) primaryKeyData).ceilingKey(value) != null;
            case GREATER_THAN_EQUAL:
                return ((TreeMap<Object, StreamEvent>) primaryKeyData).floorKey(value) != null;
            case EQUAL:
                return primaryKeyData.get(value) != null;
            case NOT_EQUAL:
                return primaryKeyData.size() > 1;
        }
    } else {
        TreeMap<Object, Set<StreamEvent>> currentIndexedData = indexData.get(attribute);

        switch (operator) {

            case LESS_THAN:
                return currentIndexedData.lowerKey(value) != null;
            case GREATER_THAN:
                return currentIndexedData.higherKey(value) != null;
            case LESS_THAN_EQUAL:
                return currentIndexedData.ceilingKey(value) != null;
            case GREATER_THAN_EQUAL:
                return currentIndexedData.floorKey(value) != null;
            case EQUAL:
                return currentIndexedData.get(value) != null;
            case NOT_EQUAL:
                return currentIndexedData.size() > 1;
        }
    }
    throw new OperationNotSupportedException(operator + " not supported for '" + value + "' by " + getClass()
            .getName());
}
 
Example 8
Source Project: siddhi   File: IndexEventHolderForCache.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public boolean containsEventSet(String attribute, Compare.Operator operator, Object value) {
    if (primaryKeyData != null && attribute.equals(primaryKeyAttributes)) {
        StreamEvent foundEvent;
        switch (operator) {
            case LESS_THAN:
                foundEvent = (StreamEvent) ((TreeMap<Object, StreamEvent>) primaryKeyData).
                        lowerKey(value);
                if (foundEvent != null) {
                    handleCachePolicyAttributeUpdate(foundEvent);
                    return true;
                } else {
                    return false;
                }
            case GREATER_THAN:
                foundEvent = (StreamEvent) ((TreeMap<Object, StreamEvent>) primaryKeyData).
                        higherKey(value);
                if (foundEvent != null) {
                    handleCachePolicyAttributeUpdate(foundEvent);
                    return true;
                } else {
                    return false;
                }
            case LESS_THAN_EQUAL:
                foundEvent = (StreamEvent) ((TreeMap<Object, StreamEvent>) primaryKeyData).
                        ceilingKey(value);
                if (foundEvent != null) {
                    handleCachePolicyAttributeUpdate(foundEvent);
                    return true;
                } else {
                    return false;
                }
            case GREATER_THAN_EQUAL:
                foundEvent = (StreamEvent) ((TreeMap<Object, StreamEvent>) primaryKeyData).
                        floorKey(value);
                if (foundEvent != null) {
                    handleCachePolicyAttributeUpdate(foundEvent);
                    return true;
                } else {
                    return false;
                }
            case EQUAL:
                foundEvent = primaryKeyData.get(value);
                if (foundEvent != null) {
                    handleCachePolicyAttributeUpdate(foundEvent);
                    return true;
                } else {
                    return false;
                }
            case NOT_EQUAL:
                return primaryKeyData.size() > 1;
        }
    } else {
        TreeMap<Object, Set<StreamEvent>> currentIndexedData = indexData.get(attribute);

        switch (operator) {

            case LESS_THAN:
                return currentIndexedData.lowerKey(value) != null;
            case GREATER_THAN:
                return currentIndexedData.higherKey(value) != null;
            case LESS_THAN_EQUAL:
                return currentIndexedData.ceilingKey(value) != null;
            case GREATER_THAN_EQUAL:
                return currentIndexedData.floorKey(value) != null;
            case EQUAL:
                return currentIndexedData.get(value) != null;
            case NOT_EQUAL:
                return currentIndexedData.size() > 1;
        }
    }
    throw new OperationNotSupportedException(operator + " not supported for '" + value + "' by " + getClass()
            .getName());
}