Skip to content

Commit

Permalink
Standardize parameter names across Immutable*.of(...) methods.
Browse files Browse the repository at this point in the history
This increases the chances that they will be sorted from fewest args to most args.

It also matches what we already do for the `of` methods of key-value collections like `ImmutableMap`.

RELNOTES=n/a
PiperOrigin-RevId: 631629370
  • Loading branch information
cpovirk authored and Google Java Core Libraries committed May 8, 2024
1 parent 1b3969e commit b9b6084
Show file tree
Hide file tree
Showing 13 changed files with 36 additions and 36 deletions.
Expand Up @@ -95,10 +95,10 @@ public static <E> ImmutableList<E> of() {
* comparably to {@link Collections#singletonList}, but will not accept a null element. It is
* preferable mainly for consistency and maintainability of your code.
*
* @throws NullPointerException if {@code element} is null
* @throws NullPointerException if the element is null
*/
public static <E> ImmutableList<E> of(E element) {
return construct(element);
public static <E> ImmutableList<E> of(E e1) {
return construct(e1);
}

/**
Expand Down
Expand Up @@ -109,11 +109,11 @@ public static <E> ImmutableMultiset<E> of() {
/**
* Returns an immutable multiset containing a single element.
*
* @throws NullPointerException if {@code element} is null
* @throws NullPointerException if the element is null
* @since 6.0 (source-compatible since 2.0)
*/
public static <E> ImmutableMultiset<E> of(E element) {
return copyFromElements(element);
public static <E> ImmutableMultiset<E> of(E e1) {
return copyFromElements(e1);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions android/guava/src/com/google/common/collect/ImmutableSet.java
Expand Up @@ -81,12 +81,12 @@ public static <E> ImmutableSet<E> of() {
}

/**
* Returns an immutable set containing {@code element}. Preferred over {@link
* Returns an immutable set containing the given element. Preferred over {@link
* Collections#singleton} for code consistency, {@code null} rejection, and because the return
* type conveys the immutability guarantee.
*/
public static <E> ImmutableSet<E> of(E element) {
return new SingletonImmutableSet<>(element);
public static <E> ImmutableSet<E> of(E e1) {
return new SingletonImmutableSet<>(e1);
}

/**
Expand Down
Expand Up @@ -140,9 +140,9 @@ public static <E> ImmutableSortedMultiset<E> of() {
}

/** Returns an immutable sorted multiset containing a single element. */
public static <E extends Comparable<? super E>> ImmutableSortedMultiset<E> of(E element) {
public static <E extends Comparable<? super E>> ImmutableSortedMultiset<E> of(E e1) {
RegularImmutableSortedSet<E> elementSet =
(RegularImmutableSortedSet<E>) ImmutableSortedSet.of(element);
(RegularImmutableSortedSet<E>) ImmutableSortedSet.of(e1);
long[] cumulativeCounts = {0, 1};
return new RegularImmutableSortedMultiset<>(elementSet, cumulativeCounts, 0, 1);
}
Expand Down Expand Up @@ -817,7 +817,7 @@ public static <E> ImmutableSortedMultiset.Builder<E> builder() {
*/
@DoNotCall("Elements must be Comparable. (Or, pass a Comparator to orderedBy or copyOf.)")
@Deprecated
public static <E> ImmutableSortedMultiset<E> of(E element) {
public static <E> ImmutableSortedMultiset<E> of(E e1) {
throw new UnsupportedOperationException();
}

Expand Down
Expand Up @@ -103,8 +103,8 @@ public static <E> ImmutableSortedSet<E> of() {
}

/** Returns an immutable sorted set containing a single element. */
public static <E extends Comparable<? super E>> ImmutableSortedSet<E> of(E element) {
return new RegularImmutableSortedSet<>(ImmutableList.of(element), Ordering.natural());
public static <E extends Comparable<? super E>> ImmutableSortedSet<E> of(E e1) {
return new RegularImmutableSortedSet<>(ImmutableList.of(e1), Ordering.natural());
}

/**
Expand Down Expand Up @@ -845,7 +845,7 @@ public static <E> ImmutableSortedSet.Builder<E> builderWithExpectedSize(int expe
*/
@DoNotCall("Pass a parameter of type Comparable")
@Deprecated
public static <E> ImmutableSortedSet<E> of(E element) {
public static <E> ImmutableSortedSet<E> of(E e1) {
throw new UnsupportedOperationException();
}

Expand Down
Expand Up @@ -54,8 +54,8 @@ public static <E> ImmutableList<E> of() {
return (ImmutableList<E>) RegularImmutableList.EMPTY;
}

public static <E> ImmutableList<E> of(E element) {
return new SingletonImmutableList<E>(checkNotNull(element));
public static <E> ImmutableList<E> of(E e1) {
return new SingletonImmutableList<E>(checkNotNull(e1));
}

public static <E> ImmutableList<E> of(E e1, E e2) {
Expand Down
Expand Up @@ -55,8 +55,8 @@ public static <E> ImmutableSet<E> of() {
return (ImmutableSet<E>) RegularImmutableSet.EMPTY;
}

public static <E> ImmutableSet<E> of(E element) {
return new SingletonImmutableSet<E>(element);
public static <E> ImmutableSet<E> of(E e1) {
return new SingletonImmutableSet<E>(e1);
}

@SuppressWarnings("unchecked")
Expand Down
Expand Up @@ -79,8 +79,8 @@ public static <E> ImmutableSortedSet<E> of() {
return (ImmutableSortedSet<E>) NATURAL_EMPTY_SET;
}

public static <E extends Comparable<? super E>> ImmutableSortedSet<E> of(E element) {
return ofInternal(Ordering.natural(), element);
public static <E extends Comparable<? super E>> ImmutableSortedSet<E> of(E e1) {
return ofInternal(Ordering.natural(), e1);
}

@SuppressWarnings("unchecked")
Expand Down
6 changes: 3 additions & 3 deletions guava/src/com/google/common/collect/ImmutableList.java
Expand Up @@ -95,10 +95,10 @@ public static <E> ImmutableList<E> of() {
* comparably to {@link Collections#singletonList}, but will not accept a null element. It is
* preferable mainly for consistency and maintainability of your code.
*
* @throws NullPointerException if {@code element} is null
* @throws NullPointerException if the element is null
*/
public static <E> ImmutableList<E> of(E element) {
return new SingletonImmutableList<>(element);
public static <E> ImmutableList<E> of(E e1) {
return new SingletonImmutableList<>(e1);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions guava/src/com/google/common/collect/ImmutableMultiset.java
Expand Up @@ -104,11 +104,11 @@ public static <E> ImmutableMultiset<E> of() {
/**
* Returns an immutable multiset containing a single element.
*
* @throws NullPointerException if {@code element} is null
* @throws NullPointerException if the element is null
* @since 6.0 (source-compatible since 2.0)
*/
public static <E> ImmutableMultiset<E> of(E element) {
return copyFromElements(element);
public static <E> ImmutableMultiset<E> of(E e1) {
return copyFromElements(e1);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions guava/src/com/google/common/collect/ImmutableSet.java
Expand Up @@ -84,12 +84,12 @@ public static <E> ImmutableSet<E> of() {
}

/**
* Returns an immutable set containing {@code element}. Preferred over {@link
* Returns an immutable set containing the given element. Preferred over {@link
* Collections#singleton} for code consistency, {@code null} rejection, and because the return
* type conveys the immutability guarantee.
*/
public static <E> ImmutableSet<E> of(E element) {
return new SingletonImmutableSet<>(element);
public static <E> ImmutableSet<E> of(E e1) {
return new SingletonImmutableSet<>(e1);
}

/*
Expand Down
Expand Up @@ -114,9 +114,9 @@ public static <E> ImmutableSortedMultiset<E> of() {
}

/** Returns an immutable sorted multiset containing a single element. */
public static <E extends Comparable<? super E>> ImmutableSortedMultiset<E> of(E element) {
public static <E extends Comparable<? super E>> ImmutableSortedMultiset<E> of(E e1) {
RegularImmutableSortedSet<E> elementSet =
(RegularImmutableSortedSet<E>) ImmutableSortedSet.of(element);
(RegularImmutableSortedSet<E>) ImmutableSortedSet.of(e1);
long[] cumulativeCounts = {0, 1};
return new RegularImmutableSortedMultiset<>(elementSet, cumulativeCounts, 0, 1);
}
Expand Down Expand Up @@ -665,7 +665,7 @@ public static <E> ImmutableSortedMultiset.Builder<E> builder() {
*/
@DoNotCall("Elements must be Comparable. (Or, pass a Comparator to orderedBy or copyOf.)")
@Deprecated
public static <E> ImmutableSortedMultiset<E> of(E element) {
public static <E> ImmutableSortedMultiset<E> of(E e1) {
throw new UnsupportedOperationException();
}

Expand Down
6 changes: 3 additions & 3 deletions guava/src/com/google/common/collect/ImmutableSortedSet.java
Expand Up @@ -105,8 +105,8 @@ public static <E> ImmutableSortedSet<E> of() {
}

/** Returns an immutable sorted set containing a single element. */
public static <E extends Comparable<? super E>> ImmutableSortedSet<E> of(E element) {
return new RegularImmutableSortedSet<>(ImmutableList.of(element), Ordering.natural());
public static <E extends Comparable<? super E>> ImmutableSortedSet<E> of(E e1) {
return new RegularImmutableSortedSet<>(ImmutableList.of(e1), Ordering.natural());
}

/**
Expand Down Expand Up @@ -914,7 +914,7 @@ public static <E> ImmutableSortedSet.Builder<E> builderWithExpectedSize(int expe
*/
@DoNotCall("Pass a parameter of type Comparable")
@Deprecated
public static <E> ImmutableSortedSet<E> of(E element) {
public static <E> ImmutableSortedSet<E> of(E e1) {
throw new UnsupportedOperationException();
}

Expand Down

0 comments on commit b9b6084

Please sign in to comment.