public V get()

in ch-commons-util/src/main/java/com/cloudhopper/commons/util/StringLookupMap.java [94:129]


    public V get(String key) throws IllegalArgumentException {
        assertValidGetKey(key);

        key = toCorrectKeyCaseSensitivity(key);

        // check the "specific" map first for an exact match
        if (this.specificMap != null) {
            V specificValue = this.specificMap.get(key);
            if (specificValue != null) {
                return specificValue;
            }
        }

        // if we got here, specific match wasn't found
        if (this.prefixMap != null) {
            // fallback to the "prefix" map and try to find the best match
            Entry<String,V> entry = this.prefixMap.floorEntry(key);
            if (entry != null) {
                // we need to check that the prefix key returned really is an actual prefix
                if (key.startsWith(entry.getKey())) {
                    // somewhat strange, but the key to lookup by > length of prefix key
                    if (key.length() > entry.getKey().length()) {
                        return entry.getValue();
                    }
                }
            }
        }

        // is there a final prefix value?
        if (this.rootPrefixValue != null) {
            return this.rootPrefixValue;
        }

        // nothing was found
        return null;
    }