    001/*
    002 * Licensed to the Apache Software Foundation (ASF) under one or more
    003 * contributor license agreements. See the NOTICE file distributed with
    004 * this work for additional information regarding copyright ownership.
    005 * The ASF licenses this file to You under the Apache license, Version 2.0
    006 * (the "License"); you may not use this file except in compliance with
    007 * the License. You may obtain a copy of the License at
    008 *
    009 *      http://www.apache.org/licenses/LICENSE-2.0
    010 *
    011 * Unless required by applicable law or agreed to in writing, software
    012 * distributed under the License is distributed on an "AS IS" BASIS,
    013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    014 * See the license for the specific language governing permissions and
    015 * limitations under the license.
    016 */
    017
    018package org.apache.commons.text.lookup;
    019
    020/**
    021 * Lookups a String key for a String value.
    022 * <p>
    023 * This class represents the simplest form of a string to string map. It has a benefit over a map in that it can create
    024 * the result on demand based on the key.
    025 * </p>
    026 * <p>
    027 * For example, it would be possible to implement a lookup that used the key as a primary key, and looked up the value
    028 * on demand from the database.
    029 * </p>
    030 *
    031 * @since 1.3
    032 */
    033@FunctionalInterface
    034public interface StringLookup {
    035
    036    /**
    037     * Looks up a String key to provide a String value.
    038     * <p>
    039     * The internal implementation may use any mechanism to return the value. The simplest implementation is to use a
    040     * Map. However, virtually any implementation is possible.
    041     * </p>
    042     * <p>
    043     * For example, it would be possible to implement a lookup that used the key as a primary key, and looked up the
    044     * value on demand from the database Or, a numeric based implementation could be created that treats the key as an
    045     * integer, increments the value and return the result as a string - converting 1 to 2, 15 to 16 etc.
    046     * </p>
    047     * <p>
    048     * This method always returns a String, regardless of the underlying data, by converting it as necessary. For
    049     * example:
    050     * </p>
    051     *
    052     * <pre>
    053     * Map&lt;String, Object&gt; map = new HashMap&lt;String, Object&gt;();
    054     * map.put("number", Integer.valueOf(2));
    055     * assertEquals("2", StringLookupFactory.mapStringLookup(map).lookup("number"));
    056     * </pre>
    057     *
    058     * @param key the key to look up, may be null.
    059     * @return The matching value, null if no match.
    060     */
    061    String lookup(String key);
    062}