    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 * Lookup a String key to 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 */
    033public interface StringLookup {
    034
    035    /**
    036     * Looks up a String key to a String value.
    037     * <p>
    038     * The internal implementation may use any mechanism to return the value. The simplest implementation is to use a
    039     * Map. However, virtually any implementation is possible.
    040     * </p>
    041     * <p>
    042     * For example, it would be possible to implement a lookup that used the key as a primary key, and looked up the
    043     * value on demand from the database Or, a numeric based implementation could be created that treats the key as an
    044     * integer, increments the value and return the result as a string - converting 1 to 2, 15 to 16 etc.
    045     * </p>
    046     * <p>
    047     * This method always returns a String, regardless of the underlying data, by converting it as necessary. For
    048     * example:
    049     * </p>
    050     *
    051     * <pre>
    052     * Map&lt;String, Object&gt; map = new HashMap&lt;String, Object&gt;();
    053     * map.put("number", new Integer(2));
    054     * assertEquals("2", StrLookup.mapLookup(map).lookup("number"));
    055     * </pre>
    056     *
    057     * @param key
    058     *            the key to look up, may be null
    059     * @return the matching value, null if no match
    060     */
    061    String lookup(String key);
    062}