comparison 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
comparison
equal deleted inserted replaced
1018:4dc1e1a18661 1019:f126d30e04a4
1 // to replace BufferCache
2
3 package org.eclipse.jetty.io;
4
5 import java.util.HashMap;
6 import java.util.Map;
7 import org.eclipse.jetty.util.StringUtil;
8
9
10 public class StringCache {
11 private final Map<String,Integer> stringToOrdinal = new HashMap<String,Integer>();
12 // private final Map<Integer,String> ordinalToString = new HashMap<Integer,String>();
13
14 public byte[] add(String value, int ordinal) {
15 stringToOrdinal.put(value.toLowerCase(), ordinal);
16 // ordinalToString.put(ordinal, value);
17 return StringUtil.getBytes(value);
18 }
19
20 public int getOrdinal(String value) {
21 Integer i = stringToOrdinal.get(value.toLowerCase());
22 return i==null ? -1 : i;
23 }
24
25 public boolean contains(String value) {
26 return stringToOrdinal.containsKey(value.toLowerCase());
27 }
28 }