Code example for NavigableMap

Methods: ceilingEntry, floorEntry, put

0
    translation.replacementText = replacementText;
 
    // Sanity check for overlap with regions already being expanded 
    assert (tokenStopIndex >= tokenStartIndex);
    Map.Entry<Integer, Translation> existingEntry;
    existingEntry = translations.floorEntry(tokenStartIndex);
    boolean prefix = false;
    if (existingEntry != null) {
      if (existingEntry.getKey().equals(tokenStartIndex)) {
        if (existingEntry.getValue().tokenStopIndex == tokenStopIndex) {
          if (existingEntry.getValue().replacementText.equals(replacementText)) {
            // exact match for existing mapping: somebody is doing something 
            // redundant, but we'll let it pass 
            return; 
          } 
        } else if (tokenStopIndex > existingEntry.getValue().tokenStopIndex) {
          // is existing mapping a prefix for new mapping? if so, that's also 
          // redundant, but in this case we need to expand it 
          prefix = replacementText.startsWith(
            existingEntry.getValue().replacementText);
          assert(prefix);
        } else { 
          // new mapping is a prefix for existing mapping:  ignore it 
          prefix = existingEntry.getValue().replacementText.startsWith(
            replacementText);
          assert(prefix);
          return; 
        } 
      } 
      if (!prefix) {
        assert (existingEntry.getValue().tokenStopIndex < tokenStartIndex);
      } 
    } 
    if (!prefix) {
      existingEntry = translations.ceilingEntry(tokenStartIndex);
      if (existingEntry != null) {
        assert (existingEntry.getKey() > tokenStopIndex);
      } 
    } 
 
    // It's all good: create a new entry in the map (or update existing one) 
    translations.put(tokenStartIndex, translation);
  } 
 
  /** 
   * Register a translation for an tabName. 
   *