001package edu.wpi.first.wpilibj.networktables2.util; 002 003import java.util.*; 004 005/** 006 * A simple cache that allows for caching the mapping of one string to another calculated one 007 * 008 * @author Mitchell 009 * 010 */ 011public abstract class StringCache { 012 private final Hashtable cache = new Hashtable(); 013 014 015 /** 016 * @param input 017 * @return the value for a given input 018 */ 019 public String get(final String input){ 020 String cachedValue = (String)cache.get(input); 021 if(cachedValue==null) 022 cache.put(input, cachedValue = calc(input)); 023 return cachedValue; 024 } 025 026 /** 027 * Will only be called if a value has not already been calculated 028 * @param input 029 * @return the calculated value for a given input 030 */ 031 public abstract String calc(String input); 032}