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

The following examples show how to use java.util.TreeMap#higherKey() . 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: TreeMapTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * higherKey returns next element
 */
public void testHigherKey() {
    TreeMap q = map5();
    Object e1 = q.higherKey(three);
    assertEquals(four, e1);

    Object e2 = q.higherKey(zero);
    assertEquals(one, e2);

    Object e3 = q.higherKey(five);
    assertNull(e3);

    Object e4 = q.higherKey(six);
    assertNull(e4);
}
 
Example 2
Source File: TreeMapTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * higherKey returns next element
 */
public void testHigherKey() {
    TreeMap q = map5();
    Object e1 = q.higherKey(three);
    assertEquals(four, e1);

    Object e2 = q.higherKey(zero);
    assertEquals(one, e2);

    Object e3 = q.higherKey(five);
    assertNull(e3);

    Object e4 = q.higherKey(six);
    assertNull(e4);
}
 
Example 3
Source File: IndexEventHolder.java    From siddhi with 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 4
Source File: IndexEventHolderForCache.java    From siddhi with 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());
}