diff 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 diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/org/eclipse/jetty/io/StringCache.java	Mon Oct 31 03:33:42 2016 -0600
@@ -0,0 +1,28 @@
+// 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());
+	}
+}