cdm/src/main/java/ucar/nc2/Group.java
public boolean addDimensionIfNotExists(Dimension dim) {
    if (immutable) throw new IllegalStateException("Cant modify");

    if (!dim.isShared()) {
      throw new IllegalArgumentException("Dimensions added to a group must be shared.");
    }

    if (findDimensionLocal(dim.getShortName()) != null)
      return false;

    dimensions.add(dim);
    dim.setGroup(this);
    return true;
  }
public boolean addDimensionIfNotExists(Dimension dim) {
    if (immutable) throw new IllegalStateException("Cant modify");

    if (!dim.isShared()) {
      throw new IllegalArgumentException("Dimensions added to a group must be shared.");
    }

    if (findDimensionLocal(dim.getShortName()) != null)
      return false;

    dimensions.add(dim);
    dim.setGroup(this);
    return true;
  }
Adds the specified shared dimension to this group, but only if another dimension with the same name doesn't
already exist.

@param dim  the dimension to add.
@return {@code true} if {@code dim} was successfully added to the group. Otherwise, {@code false} will be returned,
meaning that a dimension with {@code dim}'s name already exists within the group.
@throws IllegalStateException  if this dimension is {@link #setImmutable() immutable}.
@throws IllegalArgumentException  if {@code dim} isn't shared.