View Javadoc

1   //
2   //  ========================================================================
3   //  Copyright (c) 1995-2013 Mort Bay Consulting Pty. Ltd.
4   //  ------------------------------------------------------------------------
5   //  All rights reserved. This program and the accompanying materials
6   //  are made available under the terms of the Eclipse Public License v1.0
7   //  and Apache License v2.0 which accompanies this distribution.
8   //
9   //      The Eclipse Public License is available at
10  //      http://www.eclipse.org/legal/epl-v10.html
11  //
12  //      The Apache License v2.0 is available at
13  //      http://www.opensource.org/licenses/apache2.0.php
14  //
15  //  You may elect to redistribute this code under either of these licenses.
16  //  ========================================================================
17  //
18  
19  package org.eclipse.jetty.util;
20  
21  import java.nio.ByteBuffer;
22  
23  
24  /* ------------------------------------------------------------ */
25  /** Abstract Trie implementation.
26   * <p>Provides some common implementations, which may not be the most
27   * efficient. For byte operations, the assumption is made that the charset
28   * is ISO-8859-1</p>
29   * @param <V>
30   */
31  public abstract class AbstractTrie<V> implements Trie<V>
32  {
33      final boolean _caseInsensitive;
34      
35      protected AbstractTrie(boolean insensitive)
36      {
37          _caseInsensitive=insensitive;
38      }
39  
40      @Override
41      public boolean put(V v)
42      {
43          return put(v.toString(),v);
44      }
45  
46      @Override
47      public V remove(String s)
48      {
49          V o=get(s);
50          put(s,null);
51          return o;
52      }
53  
54      @Override
55      public V get(String s)
56      {
57          return get(s,0,s.length());
58      }
59  
60      @Override
61      public V get(ByteBuffer b)
62      {
63          return get(b,0,b.remaining());
64      }
65  
66      @Override
67      public V getBest(String s)
68      {
69          return getBest(s,0,s.length());
70      }
71      
72      @Override
73      public V getBest(byte[] b, int offset, int len)
74      {
75          return getBest(new String(b,offset,len,StringUtil.__ISO_8859_1_CHARSET));
76      }
77  
78      @Override
79      public boolean isCaseInsensitive()
80      {
81          return _caseInsensitive;
82      }
83  
84  }