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  import java.nio.charset.StandardCharsets;
23  
24  
25  /* ------------------------------------------------------------ */
26  /** Abstract Trie implementation.
27   * <p>Provides some common implementations, which may not be the most
28   * efficient. For byte operations, the assumption is made that the charset
29   * is ISO-8859-1</p>
30   * @param <V>
31   */
32  public abstract class AbstractTrie<V> implements Trie<V>
33  {
34      final boolean _caseInsensitive;
35      
36      protected AbstractTrie(boolean insensitive)
37      {
38          _caseInsensitive=insensitive;
39      }
40  
41      @Override
42      public boolean put(V v)
43      {
44          return put(v.toString(),v);
45      }
46  
47      @Override
48      public V remove(String s)
49      {
50          V o=get(s);
51          put(s,null);
52          return o;
53      }
54  
55      @Override
56      public V get(String s)
57      {
58          return get(s,0,s.length());
59      }
60  
61      @Override
62      public V get(ByteBuffer b)
63      {
64          return get(b,0,b.remaining());
65      }
66  
67      @Override
68      public V getBest(String s)
69      {
70          return getBest(s,0,s.length());
71      }
72      
73      @Override
74      public V getBest(byte[] b, int offset, int len)
75      {
76          return getBest(new String(b,offset,len,StandardCharsets.ISO_8859_1));
77      }
78  
79      @Override
80      public boolean isCaseInsensitive()
81      {
82          return _caseInsensitive;
83      }
84  
85  }