Exemple #1
0
 /** Given an input string, level, and optionally a tag length, find a matching prefix. */
 private PrefixMatch findPrefixMatch(
     String input, TagLengthList tagLength, LevelTypeList level_type) {
   List<PrefixMatch> match_list = new ArrayList<PrefixMatch>();
   PrefixTree<PrefixMatch> tree = prefix_tree_map.get(level_type);
   assert tree != null;
   List<PrefixMatch> list = tree.search(input);
   if (!list.isEmpty()) {
     if (tagLength == null) match_list.addAll(list);
     else {
       for (PrefixMatch match : list)
         if (match.getScheme().getTagLength() == tagLength) match_list.add(match);
     }
   }
   if (match_list.isEmpty())
     throw new TDTException("No schemes or levels matched the input value");
   else if (match_list.size() > 1)
     throw new TDTException("More than one scheme/level matched the input value");
   else return match_list.get(0);
 }
Exemple #2
0
  /** initialise various indices */
  private void initFromTDT(EpcTagDataTranslation tdt) {
    Scheme[] scheme = tdt.getScheme();
    for (Scheme ss : scheme) {

      // create an index so that we can find a scheme based on tag length

      for (Level level : ss.getLevel()) {
        String s = level.getPrefixMatch();
        if (s != null) {
          // insert into prefix tree according to level type.
          PrefixTree<PrefixMatch> prefix_tree = prefix_tree_map.get(level.getType());
          if (prefix_tree == null) {
            prefix_tree = new PrefixTree<PrefixMatch>();
            prefix_tree_map.put(level.getType(), prefix_tree);
          }
          prefix_tree.insert(s, new PrefixMatch(ss, level));
        }
      }
    }
  }