01: /**********************************************************************************
02: * $URL: https://source.sakaiproject.org/svn/content/tags/sakai_2-4-1/content-tool/tool/src/java/org/sakaiproject/content/tool/EntityCounter.java $
03: * $Id: EntityCounter.java 23076 2007-03-21 18:12:33Z jimeng@umich.edu $
04: ***********************************************************************************
05: *
06: * Copyright (c) 2007 The Sakai Foundation.
07: *
08: * Licensed under the Educational Community License, Version 1.0 (the "License");
09: * you may not use this file except in compliance with the License.
10: * You may obtain a copy of the License at
11: *
12: * http://www.opensource.org/licenses/ecl1.php
13: *
14: * Unless required by applicable law or agreed to in writing, software
15: * distributed under the License is distributed on an "AS IS" BASIS,
16: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17: * See the License for the specific language governing permissions and
18: * limitations under the License.
19: *
20: **********************************************************************************/package org.sakaiproject.content.tool;
21:
22: import java.util.HashMap;
23: import java.util.Map;
24:
25: /**
26: * EntityCounter
27: *
28: */
29: public class EntityCounter {
30: protected Map<String, Integer> values = new HashMap<String, Integer>();
31:
32: public void decrement(String key) {
33: Integer val = values.get(key);
34: if (val == null) {
35: values.put(key, new Integer(-1));
36: } else {
37: values.put(key, new Integer(val.intValue() - 1));
38: }
39: }
40:
41: public int getValue(String key) {
42: Integer val = values.get(key);
43: if (val == null) {
44: val = new Integer(0);
45: }
46: return val.intValue();
47: }
48:
49: public void increment(String key) {
50: Integer val = values.get(key);
51: if (val == null) {
52: values.put(key, new Integer(1));
53: } else {
54: values.put(key, new Integer(val.intValue() + 1));
55: }
56: }
57: }
|