/**
  * Continues the search, given the initial state described by the lastResult. Package protected.
  */
 SearchResult continueSearch(SearchResult lastResult) {
   byte[] bytes = lastResult.bytes;
   State state = lastResult.lastMatchedState;
   for (int i = lastResult.lastIndex; i < bytes.length; i++) {
     byte b = bytes[i];
     while (state.get(b) == null) state = state.getFail();
     state = state.get(b);
     if (state.getOutputs().size() > 0) return new SearchResult(state, bytes, i + 1);
   }
   return null;
 }
Exemple #2
0
 public void paint(Graphics g) {
   g.setColor(Color.gray);
   g.fillRect(0, 0, w, h);
   g.setColor(Color.black);
   g.drawRect(0, 0, w, h);
   g.setColor(Color.blue);
   g.fillRect(0, h, w, h);
   g.setColor(Color.black);
   g.drawRect(0, h, w, h);
   g.drawString("resting", 10, 20);
   g.drawString("waits to swim", 10, h - 20);
   g.drawString("waits to exit", 10, (3 * h) / 2 - 20);
   g.drawString("swimming", 10, 2 * h - 20);
   if (e == null) return;
   for (int i = 0; i < e.e.length; i++) {
     switch (e.get(i)) {
       case 0:
         rect(g, (i < e.K ? Color.red : Color.green), i, 0);
         break;
       case 1:
         rect(g, (i < e.K ? Color.red : Color.green), i, 1);
         break;
       case 2:
         rect(g, (i < e.K ? Color.red : Color.green), i, 3);
         break;
       case 3:
         rect(g, (i < e.K ? Color.red : Color.green), i, 2);
         break;
       default:
     }
   }
 }
  // Returns the root type from the globals.
  private ObjectType getRootType() {
    State globals = getGlobals();

    if (globals != null) {
      Object rootType = globals.get(ROOT_TYPE_FIELD);

      if (rootType == null) {
        rootType = globals.get("rootRecordType");
      }

      if (rootType instanceof ObjectType) {
        return (ObjectType) rootType;
      }
    }

    return null;
  }
        @Override
        @SuppressWarnings("unchecked")
        protected Map<String, ObjectIndex> create() {
          State globals = getGlobals();
          Object definitions = globals != null ? globals.get(GLOBAL_INDEXES_FIELD) : null;

          return ObjectIndex.Static.convertDefinitionsToInstances(
              DatabaseEnvironment.this,
              definitions instanceof List ? (List<Map<String, Object>>) definitions : null);
        }
 /**
  * DANGER DANGER: dense algorithm code ahead. Very order dependent. Initializes the fail
  * transitions of all states except for the root.
  */
 private void prepareFailTransitions() {
   Queue q = new Queue();
   for (int i = 0; i < 256; i++)
     if (this.root.get((byte) i) != null) {
       this.root.get((byte) i).setFail(this.root);
       q.add(this.root.get((byte) i));
     }
   this.prepareRoot();
   while (!q.isEmpty()) {
     State state = q.pop();
     byte[] keys = state.keys();
     for (int i = 0; i < keys.length; i++) {
       State r = state;
       byte a = keys[i];
       State s = r.get(a);
       q.add(s);
       r = r.getFail();
       while (r.get(a) == null) r = r.getFail();
       s.setFail(r.get(a));
       s.getOutputs().addAll(r.get(a).getOutputs());
     }
   }
 }