1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache license, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the license for the specific language governing permissions and 15 * limitations under the license. 16 */ 17 18 package org.apache.commons.text.lookup; 19 20 /** 21 * Lookups a String key for a String value. 22 * <p> 23 * This class represents the simplest form of a string to string map. It has a benefit over a map in that it can create 24 * the result on demand based on the key. 25 * </p> 26 * <p> 27 * For example, it would be possible to implement a lookup that used the key as a primary key, and looked up the value 28 * on demand from the database. 29 * </p> 30 * 31 * @since 1.3 32 */ 33 @FunctionalInterface 34 public interface StringLookup { 35 36 /** 37 * Looks up a String key to provide a String value. 38 * <p> 39 * The internal implementation may use any mechanism to return the value. The simplest implementation is to use a 40 * Map. However, virtually any implementation is possible. 41 * </p> 42 * <p> 43 * For example, it would be possible to implement a lookup that used the key as a primary key, and looked up the 44 * value on demand from the database Or, a numeric based implementation could be created that treats the key as an 45 * integer, increments the value and return the result as a string - converting 1 to 2, 15 to 16 etc. 46 * </p> 47 * <p> 48 * This method always returns a String, regardless of the underlying data, by converting it as necessary. For 49 * example: 50 * </p> 51 * 52 * <pre> 53 * Map<String, Object> map = new HashMap<String, Object>(); 54 * map.put("number", new Integer(2)); 55 * assertEquals("2", StringLookupFactory.mapStringLookup(map).lookup("number")); 56 * </pre> 57 * 58 * @param key the key to look up, may be null. 59 * @return The matching value, null if no match. 60 */ 61 String lookup(String key); 62 }