view src/org/eclipse/jetty/io/StringCache.java @ 1019:f126d30e04a4

start replacing BufferCache with StringCache
author Franklin Schmidt <fschmidt@gmail.com>
date Mon, 31 Oct 2016 03:33:42 -0600
parents
children 6be43ef1eb96
line wrap: on
line source

// to replace BufferCache

package org.eclipse.jetty.io;

import java.util.HashMap;
import java.util.Map;
import org.eclipse.jetty.util.StringUtil;


public class StringCache {
	private final Map<String,Integer> stringToOrdinal = new HashMap<String,Integer>();
//	private final Map<Integer,String> ordinalToString = new HashMap<Integer,String>();

	public byte[] add(String value, int ordinal) {
		stringToOrdinal.put(value.toLowerCase(), ordinal);
//		ordinalToString.put(ordinal, value);
		return StringUtil.getBytes(value);
	}

	public int getOrdinal(String value) {
		Integer i = stringToOrdinal.get(value.toLowerCase());
		return i==null ? -1 : i;
	}

	public boolean contains(String value) {
		return stringToOrdinal.containsKey(value.toLowerCase());
	}
}