cassandra-pr mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aweisberg <...@git.apache.org>
Subject [GitHub] cassandra pull request #224: 14405 replicas
Date Wed, 16 May 2018 17:06:10 GMT
Github user aweisberg commented on a diff in the pull request:

    https://github.com/apache/cassandra/pull/224#discussion_r188119369
  
    --- Diff: src/java/org/apache/cassandra/locator/ReplicaList.java ---
    @@ -0,0 +1,244 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you under the Apache License, Version 2.0 (the
    + * "License"); you may not use this file except in compliance
    + * with the License.  You may obtain a copy of the License at
    + *
    + *     http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +
    +package org.apache.cassandra.locator;
    +
    +import java.util.ArrayList;
    +import java.util.Collection;
    +import java.util.Comparator;
    +import java.util.Iterator;
    +import java.util.List;
    +import java.util.Objects;
    +import java.util.function.Predicate;
    +
    +import com.google.common.collect.ImmutableList;
    +import com.google.common.collect.Iterables;
    +
    +public class ReplicaList extends Replicas
    +{
    +    static final ReplicaList EMPTY = new ReplicaList(ImmutableList.of());
    +
    +    private final List<Replica> replicaList;
    +
    +    public ReplicaList()
    +    {
    +        replicaList = new ArrayList<>();
    +    }
    +
    +    public ReplicaList(int capacity)
    +    {
    +        replicaList = new ArrayList<>(capacity);
    +    }
    +
    +    public ReplicaList(ReplicaList from)
    +    {
    +        replicaList = new ArrayList<>(from.replicaList);
    +    }
    +
    +    public ReplicaList(Replicas from)
    +    {
    +        replicaList = new ArrayList<>(from.size());
    +        addAll(from);
    +    }
    +
    +    public ReplicaList(Collection<Replica> from)
    +    {
    +        replicaList = new ArrayList<>(from);
    +    }
    +
    +    private ReplicaList(List<Replica> replicaList)
    +    {
    +        this.replicaList = replicaList;
    +    }
    +
    +    public boolean equals(Object o)
    +    {
    +        if (this == o) return true;
    +        if (o == null || getClass() != o.getClass()) return false;
    +        ReplicaList that = (ReplicaList) o;
    +        return Objects.equals(replicaList, that.replicaList);
    +    }
    +
    +    public int hashCode()
    +    {
    +
    +        return Objects.hash(replicaList);
    +    }
    +
    +    @Override
    +    public String toString()
    +    {
    +        return replicaList.toString();
    +    }
    +
    +    @Override
    +    public boolean add(Replica replica)
    +    {
    +        return replicaList.add(replica);
    +    }
    +
    +    @Override
    +    public void addAll(Iterable<Replica> replicas)
    +    {
    +        Iterables.addAll(replicaList, replicas);
    +    }
    +
    +    @Override
    +    public int size()
    +    {
    +        return replicaList.size();
    +    }
    +
    +    @Override
    +    public Iterator<Replica> iterator()
    +    {
    +        return replicaList.iterator();
    +    }
    +
    +    public Replica get(int idx)
    +    {
    +        return replicaList.get(idx);
    +    }
    +
    +    public List<InetAddressAndPort> asEndpointList()
    +    {
    +        List<InetAddressAndPort> endpoints = new ArrayList<>(replicaList.size());
    +        for (Replica replica: replicaList)
    +        {
    +            endpoints.add(replica.getEndpoint());
    +        }
    +        return endpoints;
    +    }
    +
    +    @Override
    +    public void removeEndpoint(InetAddressAndPort endpoint)
    +    {
    +        replicaList.removeIf(r -> r.getEndpoint().equals(endpoint));
    +    }
    +
    +    @Override
    +    public void removeReplica(Replica replica)
    +    {
    +        replicaList.remove(replica);
    +    }
    +
    +    public ReplicaList filter(Predicate<Replica> predicate)
    +    {
    +        ArrayList<Replica> newReplicaList = new ArrayList<>(size());
    --- End diff --
    
    This only makes sense if size() is smaller than the default allocation size of ArrayList?
Otherwise you don't know what will come out of filter and probably want to use the usual algorithm?


---

---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Mime
View raw message