Esempio n. 1
0
  /**
   * Insert a newly created item into this folder. Observe we assume <code>entry.id().parent() == id
   * </code>.
   *
   * @param item
   */
  protected void insert(Path.Item item) throws IOException {
    if (item.id().parent() != id) {
      throw new IllegalArgumentException(
          "Cannot insert with incorrect Path.Item ("
              + item.id()
              + ") into AbstractFolder ("
              + id
              + ")");
    }
    updateContents();

    Path.ID id = item.id();
    int index = binarySearch(contents, nentries, id);

    if (index < 0) {
      index = -index - 1; // calculate insertion point
    } else {
      // indicates already an entry with a different content type
    }

    if ((nentries + 1) < contents.length) {
      System.arraycopy(contents, index, contents, index + 1, nentries - index);
    } else {
      Path.Item[] tmp = new Path.Item[(nentries + 1) * 2];
      System.arraycopy(contents, 0, tmp, 0, index);
      System.arraycopy(contents, index, tmp, index + 1, nentries - index);
      contents = tmp;
    }

    contents[index] = item;
    nentries++;
  }
Esempio n. 2
0
  @Override
  public <T> void getAll(Content.Filter<T> filter, Set<Path.ID> entries) throws IOException {
    updateContents();

    // It would be nice to further optimise this loop. The key issue is that,
    // at some point, we might know the filter could never match. In which
    // case, we want to stop the recursion early, rather than exploring a
    // potentially largel subtree.

    for (int i = 0; i != nentries; ++i) {
      Path.Item item = contents[i];
      if (item instanceof Entry) {
        Entry entry = (Entry) item;
        if (filter.matches(entry.id(), entry.contentType())) {
          entries.add(entry.id());
        }
      } else if (item instanceof Path.Folder && filter.matchesSubpath(item.id())) {
        Path.Folder folder = (Path.Folder) item;
        folder.getAll(filter, entries);
      }
    }
  }
Esempio n. 3
0
 public int compare(Path.Item e1, Path.Item e2) {
   return e1.id().compareTo(e2.id());
 }