class DefaultAcl {

  public boolean applyToIfEnabled(Item item) {
    if (!aclMode.isEnabled()) { // do nothing if default ACL not being used
      return false;
    }
    checkNotNull(item, "Item cannot be null.");

    if (isAclEmpty(item)) {
      // In every mode use case, if the item has no ACL information (aside from an owner), just set
      // the ACL as defined in DefaultAcl
      applyDefaultAcl(item);
      return true;
    } else {
      switch (aclMode) {
        case FALLBACK: // only set if no current ACL being used
          return false;

        case APPEND: // add to existing ACL
          List<Principal> appendedReaders = getCopyOrEmptyList(item.getAcl().getReaders());
          appendedReaders.addAll(commonAcl.getReaders());
          List<Principal> appendedDeniedReaders =
              getCopyOrEmptyList(item.getAcl().getDeniedReaders());
          appendedDeniedReaders.addAll(commonAcl.getDeniedReaders());
          Acl.Builder appendedAcl =
              new Acl.Builder()
                  .setReaders(appendedReaders)
                  .setDeniedReaders(appendedDeniedReaders)
                  .setInheritFrom(item.getAcl().getInheritAclFrom())
                  .setOwners(getCopyOrEmptyList(item.getAcl().getOwners()));
          if (!Strings.isNullOrEmpty(item.getAcl().getAclInheritanceType())) {
            appendedAcl.setInheritanceType(
                InheritanceType.valueOf(item.getAcl().getAclInheritanceType()));
          }
          appendedAcl.build().applyTo(item);
          return true;

        case OVERRIDE: // replace existing ACL
          applyDefaultAcl(item);
          return true;

        default: // should never get this far
          throw new IllegalStateException(
              "Attempting to apply a default ACL with mode: " + aclMode.toString());
      }
    }
  }

  private  DefaultAcl(Builder builder);

}