mirror of https://github.com/grpc/grpc-java.git
core: Remove com.google.common.collect usages, again
Commit 656e8ce (#2208) removed most usages, but missed one and one was
re-added. Since all usages are removed, it should be much easier to
notice regressions.
This commit is contained in:
parent
1623063143
commit
bb7384639b
|
|
@ -35,7 +35,6 @@ import static com.google.common.base.Preconditions.checkArgument;
|
|||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
import java.net.SocketAddress;
|
||||
import java.util.ArrayList;
|
||||
|
|
@ -64,7 +63,8 @@ public final class ResolvedServerInfoGroup {
|
|||
private ResolvedServerInfoGroup(List<ResolvedServerInfo> resolvedServerInfoList,
|
||||
Attributes attributes) {
|
||||
checkArgument(!resolvedServerInfoList.isEmpty(), "empty server list");
|
||||
this.resolvedServerInfoList = Collections.unmodifiableList(resolvedServerInfoList);
|
||||
this.resolvedServerInfoList =
|
||||
Collections.unmodifiableList(new ArrayList<ResolvedServerInfo>(resolvedServerInfoList));
|
||||
this.attributes = checkNotNull(attributes, "attributes");
|
||||
}
|
||||
|
||||
|
|
@ -148,11 +148,10 @@ public final class ResolvedServerInfoGroup {
|
|||
}
|
||||
|
||||
public static class Builder {
|
||||
private final ImmutableList.Builder<ResolvedServerInfo> groupBuilder;
|
||||
private final List<ResolvedServerInfo> group = new ArrayList<ResolvedServerInfo>();
|
||||
private final Attributes attributes;
|
||||
|
||||
public Builder(Attributes attributes) {
|
||||
this.groupBuilder = ImmutableList.builder();
|
||||
this.attributes = attributes;
|
||||
}
|
||||
|
||||
|
|
@ -161,17 +160,17 @@ public final class ResolvedServerInfoGroup {
|
|||
}
|
||||
|
||||
public Builder add(ResolvedServerInfo resolvedServerInfo) {
|
||||
groupBuilder.add(resolvedServerInfo);
|
||||
group.add(resolvedServerInfo);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder addAll(Collection<ResolvedServerInfo> resolvedServerInfo) {
|
||||
groupBuilder.addAll(resolvedServerInfo);
|
||||
group.addAll(resolvedServerInfo);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ResolvedServerInfoGroup build() {
|
||||
return new ResolvedServerInfoGroup(groupBuilder.build(), attributes);
|
||||
return new ResolvedServerInfoGroup(group, attributes);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,7 +32,6 @@
|
|||
package io.grpc.internal;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.collect.Iterators;
|
||||
|
||||
import io.grpc.EquivalentAddressGroup;
|
||||
import io.grpc.Status;
|
||||
|
|
@ -44,6 +43,7 @@ import java.util.Collection;
|
|||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.annotation.concurrent.NotThreadSafe;
|
||||
|
|
@ -62,7 +62,7 @@ public class RoundRobinServerList<T> {
|
|||
private RoundRobinServerList(TransportManager<T> tm, List<EquivalentAddressGroup> list) {
|
||||
this.tm = tm;
|
||||
this.list = list;
|
||||
this.cyclingIter = Iterators.cycle(list);
|
||||
this.cyclingIter = new CycleIterator<EquivalentAddressGroup>(list);
|
||||
this.requestDroppingTransport =
|
||||
tm.createFailingTransport(Status.UNAVAILABLE.withDescription("Throttled by LB"));
|
||||
}
|
||||
|
|
@ -136,4 +136,36 @@ public class RoundRobinServerList<T> {
|
|||
Collections.unmodifiableList(new ArrayList<EquivalentAddressGroup>(list)));
|
||||
}
|
||||
}
|
||||
|
||||
private static final class CycleIterator<T> implements Iterator<T> {
|
||||
private final List<T> list;
|
||||
private int index;
|
||||
|
||||
public CycleIterator(List<T> list) {
|
||||
this.list = list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return !list.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public T next() {
|
||||
if (!hasNext()) {
|
||||
throw new NoSuchElementException();
|
||||
}
|
||||
T val = list.get(index);
|
||||
index++;
|
||||
if (index >= list.size()) {
|
||||
index -= list.size();
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue