• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2008 Esmertec AG.
3  * Copyright (C) 2008 The Android Open Source Project
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 package com.android.mms.util;
19 
20 import android.util.Config;
21 import android.util.Log;
22 
23 import java.util.HashMap;
24 
25 public class SendingProgressTokenManager {
26     private static final String TAG = "SendingProgressTokenManager";
27     private static final boolean DEBUG = false;
28     private static final boolean LOCAL_LOGV = DEBUG ? Config.LOGD : Config.LOGV;
29     private static final HashMap<Object, Long> TOKEN_POOL;
30 
31     public static final long NO_TOKEN = -1L;
32 
33     static {
34         TOKEN_POOL = new HashMap<Object, Long>();
35     }
36 
get(Object key)37     synchronized public static long get(Object key) {
38         Long token = TOKEN_POOL.get(key);
39         if (LOCAL_LOGV) {
40             Log.v(TAG, "TokenManager.get(" + key + ") -> " + token);
41         }
42         return token != null ? token : NO_TOKEN;
43     }
44 
put(Object key, long token)45     synchronized public static void put(Object key, long token) {
46         if (LOCAL_LOGV) {
47             Log.v(TAG, "TokenManager.put(" + key + ", " + token + ")");
48         }
49         TOKEN_POOL.put(key, token);
50     }
51 
remove(Object key)52     synchronized public static void remove(Object key) {
53         if (LOCAL_LOGV) {
54             Log.v(TAG, "TokenManager.remove(" + key + ")");
55         }
56         TOKEN_POOL.remove(key);
57     }
58 }
59