code: private void put(DirectoryEntry entry, boolean overwriteExisting) {
      int index = bucketIndex(entry.name(), table.length);
  
      // find the place the new entry should go, ensuring an entry with the same name doesn't already
      // exist along the way
      DirectoryEntry prev = null;
      DirectoryEntry curr = table[index];
      while (curr != null) {
        if (curr.name().equals(entry.name())) {
          if (overwriteExisting) {
            // just replace the existing entry; no need to expand, and entryCount doesn't change
            if (prev != null) {
              prev.next = entry;
            } else {
              table[index] = entry;
            }
            entry.next = curr.next;
            curr.next = null;
            entry.file().incrementLinkCount();
            return;
          } else {
            throw new IllegalArgumentException("entry '" + entry.name() + "' already exists");
          }
        }
  
        prev = curr;
        curr = curr.next;
      }
  
      entryCount++;
      if (expandIfNeeded()) {
        // if the table was expanded, the index/entry we found is no longer applicable, so just add
        // the entry normally
        index = bucketIndex(entry.name(), table.length);
        addToBucket(index, table, entry);
      } else {
        // otherwise, we just can use the index/entry we found
        if (prev != null) {
          prev.next = entry;
        } else {
          table[index] = entry;
        }
      }
  
      entry.file().incrementLinkCount();
    }
docs: Adds the given entry to the directory. {@code overwriteExisting} determines whether an existing
  entry with the same name should be overwritten or an exception should be thrown.