Skip to content

Commit

Permalink
Avoid exposing some types outside the scope in which those types are …
Browse files Browse the repository at this point in the history
…visible.

Java doesn't mind this, but it's not like it's accomplishing anything for us.

I've tried to make things `private` where possible and fallen back to making types package-private where necessary.

(In `Synchronized`, I made everything package-private for consistency, rather than trying to trace through the class hierarchies to expose only the types that need it.)

I also sprinkled in some `final` keywords while I was in the area.

RELNOTES=n/a
PiperOrigin-RevId: 573211489
  • Loading branch information
cpovirk authored and Google Java Core Libraries committed Oct 13, 2023
1 parent b4812fd commit d65edb4
Show file tree
Hide file tree
Showing 19 changed files with 76 additions and 78 deletions.
2 changes: 1 addition & 1 deletion android/guava/src/com/google/common/base/MoreObjects.java
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ private ToStringHelper addUnconditionalHolder(String name, Object value) {
}

// Holder object for values that might be null and/or empty.
private static class ValueHolder {
static class ValueHolder {
@CheckForNull String name;
@CheckForNull Object value;
@CheckForNull ValueHolder next;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1050,7 +1050,7 @@ public SortedSet<K> tailSet(@ParametricNullness K fromElement) {
}

@WeakOuter
class NavigableKeySet extends SortedKeySet implements NavigableSet<K> {
private final class NavigableKeySet extends SortedKeySet implements NavigableSet<K> {
NavigableKeySet(NavigableMap<K, Collection<V>> subMap) {
super(subMap);
}
Expand Down Expand Up @@ -1507,7 +1507,7 @@ SortedSet<K> createKeySet() {
}
}

class NavigableAsMap extends SortedAsMap implements NavigableMap<K, Collection<V>> {
private final class NavigableAsMap extends SortedAsMap implements NavigableMap<K, Collection<V>> {

NavigableAsMap(NavigableMap<K, Collection<V>> submap) {
super(submap);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,11 @@ static final class ValueEntry<K extends @Nullable Object, V extends @Nullable Ob
* frameworks like Android that define post-construct hooks like Activity.onCreate, etc.
*/

@CheckForNull ValueSetLink<K, V> predecessorInValueSet;
@CheckForNull ValueSetLink<K, V> successorInValueSet;
@CheckForNull private ValueSetLink<K, V> predecessorInValueSet;
@CheckForNull private ValueSetLink<K, V> successorInValueSet;

@CheckForNull ValueEntry<K, V> predecessorInMultimap;
@CheckForNull ValueEntry<K, V> successorInMultimap;
@CheckForNull private ValueEntry<K, V> predecessorInMultimap;
@CheckForNull private ValueEntry<K, V> successorInMultimap;

ValueEntry(
@ParametricNullness K key,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public class LinkedListMultimap<K extends @Nullable Object, V extends @Nullable
* ValueForKeyIterator} in constant time.
*/

private static final class Node<K extends @Nullable Object, V extends @Nullable Object>
static final class Node<K extends @Nullable Object, V extends @Nullable Object>
extends AbstractMapEntry<K, V> {
@ParametricNullness final K key;
@ParametricNullness V value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ boolean isIntact() {
* sake they are stored interleaved on alternate heap levels in the same array (MMPQ.queue).
*/
@WeakOuter
private class Heap {
class Heap {
final Ordering<E> ordering;

@SuppressWarnings("nullness:initialization.field.uninitialized")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -821,7 +821,7 @@ protected Set<Entry<R, Map<C, V>>> createEntrySet() {
}

@WeakOuter
class EntrySet extends TableSet<Entry<R, Map<C, V>>> {
private final class EntrySet extends TableSet<Entry<R, Map<C, V>>> {
@Override
public Iterator<Entry<R, Map<C, V>>> iterator() {
return Maps.asMapEntryIterator(
Expand Down Expand Up @@ -910,7 +910,7 @@ Collection<Map<R, V>> createValues() {
}

@WeakOuter
class ColumnMapEntrySet extends TableSet<Entry<C, Map<R, V>>> {
private final class ColumnMapEntrySet extends TableSet<Entry<C, Map<R, V>>> {
@Override
public Iterator<Entry<C, Map<R, V>>> iterator() {
return Maps.asMapEntryIterator(
Expand Down
47 changes: 23 additions & 24 deletions android/guava/src/com/google/common/collect/Synchronized.java
Original file line number Diff line number Diff line change
Expand Up @@ -326,8 +326,8 @@ public E last() {
: new SynchronizedList<E>(list, mutex);
}

private static class SynchronizedList<E extends @Nullable Object>
extends SynchronizedCollection<E> implements List<E> {
static class SynchronizedList<E extends @Nullable Object> extends SynchronizedCollection<E>
implements List<E> {
SynchronizedList(List<E> delegate, @CheckForNull Object mutex) {
super(delegate, mutex);
}
Expand Down Expand Up @@ -423,7 +423,7 @@ public int hashCode() {
private static final long serialVersionUID = 0;
}

private static class SynchronizedRandomAccessList<E extends @Nullable Object>
static final class SynchronizedRandomAccessList<E extends @Nullable Object>
extends SynchronizedList<E> implements RandomAccess {
SynchronizedRandomAccessList(List<E> list, @CheckForNull Object mutex) {
super(list, mutex);
Expand All @@ -440,7 +440,7 @@ private static class SynchronizedRandomAccessList<E extends @Nullable Object>
return new SynchronizedMultiset<E>(multiset, mutex);
}

private static class SynchronizedMultiset<E extends @Nullable Object>
static final class SynchronizedMultiset<E extends @Nullable Object>
extends SynchronizedCollection<E> implements Multiset<E> {
@CheckForNull transient Set<E> elementSet;
@CheckForNull transient Set<Multiset.Entry<E>> entrySet;
Expand Down Expand Up @@ -537,7 +537,7 @@ public int hashCode() {
return new SynchronizedMultimap<>(multimap, mutex);
}

private static class SynchronizedMultimap<K extends @Nullable Object, V extends @Nullable Object>
static class SynchronizedMultimap<K extends @Nullable Object, V extends @Nullable Object>
extends SynchronizedObject implements Multimap<K, V> {
@CheckForNull transient Set<K> keySet;
@CheckForNull transient Collection<V> valuesCollection;
Expand Down Expand Up @@ -724,7 +724,7 @@ public int hashCode() {
return new SynchronizedListMultimap<>(multimap, mutex);
}

private static class SynchronizedListMultimap<
static final class SynchronizedListMultimap<
K extends @Nullable Object, V extends @Nullable Object>
extends SynchronizedMultimap<K, V> implements ListMultimap<K, V> {
SynchronizedListMultimap(ListMultimap<K, V> delegate, @CheckForNull Object mutex) {
Expand Down Expand Up @@ -768,8 +768,7 @@ public List<V> replaceValues(K key, Iterable<? extends V> values) {
return new SynchronizedSetMultimap<>(multimap, mutex);
}

private static class SynchronizedSetMultimap<
K extends @Nullable Object, V extends @Nullable Object>
static class SynchronizedSetMultimap<K extends @Nullable Object, V extends @Nullable Object>
extends SynchronizedMultimap<K, V> implements SetMultimap<K, V> {
@CheckForNull transient Set<Map.Entry<K, V>> entrySet;

Expand Down Expand Up @@ -825,7 +824,7 @@ SortedSetMultimap<K, V> sortedSetMultimap(
return new SynchronizedSortedSetMultimap<>(multimap, mutex);
}

private static class SynchronizedSortedSetMultimap<
static final class SynchronizedSortedSetMultimap<
K extends @Nullable Object, V extends @Nullable Object>
extends SynchronizedSetMultimap<K, V> implements SortedSetMultimap<K, V> {
SynchronizedSortedSetMultimap(SortedSetMultimap<K, V> delegate, @CheckForNull Object mutex) {
Expand Down Expand Up @@ -892,7 +891,7 @@ public Comparator<? super V> valueComparator() {
}
}

private static class SynchronizedAsMapEntries<
static final class SynchronizedAsMapEntries<
K extends @Nullable Object, V extends @Nullable Object>
extends SynchronizedSet<Map.Entry<K, Collection<V>>> {
SynchronizedAsMapEntries(
Expand Down Expand Up @@ -999,7 +998,7 @@ public boolean retainAll(Collection<?> c) {
return new SynchronizedMap<>(map, mutex);
}

private static class SynchronizedMap<K extends @Nullable Object, V extends @Nullable Object>
static class SynchronizedMap<K extends @Nullable Object, V extends @Nullable Object>
extends SynchronizedObject implements Map<K, V> {
@CheckForNull transient Set<K> keySet;
@CheckForNull transient Collection<V> values;
Expand Down Expand Up @@ -1202,8 +1201,7 @@ public SortedMap<K, V> tailMap(K fromKey) {
return new SynchronizedBiMap<>(bimap, mutex, null);
}

@VisibleForTesting
static class SynchronizedBiMap<K extends @Nullable Object, V extends @Nullable Object>
static final class SynchronizedBiMap<K extends @Nullable Object, V extends @Nullable Object>
extends SynchronizedMap<K, V> implements BiMap<K, V>, Serializable {
@CheckForNull private transient Set<V> valueSet;
@RetainedWith @CheckForNull private transient BiMap<V, K> inverse;
Expand Down Expand Up @@ -1250,7 +1248,7 @@ public BiMap<V, K> inverse() {
private static final long serialVersionUID = 0;
}

private static class SynchronizedAsMap<K extends @Nullable Object, V extends @Nullable Object>
static final class SynchronizedAsMap<K extends @Nullable Object, V extends @Nullable Object>
extends SynchronizedMap<K, Collection<V>> {
@CheckForNull transient Set<Map.Entry<K, Collection<V>>> asMapEntrySet;
@CheckForNull transient Collection<Collection<V>> asMapValues;
Expand Down Expand Up @@ -1297,7 +1295,7 @@ public boolean containsValue(@CheckForNull Object o) {
private static final long serialVersionUID = 0;
}

private static class SynchronizedAsMapValues<V extends @Nullable Object>
static final class SynchronizedAsMapValues<V extends @Nullable Object>
extends SynchronizedCollection<Collection<V>> {
SynchronizedAsMapValues(Collection<Collection<V>> delegate, @CheckForNull Object mutex) {
super(delegate, mutex);
Expand All @@ -1319,8 +1317,8 @@ Collection<V> transform(Collection<V> from) {

@GwtIncompatible // NavigableSet
@VisibleForTesting
static class SynchronizedNavigableSet<E extends @Nullable Object> extends SynchronizedSortedSet<E>
implements NavigableSet<E> {
static final class SynchronizedNavigableSet<E extends @Nullable Object>
extends SynchronizedSortedSet<E> implements NavigableSet<E> {
SynchronizedNavigableSet(NavigableSet<E> delegate, @CheckForNull Object mutex) {
super(delegate, mutex);
}
Expand Down Expand Up @@ -1463,7 +1461,8 @@ public SortedSet<E> tailSet(E fromElement) {

@GwtIncompatible // NavigableMap
@VisibleForTesting
static class SynchronizedNavigableMap<K extends @Nullable Object, V extends @Nullable Object>
static final class SynchronizedNavigableMap<
K extends @Nullable Object, V extends @Nullable Object>
extends SynchronizedSortedMap<K, V> implements NavigableMap<K, V> {

SynchronizedNavigableMap(NavigableMap<K, V> delegate, @CheckForNull Object mutex) {
Expand Down Expand Up @@ -1664,7 +1663,7 @@ Map.Entry<K, V> nullableSynchronizedEntry(
}

@GwtIncompatible // works but is needed only for NavigableMap
private static class SynchronizedEntry<K extends @Nullable Object, V extends @Nullable Object>
static final class SynchronizedEntry<K extends @Nullable Object, V extends @Nullable Object>
extends SynchronizedObject implements Map.Entry<K, V> {

SynchronizedEntry(Map.Entry<K, V> delegate, @CheckForNull Object mutex) {
Expand Down Expand Up @@ -1719,8 +1718,8 @@ public V setValue(V value) {
return (queue instanceof SynchronizedQueue) ? queue : new SynchronizedQueue<E>(queue, mutex);
}

private static class SynchronizedQueue<E extends @Nullable Object>
extends SynchronizedCollection<E> implements Queue<E> {
static class SynchronizedQueue<E extends @Nullable Object> extends SynchronizedCollection<E>
implements Queue<E> {

SynchronizedQueue(Queue<E> delegate, @CheckForNull Object mutex) {
super(delegate, mutex);
Expand Down Expand Up @@ -1775,8 +1774,8 @@ public E remove() {
return new SynchronizedDeque<E>(deque, mutex);
}

private static final class SynchronizedDeque<E extends @Nullable Object>
extends SynchronizedQueue<E> implements Deque<E> {
static final class SynchronizedDeque<E extends @Nullable Object> extends SynchronizedQueue<E>
implements Deque<E> {

SynchronizedDeque(Deque<E> delegate, @CheckForNull Object mutex) {
super(delegate, mutex);
Expand Down Expand Up @@ -1918,7 +1917,7 @@ Table<R, C, V> table(Table<R, C, V> table, @CheckForNull Object mutex) {
return new SynchronizedTable<>(table, mutex);
}

private static final class SynchronizedTable<
static final class SynchronizedTable<
R extends @Nullable Object, C extends @Nullable Object, V extends @Nullable Object>
extends SynchronizedObject implements Table<R, C, V> {

Expand Down
2 changes: 1 addition & 1 deletion android/guava/src/com/google/common/collect/Tables.java
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@ RowSortedTable<R, C, V> unmodifiableRowSortedTable(
return new UnmodifiableRowSortedMap<>(table);
}

static final class UnmodifiableRowSortedMap<
private static final class UnmodifiableRowSortedMap<
R extends @Nullable Object, C extends @Nullable Object, V extends @Nullable Object>
extends UnmodifiableTable<R, C, V> implements RowSortedTable<R, C, V> {

Expand Down
2 changes: 1 addition & 1 deletion android/guava/src/com/google/common/io/BaseEncoding.java
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ public static BaseEncoding base16() {
return BASE16;
}

private static final class Alphabet {
static final class Alphabet {
private final String name;
// this is meant to be immutable -- don't modify it!
private final char[] chars;
Expand Down
2 changes: 1 addition & 1 deletion guava/src/com/google/common/base/MoreObjects.java
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ private ToStringHelper addUnconditionalHolder(String name, Object value) {
}

// Holder object for values that might be null and/or empty.
private static class ValueHolder {
static class ValueHolder {
@CheckForNull String name;
@CheckForNull Object value;
@CheckForNull ValueHolder next;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1063,7 +1063,7 @@ public SortedSet<K> tailSet(@ParametricNullness K fromElement) {
}

@WeakOuter
class NavigableKeySet extends SortedKeySet implements NavigableSet<K> {
private final class NavigableKeySet extends SortedKeySet implements NavigableSet<K> {
NavigableKeySet(NavigableMap<K, Collection<V>> subMap) {
super(subMap);
}
Expand Down Expand Up @@ -1552,7 +1552,7 @@ SortedSet<K> createKeySet() {
}
}

class NavigableAsMap extends SortedAsMap implements NavigableMap<K, Collection<V>> {
private final class NavigableAsMap extends SortedAsMap implements NavigableMap<K, Collection<V>> {

NavigableAsMap(NavigableMap<K, Collection<V>> submap) {
super(submap);
Expand Down
8 changes: 4 additions & 4 deletions guava/src/com/google/common/collect/HashBiMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public final class HashBiMap<K extends @Nullable Object, V extends @Nullable Obj
return bimap;
}

private static final class BiEntry<K extends @Nullable Object, V extends @Nullable Object>
static final class BiEntry<K extends @Nullable Object, V extends @Nullable Object>
extends ImmutableEntry<K, V> {
final int keyHash;
final int valueHash;
Expand Down Expand Up @@ -438,7 +438,7 @@ public int size() {
return size;
}

abstract class Itr<T extends @Nullable Object> implements Iterator<T> {
private abstract class Itr<T extends @Nullable Object> implements Iterator<T> {
@CheckForNull BiEntry<K, V> next = firstInKeyInsertionOrder;
@CheckForNull BiEntry<K, V> toRemove = null;
int expectedModCount = modCount;
Expand Down Expand Up @@ -531,7 +531,7 @@ Entry<K, V> output(BiEntry<K, V> entry) {
}

class MapEntry extends AbstractMapEntry<K, V> {
BiEntry<K, V> delegate;
private BiEntry<K, V> delegate;

MapEntry(BiEntry<K, V> entry) {
this.delegate = entry;
Expand Down Expand Up @@ -708,7 +708,7 @@ Entry<V, K> output(BiEntry<K, V> entry) {
}

class InverseEntry extends AbstractMapEntry<V, K> {
BiEntry<K, V> delegate;
private BiEntry<K, V> delegate;

InverseEntry(BiEntry<K, V> entry) {
this.delegate = entry;
Expand Down
8 changes: 4 additions & 4 deletions guava/src/com/google/common/collect/LinkedHashMultimap.java
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,11 @@ static final class ValueEntry<K extends @Nullable Object, V extends @Nullable Ob
* frameworks like Android that define post-construct hooks like Activity.onCreate, etc.
*/

@CheckForNull ValueSetLink<K, V> predecessorInValueSet;
@CheckForNull ValueSetLink<K, V> successorInValueSet;
@CheckForNull private ValueSetLink<K, V> predecessorInValueSet;
@CheckForNull private ValueSetLink<K, V> successorInValueSet;

@CheckForNull ValueEntry<K, V> predecessorInMultimap;
@CheckForNull ValueEntry<K, V> successorInMultimap;
@CheckForNull private ValueEntry<K, V> predecessorInMultimap;
@CheckForNull private ValueEntry<K, V> successorInMultimap;

ValueEntry(
@ParametricNullness K key,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public class LinkedListMultimap<K extends @Nullable Object, V extends @Nullable
* ValueForKeyIterator} in constant time.
*/

private static final class Node<K extends @Nullable Object, V extends @Nullable Object>
static final class Node<K extends @Nullable Object, V extends @Nullable Object>
extends AbstractMapEntry<K, V> {
@ParametricNullness final K key;
@ParametricNullness V value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ boolean isIntact() {
* sake they are stored interleaved on alternate heap levels in the same array (MMPQ.queue).
*/
@WeakOuter
private class Heap {
class Heap {
final Ordering<E> ordering;

@SuppressWarnings("nullness:initialization.field.uninitialized")
Expand Down
4 changes: 2 additions & 2 deletions guava/src/com/google/common/collect/StandardTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -846,7 +846,7 @@ protected Set<Entry<R, Map<C, V>>> createEntrySet() {
}

@WeakOuter
class EntrySet extends TableSet<Entry<R, Map<C, V>>> {
private final class EntrySet extends TableSet<Entry<R, Map<C, V>>> {
@Override
public Iterator<Entry<R, Map<C, V>>> iterator() {
return Maps.asMapEntryIterator(
Expand Down Expand Up @@ -935,7 +935,7 @@ Collection<Map<R, V>> createValues() {
}

@WeakOuter
class ColumnMapEntrySet extends TableSet<Entry<C, Map<R, V>>> {
private final class ColumnMapEntrySet extends TableSet<Entry<C, Map<R, V>>> {
@Override
public Iterator<Entry<C, Map<R, V>>> iterator() {
return Maps.asMapEntryIterator(
Expand Down
Loading

0 comments on commit d65edb4

Please sign in to comment.