private boolean isSourceOppositeToTargetInt(
      long sourceSense, long targetSense, POS sourcePOS, POS targetPOS) {
    long key;
    if (targetSense > sourceSense) {
      key = (targetSense << 32) + sourceSense;
    } else {
      key = (sourceSense << 32) + targetSense;
    }

    if ((POS.NOUN == sourcePOS) && (POS.NOUN == targetPOS)) {
      if (Arrays.binarySearch(noun_opp, key) >= 0) {
        log.trace("Found ! using ! (ANTONYM) between nouns");
        return true;
      }
    } else {
      if ((POS.ADJECTIVE == sourcePOS) && (POS.ADJECTIVE == targetPOS)) {
        if (Arrays.binarySearch(adj_opp, key) >= 0) {
          log.trace("Found ! using ! (ANTONYM) between adjectives");
          return true;
        }
      } else {
        if ((POS.ADVERB == sourcePOS) && (POS.ADVERB == targetPOS)) {
          if (Arrays.binarySearch(adv_opp, key) >= 0) {
            log.trace("Found ! using ! (ANTONYM) between adverbs");
            return true;
          }
        }
      }
    }

    return false;
  }
  private boolean isSourceSynonymTargetInt(
      long sourceSense, long targetSense, POS sourcePOS, POS targetPOS) {
    if (sourceSense == targetSense) {
      return true;
    }

    long key;
    if (targetSense > sourceSense) {
      key = (targetSense << 32) + sourceSense;
    } else {
      key = (sourceSense << 32) + targetSense;
    }

    if ((POS.ADJECTIVE == sourcePOS) && (POS.ADJECTIVE == targetPOS)) {
      if (Arrays.binarySearch(adj_syn, key) >= 0) {
        log.trace("Found = using & (SIMILAR_TO) between adjectives");
        return true;
      }
    }
    if ((POS.NOUN == sourcePOS) && (POS.VERB == targetPOS)) {
      key = (targetSense << 32) + sourceSense;
      if (Arrays.binarySearch(nominalizations, key) >= 0) {
        log.trace("Found = using + (DERIVATION) between a noun and a verb");
        return true;
      }
    }
    if ((POS.VERB == sourcePOS) && (POS.NOUN == targetPOS)) {
      key = (sourceSense << 32) + targetSense;
      if (Arrays.binarySearch(nominalizations, key) >= 0) {
        log.trace("Found = using + (DERIVATION) between a verb and a noun");
        return true;
      }
    }
    return false;
  }
 public static final boolean accepts(final String acceptHeader, final String toAccept) {
   final String[] acceptValues = acceptHeader.split("\\s*(,|;)\\s*");
   Arrays.sort(acceptValues);
   return Arrays.binarySearch(acceptValues, toAccept) > -1
       || Arrays.binarySearch(acceptValues, toAccept.replaceAll("/.*$", "/*")) > -1
       || Arrays.binarySearch(acceptValues, "*/*") > -1;
 }
Example #4
1
 public void solve(int testNumber, FastScanner in, FastPrinter out) {
   int n = in.nextInt();
   int p = in.nextInt();
   int m = in.nextInt();
   Query[] qs = new Query[m];
   int[] z = new int[4 * m + 10];
   int cn = 0;
   for (int i = 0; i < m; i++) {
     int time = in.nextInt();
     int type = in.next().equals("save") ? 0 : 1;
     int a = in.nextInt();
     int b = in.nextInt();
     qs[i] = new Query(time, type, a, b);
     if (type == 0) {
       z[cn++] = a - 1;
       z[cn++] = b;
     } else {
       --a;
       z[cn++] = a - b + 1;
       z[cn++] = a;
       z[cn++] = a + b;
     }
   }
   z[cn++] = 0;
   z[cn++] = n;
   z = Arrays.copyOf(z, cn);
   z = ArrayUtils.sortAndUnique(z);
   int[] cnt = new int[z.length - 1];
   {
     for (int i = 0; i < z.length - 1; i++) {
       cnt[i] = z[i + 1] - z[i];
     }
   }
   SegmentTree tree = new SegmentTree(cnt);
   int last = 0;
   double all = 0;
   for (int i = 0; i < m; i++) {
     int time = qs[i].time;
     tree.addValue(0, cnt.length, 1. * p * (time - last), 0);
     last = time;
     if (qs[i].type == 0) {
       int l = qs[i].a - 1;
       int r = qs[i].b;
       l = Arrays.binarySearch(z, l);
       r = Arrays.binarySearch(z, r);
       double sum = tree.getSum(l, r);
       all += sum;
       out.println(all);
       tree.setZero(l, r);
     } else {
       int index = qs[i].a - 1;
       int d = qs[i].b;
       double x = all / (2 * SegmentTree.sum(d) + d);
       int id = Arrays.binarySearch(z, index);
       tree.addValue(Arrays.binarySearch(z, index - d + 1), id, x, x);
       tree.addValue(id, Arrays.binarySearch(z, index + d), d * x, -x);
       all = 0;
     }
   }
 }
 public static double[][] pxy(double[] x, double[] y, double min, double max, int nIntervals) {
   if (x.length != y.length) return null;
   double[][] count = new double[nIntervals][nIntervals];
   double[] intervals = new double[nIntervals];
   for (int i = 0; i < nIntervals; i++) {
     intervals[i] = min + (max - min) / nIntervals * (i + 1);
   }
   for (int i = 0; i < x.length; i++) {
     int posx = Arrays.binarySearch(intervals, x[i]);
     // if posx >= 0, it matches one of the interval limits:
     if (posx < 0) {
       if (posx == -1) posx = 0;
       else posx = -posx - 2;
     }
     for (int j = 0; j < y.length; j++) {
       int posy = Arrays.binarySearch(intervals, y[i]);
       if (posy < 0) {
         if (posy == -1) posy = 0;
         else posy = -posy - 2;
       }
       count[posx][posy]++;
     }
   }
   for (int i = 0; i < nIntervals; i++) {
     for (int j = 0; j < nIntervals; j++) {
       count[i][j] /= x.length;
     }
   }
   return count;
 }
Example #6
1
 // Makes sure QueryKeys have no problem going in and out of GGEP blocks
 public void testQueryKeysAndGGEP() throws Exception {
   MACCalculatorRepositoryManager macManager = new MACCalculatorRepositoryManager();
   Random rand = new Random();
   for (int i = 4; i < 17; i++) {
     byte[] qk = new byte[i];
     Arrays.sort(qk);
     // make sure the bytes have offensive characters....
     while ((Arrays.binarySearch(qk, (byte) 0x1c) < 0)
         || (Arrays.binarySearch(qk, (byte) 0x00) < 0)) {
       rand.nextBytes(qk);
       Arrays.sort(qk);
     }
     AddressSecurityToken addressSecurityToken = new AddressSecurityToken(qk, macManager);
     ByteArrayOutputStream baos = new ByteArrayOutputStream();
     addressSecurityToken.write(baos);
     GGEP in = new GGEP(true);
     in.put(GGEPKeys.GGEP_HEADER_QUERY_KEY_SUPPORT, baos.toByteArray());
     baos = new ByteArrayOutputStream();
     in.write(baos);
     GGEP out = new GGEP(baos.toByteArray(), 0, null);
     AddressSecurityToken queryKey2 =
         new AddressSecurityToken(
             out.getBytes(GGEPKeys.GGEP_HEADER_QUERY_KEY_SUPPORT), macManager);
     assertEquals("qks not equal, i = " + i, addressSecurityToken, queryKey2);
   }
 }
Example #7
0
 public int indexOfWithType(int val) {
   if (withDummy) {
     return Arrays.binarySearch(_elements, 1, _elements.length, val);
   } else {
     return Arrays.binarySearch(_elements, val);
   }
 }
Example #8
0
 private boolean indexField(Document document, Object state, String fieldName, Type type) {
   if (Arrays.binarySearch(FIELDS, fieldName) >= 0) {
     // index all fields we know about
     document.add(new Field(fieldName, (String) state, Field.Store.YES, Field.Index.TOKENIZED));
     document.add(
         new Field(Indexer.DEFAULT_FIELD, (String) state, Field.Store.NO, Field.Index.TOKENIZED));
     return true;
   } else if (type instanceof StringType) {
     // index all strings with the exception of the fields explicitly listed as sensitive
     if (Arrays.binarySearch(SENSITIVE_FIELDS, fieldName) < 0) {
       document.add(
           new Field(
               Indexer.DEFAULT_FIELD, (String) state, Field.Store.NO, Field.Index.TOKENIZED));
     }
     return true;
   } else if (fieldName.equals("aliases")) {
     Set aliases = (Set) state;
     for (Iterator a = aliases.iterator(); a.hasNext(); ) {
       String alias = (String) a.next();
       document.add(new Field("alias", alias, Field.Store.NO, Field.Index.TOKENIZED));
       document.add(
           new Field(Indexer.DEFAULT_FIELD, alias, Field.Store.NO, Field.Index.TOKENIZED));
     }
     return true;
   }
   return false;
 }
  public boolean trigger(int event, int damage, byte element, boolean playable, L2Skill skill) {
    if (_pvpOnly && !playable) {
      return false;
    }

    if (_elements != null && Arrays.binarySearch(_elements, element) < 0) {
      return false;
    }

    if (_activationSkills != null
        && skill != null
        && Arrays.binarySearch(_activationSkills, skill.getId()) < 0) {
      return false;
    }

    // onCast is called on every skill cast, so we must check if trigger
    // have limit (can be triggered only by some specific skill)
    if (_bySkillId > 0 && (skill == null || skill.getId() != _bySkillId)) {
      return false;
    }

    // if the skill has "activationMinDamage" setted to higher than -1(default)
    // and if "activationMinDamage" is still higher than the recieved damage, the skill wont trigger
    if (_mindmg > -1 && _mindmg > damage) {
      return false;
    }

    return _triggerType.check(event) && (_chance < 0 || Rnd.getChance(_chance));
  }
Example #10
0
 // set sequences to null or empty to get all sequences
 // set positions to null or empty to get all posistions
 public Msa createSubAlignment(final int[] sequences, final int[] positions) {
   final Msa msa = new BasicMsa();
   boolean return_all_seqs = false;
   boolean return_all_pos = false;
   if ((sequences == null) || (sequences.length < 1)) {
     return_all_seqs = true;
   } else {
     Arrays.sort(sequences);
   }
   if ((positions == null) || (positions.length < 1)) {
     return_all_pos = true;
   } else {
     Arrays.sort(positions);
   }
   for (int s = 0; s < getNumberOfSequences(); ++s) {
     if (return_all_seqs || (Arrays.binarySearch(sequences, s) >= 0)) {
       for (int p = 0; p < getLength(); ++p) {
         if (return_all_pos || (Arrays.binarySearch(positions, p) >= 0)) {
           // FIXME finish me
         }
       }
     }
   }
   return msa;
 }
Example #11
0
 private boolean usesPrefixByExtlang(String language, String extlang) {
   int langIndex = Arrays.binarySearch(languages, language);
   int extlangIndex = Arrays.binarySearch(extlangs, extlang);
   assert langIndex > -1;
   int prefixExpected = prefixByExtlang[extlangIndex];
   return prefixExpected == langIndex;
 }
Example #12
0
 /**
  * we try to get the nearest synchronized sample to our desired start time. Afterwards, we are
  * ready to crop each track of the video.
  */
 private double correctTimeToNextSyncSample(Track track, double cropVidPlace, boolean nextPlace) {
   double[] timeOfSyncSamples = new double[track.getSyncSamples().length];
   long currentSample = 0;
   double currentTime = 0;
   for (int i = 0; i < track.getDecodingTimeEntries().size(); i++) {
     TimeToSampleBox.Entry entry = track.getDecodingTimeEntries().get(i);
     for (int j = 0; j < entry.getCount(); j++) {
       if (Arrays.binarySearch(track.getSyncSamples(), currentSample + 1) >= 0) {
         // samples always start with 1 but we start with zero therefore +1
         timeOfSyncSamples[Arrays.binarySearch(track.getSyncSamples(), currentSample + 1)] =
             currentTime;
       }
       currentTime += (double) entry.getDelta() / (double) track.getTrackMetaData().getTimescale();
       currentSample++;
     }
   }
   double previous = 0;
   for (double timeOfSyncSample : timeOfSyncSamples) {
     if (timeOfSyncSample > cropVidPlace) {
       if (nextPlace) {
         return timeOfSyncSample;
       } else {
         return previous;
       }
     }
     previous = timeOfSyncSample;
   }
   return timeOfSyncSamples[timeOfSyncSamples.length - 1];
 }
Example #13
0
  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));

    while (true) {
      String line = br.readLine();
      StringTokenizer st = new StringTokenizer(line);
      int a = Integer.parseInt(st.nextToken());
      int b = Integer.parseInt(st.nextToken());
      if (a == 0 && b == 0) {
        break;
      }

      int[] c1 = new int[a];
      int[] c2 = new int[b];
      st = new StringTokenizer(br.readLine());
      for (int i = 0; i < a; i++) {
        c1[i] = Integer.parseInt(st.nextToken());
      }

      st = new StringTokenizer(br.readLine());
      for (int i = 0; i < b; i++) {
        c2[i] = Integer.parseInt(st.nextToken());
      }

      Arrays.sort(c1);
      Arrays.sort(c2);

      int prev = -Integer.MIN_VALUE;
      int count1 = 0;
      for (int i = 0; i < a; i++) {
        if (prev == c1[i]) {
          continue;
        }
        prev = c1[i];
        if (Arrays.binarySearch(c2, c1[i]) < 0) {
          count1++;
        }
      }

      prev = -Integer.MIN_VALUE;
      int count2 = 0;
      for (int i = 0; i < b; i++) {
        if (prev == c2[i]) {
          continue;
        }
        prev = c2[i];
        if (Arrays.binarySearch(c1, c2[i]) < 0) {
          count2++;
        }
      }

      bw.write((count1 > count2 ? count2 : count1) + "\n");
    }

    br.close();
    bw.flush();
    bw.close();
  }
Example #14
0
 public int indexOfWithOffset(int value, int offset) {
   if (withDummy) {
     if (offset >= _elements.length) return -1;
     return Arrays.binarySearch(_elements, offset, _elements.length, value);
   } else {
     return Arrays.binarySearch(_elements, offset, _elements.length, value);
   }
 }
Example #15
0
 public int indexOfWithOffset(Integer value, int offset) {
   if (withDummy) {
     if (value == null || offset >= _elements.length) return -1;
     return Arrays.binarySearch(_elements, offset, _elements.length, value.intValue());
   } else {
     return Arrays.binarySearch(_elements, offset, _elements.length, value.intValue());
   }
 }
Example #16
0
 public int indexOf(Integer value) {
   if (withDummy) {
     if (value == null) return -1;
     return Arrays.binarySearch(_elements, 1, _elements.length, value.intValue());
   } else {
     return Arrays.binarySearch(_elements, value.intValue());
   }
 }
Example #17
0
  public Spannable processEmojiMutable(CharSequence s, int mode) {

    long prev = 0;
    long prevLong = 0;
    int prevLongCount = 0;

    ArrayList<SpanDescription> list = new ArrayList<SpanDescription>();

    for (int i = 0; i < s.length(); i++) {
      long current = s.charAt(i);

      if (prevLongCount == 3) {
        long prevId = ((prevLong & 0xFFFFFFFF) << 16) + current;
        if (Arrays.binarySearch(EMOJI_SORTED, prevId) >= 0) {
          list.add(new SpanDescription(prevId, i - 3, i + 1));
          prev = 0;
          prevLong = 0;
          prevLongCount = 0;
          continue;
        }
      }

      if (prev != 0) {
        long prevId = ((prev & 0xFFFF) << 16) + current;
        if (Arrays.binarySearch(EMOJI_SORTED, prevId) >= 0) {
          list.add(new SpanDescription(prevId, i - 1, i + 1));
          prev = 0;
          prevLong = 0;
          prevLongCount = 0;
          continue;
        }
      }

      if (Arrays.binarySearch(EMOJI_SORTED, current) >= 0) {
        list.add(new SpanDescription(current, i, i + 1));
        prev = 0;
        prevLong = 0;
        prevLongCount = 0;
      } else {
        prev = current;
        prevLong = ((prevLong & 0xFFFFFFFF) << 16) + current;
        if (prevLongCount < 3) {
          prevLongCount++;
        }
      }
    }

    Spannable spannable = spannableFactory.newSpannable(s);
    for (SpanDescription description : list) {
      spannable.setSpan(
          new EmojiSpan(
              this, indexes.get(description.id), emojiSideSize, originalMetrics.get(mode)),
          description.start,
          description.end,
          Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    }
    return spannable;
  }
Example #18
0
 @Override
 public int indexOfWithType(Integer val) {
   if (withDummy) {
     if (val == null) return -1;
     return Arrays.binarySearch(_elements, 1, _elements.length, val.intValue());
   } else {
     return Arrays.binarySearch(_elements, val.intValue());
   }
 }
Example #19
0
 public static void main(String[] args) {
   String[] sa = {"one", "two", "three", "four", "five"};
   //        Arrays.sort(sa);
   System.out.println("Sorted : " + Arrays.toString(sa));
   //        Arrays.sort(sa, new ReSortComparator());
   System.out.println("Reverse : " + Arrays.toString(sa));
   System.out.println("One is at " + Arrays.binarySearch(sa, "one"));
   System.out.println("Off is at " + Arrays.binarySearch(sa, "off"));
 }
Example #20
0
 @Override
 public boolean containsWithType(Integer val) {
   if (withDummy) {
     if (val == null) return false;
     return Arrays.binarySearch(_elements, 1, _elements.length, val.intValue()) >= 0;
   } else {
     return Arrays.binarySearch(_elements, val.intValue()) >= 0;
   }
 }
Example #21
0
  public static double[] extractInterval(double[] array, double a, double b) {
    int i = Arrays.binarySearch(array, a);
    if (i < 0) i = -i - 1; // see binarySearch docs

    int j = Arrays.binarySearch(array, i, array.length, b);
    if (j < 0) j = -j - 1;
    else j = j + 1;

    return Arrays.copyOfRange(array, i, j);
  }
Example #22
0
 /**
  * Gets Label font name awaylable on current running os
  *
  * @return label font name
  */
 private static String getLabelFontName() {
   GraphicsEnvironment g = GraphicsEnvironment.getLocalGraphicsEnvironment();
   String[] names = g.getAvailableFontFamilyNames();
   Arrays.sort(names);
   if (SystemUtils.isMac() && Arrays.binarySearch(names, "Helvetica Neue") >= 0)
     return "Helvetica Neue";
   else if (Arrays.binarySearch(names, "Helvetica") >= 0) return "Helvetica";
   else if (Arrays.binarySearch(names, "Arial") >= 0) return "Arial";
   return getMonospacedFontName();
 }
Example #23
0
 @Override
 public int indexOfWithOffset(Object value, int offset) {
   if (withDummy) {
     if (value == null || offset >= _elements.length) return -1;
     int val = parse(String.valueOf(value));
     return Arrays.binarySearch(_elements, offset, _elements.length, val);
   } else {
     int val = parse(String.valueOf(value));
     return Arrays.binarySearch(_elements, offset, _elements.length, val);
   }
 }
Example #24
0
 public double get(int i) {
   int off = numStart();
   if (i >= off) { // numbers
     if (numIds == null) return numVals[i - off];
     int j = Arrays.binarySearch(numIds, 0, nNums, i);
     return j >= 0 ? numVals[j] : 0;
   } else { // categoricals
     int j = Arrays.binarySearch(binIds, 0, nBins, i);
     return j >= 0 ? 1 : 0;
   }
 }
 /** @param args */
 public static void main(String[] args) {
   // if the key is not found the insertion point is calculated
   // by (-(inserpoint)-1)
   String[] sa = {"hi", "the", "string", "using", "binarySearch"};
   Arrays.sort(sa);
   for (String s : sa) {
     System.out.println("s****value****" + s);
   }
   System.out.println("search value****" + Arrays.binarySearch(sa, "i"));
   char c[] = {'a', 'b', 'c', 'd', 'e'};
   System.out.println("Character binary search***" + Arrays.binarySearch(c, 'p'));
 }
Example #26
0
  /** Reload the list of widgets */
  public void refresh() throws MMPException {
    try {
      // Lock Thread
      this.lock.lock();
      long lastDAOUpdate =
          DaoManagerFactory.getInstance().getDaoManager().getDao("module").getLastUpdateTimestamp();
      if (this.lastUpdate < lastDAOUpdate) {
        this.lastUpdate = lastDAOUpdate;
        // Get list of installed modules
        Module[] installedModules =
            (Module[]) DaoManagerFactory.getInstance().getDaoManager().getDao("module").list();
        Arrays.sort(installedModules);

        // Search removed modules
        for (Module runningModule : this.runningModules) {
          // Module removed
          if (Arrays.binarySearch(installedModules, runningModule) < 0) {
            this.removeModule(runningModule);
          }
        }

        // Search added and updates modules
        for (Module installedModule : installedModules) {
          int moduleIndex = Arrays.binarySearch(runningModules, installedModule);
          // Module added
          if (moduleIndex < 0) {
            this.addModule(installedModule);
          } else {
            // Get current running module
            Module runningModule = runningModules[moduleIndex];
            // Check if module has been updated
            boolean mustUpdate = false;
            // Check version
            if (installedModule.getVersion() != null && runningModule.getVersion() != null) {
              mustUpdate =
                  (installedModule.getVersion().compareTo(runningModule.getVersion()) != 0);
            }

            // Make update if needed
            if (mustUpdate) {
              this.removeModule(runningModule);
              this.addModule(installedModule);
            }
          }
        }
        this.runningModules = installedModules;
      }
    } finally {
      // Unlock thread
      this.lock.unlock();
    }
  }
Example #27
0
  public static void updateCharOffsetManyRegs(
      DynamicObject matchData, ByteList value, Encoding encoding) {
    assert RubyGuards.isRubyMatchData(matchData);
    if (Layouts.MATCH_DATA.getFields(matchData).charOffsetUpdated) return;

    final Region regs = Layouts.MATCH_DATA.getFields(matchData).region;
    int numRegs = regs.numRegs;

    if (Layouts.MATCH_DATA.getFields(matchData).charOffsets == null
        || Layouts.MATCH_DATA.getFields(matchData).charOffsets.numRegs < numRegs)
      Layouts.MATCH_DATA.getFields(matchData).charOffsets = new Region(numRegs);

    if (encoding.maxLength() == 1) {
      for (int i = 0; i < numRegs; i++) {
        Layouts.MATCH_DATA.getFields(matchData).charOffsets.beg[i] = regs.beg[i];
        Layouts.MATCH_DATA.getFields(matchData).charOffsets.end[i] = regs.end[i];
      }
      Layouts.MATCH_DATA.getFields(matchData).charOffsetUpdated = true;
      return;
    }

    Pair[] pairs = new Pair[numRegs * 2];
    for (int i = 0; i < pairs.length; i++) pairs[i] = new Pair();

    int numPos = 0;
    for (int i = 0; i < numRegs; i++) {
      if (regs.beg[i] < 0) continue;
      pairs[numPos++].bytePos = regs.beg[i];
      pairs[numPos++].bytePos = regs.end[i];
    }

    updatePairs(value, encoding, pairs);

    Pair key = new Pair();
    for (int i = 0; i < regs.numRegs; i++) {
      if (regs.beg[i] < 0) {
        Layouts.MATCH_DATA.getFields(matchData).charOffsets.beg[i] =
            Layouts.MATCH_DATA.getFields(matchData).charOffsets.end[i] = -1;
        continue;
      }
      key.bytePos = regs.beg[i];
      Layouts.MATCH_DATA.getFields(matchData).charOffsets.beg[i] =
          pairs[Arrays.binarySearch(pairs, key)].charPos;
      key.bytePos = regs.end[i];
      Layouts.MATCH_DATA.getFields(matchData).charOffsets.end[i] =
          pairs[Arrays.binarySearch(pairs, key)].charPos;
    }

    Layouts.MATCH_DATA.getFields(matchData).charOffsetUpdated = true;
  }
Example #28
0
 private static String keyTransform(String note, int key) {
   if (note.length() == 3) return note;
   if (key < 0) {
     char[] flatRange = Arrays.copyOfRange(circleOfFifths, 7 + key, 7);
     Arrays.sort(flatRange);
     if (Arrays.binarySearch(flatRange, note.charAt(0)) >= 0) return note.concat("@");
   }
   if (key > 0) {
     char[] sharpRange = Arrays.copyOfRange(circleOfFifths, 0, key);
     Arrays.sort(sharpRange);
     if (Arrays.binarySearch(sharpRange, note.charAt(0)) >= 0) return note.concat("#");
   }
   return note;
 }
Example #29
0
 @Override
 public int indexOf(Object o) {
   if (withDummy) {
     if (o == null) return -1;
     int val;
     if (o instanceof String) val = parse((String) o);
     else val = (Integer) o;
     return Arrays.binarySearch(_elements, 1, _elements.length, val);
   } else {
     int val;
     if (o instanceof String) val = parse((String) o);
     else val = (Integer) o;
     return Arrays.binarySearch(_elements, val);
   }
 }
Example #30
0
    @Override
    public SeekStatus seekCeil(BytesRef target) throws IOException {

      // already here
      if (term != null && term.equals(target)) {
        return SeekStatus.FOUND;
      }

      int startIdx = Arrays.binarySearch(indexedTermsArray, target);

      if (startIdx >= 0) {
        // we hit the term exactly... lucky us!
        TermsEnum.SeekStatus seekStatus = termsEnum.seekCeil(target);
        assert seekStatus == TermsEnum.SeekStatus.FOUND;
        ord = startIdx << indexIntervalBits;
        setTerm();
        assert term != null;
        return SeekStatus.FOUND;
      }

      // we didn't hit the term exactly
      startIdx = -startIdx - 1;

      if (startIdx == 0) {
        // our target occurs *before* the first term
        TermsEnum.SeekStatus seekStatus = termsEnum.seekCeil(target);
        assert seekStatus == TermsEnum.SeekStatus.NOT_FOUND;
        ord = 0;
        setTerm();
        assert term != null;
        return SeekStatus.NOT_FOUND;
      }

      // back up to the start of the block
      startIdx--;

      if ((ord >> indexIntervalBits) == startIdx && term != null && term.compareTo(target) <= 0) {
        // we are already in the right block and the current term is before the term we want,
        // so we don't need to seek.
      } else {
        // seek to the right block
        TermsEnum.SeekStatus seekStatus = termsEnum.seekCeil(indexedTermsArray[startIdx]);
        assert seekStatus == TermsEnum.SeekStatus.FOUND;
        ord = startIdx << indexIntervalBits;
        setTerm();
        assert term != null; // should be non-null since it's in the index
      }

      while (term != null && term.compareTo(target) < 0) {
        next();
      }

      if (term == null) {
        return SeekStatus.END;
      } else if (term.compareTo(target) == 0) {
        return SeekStatus.FOUND;
      } else {
        return SeekStatus.NOT_FOUND;
      }
    }