1 /* 2 * Copyright 2004-2006 the Seasar Foundation and the Others. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 13 * either express or implied. See the License for the specific language 14 * governing permissions and limitations under the License. 15 */ 16 package com.isenshi.util; 17 18 import java.util.HashMap; 19 import java.util.LinkedHashMap; 20 import java.util.Map; 21 22 public class TableMap { 23 24 private Map map = new HashMap(); 25 26 public void remove(String key) { 27 synchronized (map) { 28 map.remove(key); 29 } 30 } 31 32 public void put(Object value, Object key1, Object key2) { 33 synchronized (map) { 34 Map submap = (Map) map.get(key1); 35 if (submap == null) { 36 submap = new LinkedHashMap(); 37 map.put(key1, submap); 38 } 39 submap.put(key2, value); 40 } 41 } 42 43 public Object get(Object key1, Object key2) { 44 Object ret = null; 45 synchronized (map) { 46 Map submap = (Map) map.get(key1); 47 if (submap != null) { 48 ret = submap.get(key2); 49 50 } 51 } 52 return ret; 53 } 54 55 public Object remove(String key1, String key2) { 56 Object ret = null; 57 synchronized (map) { 58 Map submap = (Map) map.get(key1); 59 if (submap != null) { 60 ret = submap.remove(key2); 61 } 62 } 63 return ret; 64 } 65 66 public Map getSubMap(String key1) { 67 Map retSubmap = null; 68 synchronized (map) { 69 Map submap = (Map) map.get(key1); 70 if (submap != null) { 71 retSubmap = new LinkedHashMap(); 72 retSubmap.putAll(submap); 73 } 74 } 75 return retSubmap; 76 } 77 }