01 package org.apache.qpid.server.exchange.topic;
02
03 import org.apache.qpid.framing.AMQShortString;
04
05 import java.util.concurrent.ConcurrentHashMap;
06
07 /*
08 *
09 * Licensed to the Apache Software Foundation (ASF) under one
10 * or more contributor license agreements. See the NOTICE file
11 * distributed with this work for additional information
12 * regarding copyright ownership. The ASF licenses this file
13 * to you under the Apache License, Version 2.0 (the
14 * "License"); you may not use this file except in compliance
15 * with the License. You may obtain a copy of the License at
16 *
17 * http://www.apache.org/licenses/LICENSE-2.0
18 *
19 * Unless required by applicable law or agreed to in writing,
20 * software distributed under the License is distributed on an
21 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
22 * KIND, either express or implied. See the License for the
23 * specific language governing permissions and limitations
24 * under the License.
25 *
26 */
27 public class TopicWordDictionary
28 {
29 private final ConcurrentHashMap<AMQShortString,TopicWord> _dictionary =
30 new ConcurrentHashMap<AMQShortString,TopicWord>();
31
32
33
34 public TopicWordDictionary()
35 {
36 _dictionary.put(new AMQShortString("*"), TopicWord.ANY_WORD);
37 _dictionary.put(new AMQShortString("#"), TopicWord.WILDCARD_WORD);
38 }
39
40
41
42
43 public TopicWord getOrCreateWord(AMQShortString name)
44 {
45 TopicWord word = _dictionary.putIfAbsent(name, new TopicWord(name));
46 if(word == null)
47 {
48 word = _dictionary.get(name);
49 }
50 return word;
51 }
52
53
54 public TopicWord getWord(AMQShortString name)
55 {
56 TopicWord word = _dictionary.get(name);
57 if(word == null)
58 {
59 word = TopicWord.ANY_WORD;
60 }
61 return word;
62 }
63 }
|