1 // 2 // ======================================================================== 3 // Copyright (c) 1995-2016 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.util.Set; 23 24 25 /* ------------------------------------------------------------ */ 26 /** A Trie String lookup data structure. 27 * @param <V> the Trie entry type 28 */ 29 public interface Trie<V> 30 { 31 /* ------------------------------------------------------------ */ 32 /** Put and entry into the Trie 33 * @param s The key for the entry 34 * @param v The value of the entry 35 * @return True if the Trie had capacity to add the field. 36 */ 37 public boolean put(String s, V v); 38 39 /* ------------------------------------------------------------ */ 40 /** Put a value as both a key and a value. 41 * @param v The value and key 42 * @return True if the Trie had capacity to add the field. 43 */ 44 public boolean put(V v); 45 46 /* ------------------------------------------------------------ */ 47 public V remove(String s); 48 49 /* ------------------------------------------------------------ */ 50 /** Get and exact match from a String key 51 * @param s The key 52 * @return the value for the string key 53 */ 54 public V get(String s); 55 56 /* ------------------------------------------------------------ */ 57 /** Get and exact match from a String key 58 * @param s The key 59 * @param offset The offset within the string of the key 60 * @param len the length of the key 61 * @return the value for the string / offset / length 62 */ 63 public V get(String s,int offset,int len); 64 65 /* ------------------------------------------------------------ */ 66 /** Get and exact match from a segment of a ByteBuufer as key 67 * @param b The buffer 68 * @return The value or null if not found 69 */ 70 public V get(ByteBuffer b); 71 72 /* ------------------------------------------------------------ */ 73 /** Get and exact match from a segment of a ByteBuufer as key 74 * @param b The buffer 75 * @param offset The offset within the buffer of the key 76 * @param len the length of the key 77 * @return The value or null if not found 78 */ 79 public V get(ByteBuffer b,int offset,int len); 80 81 /* ------------------------------------------------------------ */ 82 /** Get the best match from key in a String. 83 * @param s The string 84 * @return The value or null if not found 85 */ 86 public V getBest(String s); 87 88 /* ------------------------------------------------------------ */ 89 /** Get the best match from key in a String. 90 * @param s The string 91 * @param offset The offset within the string of the key 92 * @param len the length of the key 93 * @return The value or null if not found 94 */ 95 public V getBest(String s,int offset,int len); 96 97 /* ------------------------------------------------------------ */ 98 /** Get the best match from key in a byte array. 99 * The key is assumed to by ISO_8859_1 characters. 100 * @param b The buffer 101 * @param offset The offset within the array of the key 102 * @param len the length of the key 103 * @return The value or null if not found 104 */ 105 public V getBest(byte[] b,int offset,int len); 106 107 /* ------------------------------------------------------------ */ 108 /** Get the best match from key in a byte buffer. 109 * The key is assumed to by ISO_8859_1 characters. 110 * @param b The buffer 111 * @param offset The offset within the buffer of the key 112 * @param len the length of the key 113 * @return The value or null if not found 114 */ 115 public V getBest(ByteBuffer b,int offset,int len); 116 117 /* ------------------------------------------------------------ */ 118 public Set<String> keySet(); 119 120 /* ------------------------------------------------------------ */ 121 public boolean isFull(); 122 123 /* ------------------------------------------------------------ */ 124 public boolean isCaseInsensitive(); 125 126 /* ------------------------------------------------------------ */ 127 public void clear(); 128 129 }