HIGUCHI Yuta
Committed by Gerrit Code Review

Avoid use of Objects.hash when there's only 1 params

- directly call #hashCode() when hashed Object seems non-null
- replace with Objects.hashCode(Object) when Nullable
- replace with Long.hashCode(long), etc. when primitive

Change-Id: I08c24ebbe94cf4162d1491209a14baf953163e41
Showing 67 changed files with 124 additions and 247 deletions
......@@ -61,7 +61,7 @@ public class NextHopGroupKey {
@Override
public int hashCode() {
return Objects.hash(address);
return address.hashCode();
}
@Override
......
......@@ -421,7 +421,7 @@ public class BgpRouteEntry extends RouteEntry {
@Override
public int hashCode() {
return Objects.hash(pathSegments);
return pathSegments.hashCode();
}
@Override
......
......@@ -17,8 +17,6 @@
package org.onosproject.segmentrouting;
import java.util.List;
import java.util.Objects;
import static com.google.common.base.Preconditions.checkNotNull;
/**
......@@ -96,7 +94,7 @@ public class DefaultTunnel implements Tunnel {
@Override
public int hashCode() {
return Objects.hash(labelIds);
return labelIds.hashCode();
}
@Override
......
......@@ -49,7 +49,7 @@ public final class BindingHostId {
@Override
public int hashCode() {
return Objects.hash(bindingHostId);
return bindingHostId.hashCode();
}
@Override
......
......@@ -53,7 +53,7 @@ public final class PhysicalNetwork {
@Override
public int hashCode() {
return Objects.hash(physicalNetwork);
return physicalNetwork.hashCode();
}
@Override
......
......@@ -52,7 +52,7 @@ public final class SecurityGroup {
@Override
public int hashCode() {
return Objects.hash(securityGroup);
return securityGroup.hashCode();
}
@Override
......
......@@ -53,7 +53,7 @@ public final class SegmentationId {
@Override
public int hashCode() {
return Objects.hash(segmentationId);
return segmentationId.hashCode();
}
@Override
......
......@@ -53,7 +53,7 @@ public final class SubnetId {
@Override
public int hashCode() {
return Objects.hash(subnetId);
return subnetId.hashCode();
}
@Override
......
......@@ -53,7 +53,7 @@ public final class TenantId {
@Override
public int hashCode() {
return Objects.hash(tenantId);
return tenantId.hashCode();
}
@Override
......
......@@ -52,7 +52,7 @@ public final class TenantNetworkId {
@Override
public int hashCode() {
return Objects.hash(networkId);
return networkId.hashCode();
}
@Override
......
......@@ -46,7 +46,7 @@ public final class VirtualPortId {
@Override
public int hashCode() {
return Objects.hash(portId);
return portId.hashCode();
}
@Override
......
......@@ -245,7 +245,7 @@ public final class ConfigProperty {
@Override
public int hashCode() {
return Objects.hash(name);
return name.hashCode();
}
/**
......
......@@ -20,6 +20,7 @@ import org.onlab.packet.IpAddress;
import java.util.Objects;
import static com.google.common.base.MoreObjects.toStringHelper;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* Default implementation of a controller instance descriptor.
......@@ -57,7 +58,7 @@ public class DefaultControllerNode implements ControllerNode {
* @param tcpPort TCP port
*/
public DefaultControllerNode(NodeId id, IpAddress ip, int tcpPort) {
this.id = id;
this.id = checkNotNull(id);
this.ip = ip;
this.tcpPort = tcpPort;
}
......@@ -79,7 +80,7 @@ public class DefaultControllerNode implements ControllerNode {
@Override
public int hashCode() {
return Objects.hash(id);
return id.hashCode();
}
@Override
......
......@@ -35,7 +35,7 @@ public class NodeId implements Comparable<NodeId> {
@Override
public int hashCode() {
return Objects.hash(id);
return id.hashCode();
}
@Override
......
......@@ -58,7 +58,7 @@ public class DefaultApplicationId implements ApplicationId {
@Override
public int hashCode() {
return Objects.hash(id);
return Short.hashCode(id);
}
@Override
......
......@@ -42,7 +42,7 @@ public class DefaultGroupId implements GroupId {
@Override
public int hashCode() {
return Objects.hash(id);
return id;
}
@Override
......
......@@ -127,7 +127,7 @@ public final class Version {
@Override
public int hashCode() {
return Objects.hash(format);
return format.hashCode();
}
@Override
......
......@@ -88,7 +88,7 @@ public class DefaultPath extends DefaultLink implements Path {
@Override
public int hashCode() {
return Objects.hash(links);
return links.hashCode();
}
@Override
......
......@@ -75,7 +75,7 @@ public final class DeviceId extends ElementId {
@Override
public int hashCode() {
return Objects.hash(str);
return str.hashCode();
}
@Override
......
......@@ -52,7 +52,7 @@ public final class BridgeName {
@Override
public int hashCode() {
return Objects.hash(name);
return name.hashCode();
}
@Override
......
......@@ -516,7 +516,7 @@ public final class Instructions {
@Override
public int hashCode() {
return Objects.hash(type().ordinal());
return type().ordinal();
}
@Override
......@@ -550,7 +550,7 @@ public final class Instructions {
@Override
public int hashCode() {
return Objects.hash(type().ordinal());
return type().ordinal();
}
@Override
......
......@@ -114,7 +114,7 @@ public abstract class L0ModificationInstruction implements Instruction {
@Override
public int hashCode() {
return Objects.hash(lambda);
return lambda.hashCode();
}
@Override
......
......@@ -62,7 +62,7 @@ public abstract class L1ModificationInstruction implements Instruction {
@Override
public int hashCode() {
return Objects.hash(oduSignalId);
return oduSignalId.hashCode();
}
@Override
......
......@@ -186,7 +186,7 @@ public class DefaultGroup extends DefaultGroupDescription
*/
@Override
public int hashCode() {
return super.hashCode() + Objects.hash(id);
return Objects.hash(super.hashCode(), id);
}
/*
......
......@@ -87,7 +87,7 @@ public final class BandwidthConstraint extends BooleanConstraint {
@Override
public int hashCode() {
return Objects.hash(bandwidth);
return bandwidth.hashCode();
}
@Override
......
......@@ -69,7 +69,7 @@ public class LambdaConstraint extends BooleanConstraint {
@Override
public int hashCode() {
return Objects.hash(lambda);
return Objects.hashCode(lambda);
}
@Override
......
......@@ -67,7 +67,7 @@ public class LatencyConstraint implements Constraint {
@Override
public int hashCode() {
return Objects.hash(latency);
return latency.hashCode();
}
@Override
......
......@@ -66,7 +66,7 @@ public class ObstacleConstraint extends BooleanConstraint {
@Override
public int hashCode() {
return Objects.hash(obstacles);
return obstacles.hashCode();
}
@Override
......
......@@ -91,7 +91,7 @@ public class WaypointConstraint implements Constraint {
@Override
public int hashCode() {
return Objects.hash(waypoints);
return waypoints.hashCode();
}
@Override
......
......@@ -53,7 +53,7 @@ public class BandwidthResourceAllocation implements ResourceAllocation {
@Override
public int hashCode() {
return Objects.hash(bandwidth);
return bandwidth.hashCode();
}
@Override
......
......@@ -53,7 +53,7 @@ public class BandwidthResourceRequest implements ResourceRequest {
@Override
public int hashCode() {
return Objects.hash(bandwidth);
return bandwidth.hashCode();
}
@Override
......
......@@ -53,7 +53,7 @@ public class LambdaResourceAllocation implements ResourceAllocation {
@Override
public int hashCode() {
return Objects.hash(lambda);
return Objects.hashCode(lambda);
}
@Override
......
......@@ -54,7 +54,7 @@ public class MplsLabelResourceAllocation implements ResourceAllocation {
@Override
public int hashCode() {
return Objects.hash(mplsLabel);
return Objects.hashCode(mplsLabel);
}
@Override
......
......@@ -53,7 +53,7 @@ public final class ClusterId {
@Override
public int hashCode() {
return Objects.hash(id);
return id;
}
@Override
......
......@@ -20,6 +20,7 @@ import org.onosproject.net.Link;
import java.util.Objects;
import static com.google.common.base.MoreObjects.toStringHelper;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* Implementation of the topology edge backed by a link.
......@@ -40,7 +41,7 @@ public class DefaultTopologyEdge implements TopologyEdge {
public DefaultTopologyEdge(TopologyVertex src, TopologyVertex dst, Link link) {
this.src = src;
this.dst = dst;
this.link = link;
this.link = checkNotNull(link);
}
@Override
......@@ -60,7 +61,7 @@ public class DefaultTopologyEdge implements TopologyEdge {
@Override
public int hashCode() {
return Objects.hash(link);
return link.hashCode();
}
@Override
......
......@@ -42,7 +42,7 @@ public class DefaultTopologyVertex implements TopologyVertex {
@Override
public int hashCode() {
return Objects.hash(deviceId);
return deviceId.hashCode();
}
@Override
......
......@@ -52,7 +52,7 @@ public class WallClockTimestamp implements Timestamp {
}
@Override
public int hashCode() {
return Objects.hash(unixTimestamp);
return Long.hashCode(unixTimestamp);
}
@Override
......
......@@ -138,7 +138,7 @@ public class UiView {
@Override
public int hashCode() {
return Objects.hash(id);
return id.hashCode();
}
@Override
......
......@@ -192,14 +192,17 @@ public class IntentTestsMocks {
new MplsLabelResourceAllocation(MplsLabel.valueOf(10)));
}
@Override
public IntentId intentId() {
return null;
}
@Override
public Collection<Link> links() {
return null;
}
@Override
public Set<ResourceRequest> resources() {
return null;
}
......@@ -408,7 +411,7 @@ public class IntentTestsMocks {
@Override
public int hashCode() {
return Objects.hash(priority);
return priority;
}
@Override
......
......@@ -51,7 +51,7 @@ public class SystemClockTimestamp implements Timestamp {
}
@Override
public int hashCode() {
return Objects.hash(nanoTimestamp);
return Long.hashCode(nanoTimestamp);
}
@Override
......
......@@ -50,7 +50,7 @@ public class LogicalTimestamp implements Timestamp {
@Override
public int hashCode() {
return Objects.hash(value);
return Long.hashCode(value);
}
@Override
......
......@@ -56,7 +56,7 @@ public class PartitionId {
@Override
public int hashCode() {
return Objects.hash(id);
return id;
}
@Override
......
......@@ -39,7 +39,7 @@ public class DomainEdge extends AbstractEdge<DomainVertex> {
@Override
public int hashCode() {
return 43 * super.hashCode() + Objects.hash(connectPoint);
return 43 * super.hashCode() + connectPoint.hashCode();
}
@Override
......
......@@ -63,7 +63,7 @@ public final class OpticalLogicId {
@Override
public int hashCode() {
return Objects.hash(logicId);
return Objects.hashCode(logicId);
}
@Override
......
......@@ -53,7 +53,7 @@ public class DefaultVirtualDevice extends DefaultDevice implements VirtualDevice
@Override
public int hashCode() {
return 31 * super.hashCode() + Objects.hash(networkId);
return 31 * super.hashCode() + networkId.hashCode();
}
@Override
......
......@@ -59,7 +59,7 @@ public final class TenantId {
@Override
public int hashCode() {
return Objects.hash(id);
return id.hashCode();
}
@Override
......
......@@ -49,7 +49,7 @@ public final class OvsdbBridgeName {
@Override
public int hashCode() {
return Objects.hash(value);
return value.hashCode();
}
@Override
......
......@@ -47,7 +47,7 @@ public final class OvsdbDatapathId {
@Override
public int hashCode() {
return Objects.hash(value);
return value.hashCode();
}
@Override
......
......@@ -47,7 +47,7 @@ public class OvsdbIfaceId {
@Override
public int hashCode() {
return Objects.hash(value);
return value.hashCode();
}
@Override
......
......@@ -44,7 +44,7 @@ public final class OvsdbNodeId {
@Override
public int hashCode() {
return Objects.hash(nodeId);
return nodeId.hashCode();
}
@Override
......
......@@ -49,7 +49,7 @@ public final class OvsdbPortName {
@Override
public int hashCode() {
return Objects.hash(value);
return value.hashCode();
}
@Override
......
......@@ -47,7 +47,7 @@ public final class OvsdbPortNumber {
@Override
public int hashCode() {
return Objects.hash(value);
return Objects.hashCode(value);
}
@Override
......
......@@ -49,7 +49,7 @@ public class OvsdbPortType {
@Override
public int hashCode() {
return Objects.hash(value);
return value.hashCode();
}
@Override
......
......@@ -48,7 +48,7 @@ public final class OvsdbTunnelName {
@Override
public int hashCode() {
return Objects.hash(value);
return value.hashCode();
}
@Override
......
......@@ -85,7 +85,7 @@ public final class TableUpdate {
@Override
public int hashCode() {
return Objects.hash(rows);
return rows.hashCode();
}
@Override
......
......@@ -67,7 +67,7 @@ public final class TableUpdates {
@Override
public int hashCode() {
return Objects.hash(result);
return result.hashCode();
}
@Override
......
......@@ -61,7 +61,7 @@ public final class OvsdbMap {
@Override
public int hashCode() {
return Objects.hash(map);
return map.hashCode();
}
@Override
......
......@@ -63,7 +63,7 @@ public final class OvsdbSet {
@Override
public int hashCode() {
return Objects.hash(set);
return set.hashCode();
}
@Override
......
......@@ -62,7 +62,7 @@ public final class UUID {
@Override
public int hashCode() {
return Objects.hash(value);
return value.hashCode();
}
@Override
......
......@@ -210,7 +210,7 @@ public abstract class AbstractOvsdbTableService implements OvsdbTableService {
return null;
}
ColumnDescription columnDesc = new ColumnDescription("_uuid", "getTableUuidColumn");
return (Column) getColumnHandler(columnDesc);
return getColumnHandler(columnDesc);
}
@Override
......@@ -228,7 +228,7 @@ public abstract class AbstractOvsdbTableService implements OvsdbTableService {
return null;
}
ColumnDescription columnDesc = new ColumnDescription("_version", "getTableVersionColumn");
return (Column) getColumnHandler(columnDesc);
return getColumnHandler(columnDesc);
}
/**
......@@ -260,7 +260,7 @@ public abstract class AbstractOvsdbTableService implements OvsdbTableService {
@Override
public int hashCode() {
return Objects.hash(row);
return row.hashCode();
}
@Override
......@@ -277,7 +277,7 @@ public abstract class AbstractOvsdbTableService implements OvsdbTableService {
@Override
public String toString() {
TableSchema schema = (TableSchema) getTableSchema();
TableSchema schema = getTableSchema();
String tableName = schema.name();
return toStringHelper(this).add("tableName", tableName).add("row", row).toString();
}
......
......@@ -110,7 +110,7 @@ public class DependencyCycle {
@Override
public int hashCode() {
return Objects.hash(cycle);
return cycle.hashCode();
}
@Override
......
......@@ -30,8 +30,8 @@ import static com.google.common.base.MoreObjects.toStringHelper;
*/
public class DisjointPathPair<V extends Vertex, E extends Edge<V>> implements Path<V, E> {
private Path<V, E> primary, secondary;
boolean primaryActive = true;
private final Path<V, E> primary, secondary;
private boolean primaryActive = true;
/**
* Creates a disjoint path pair from two paths.
......@@ -88,7 +88,7 @@ public class DisjointPathPair<V extends Vertex, E extends Edge<V>> implements Pa
* @return boolean representing whether it has backup
*/
public boolean hasBackup() {
return secondary != null && secondary.edges() != null;
return secondary != null;
}
@Override
......@@ -103,7 +103,9 @@ public class DisjointPathPair<V extends Vertex, E extends Edge<V>> implements Pa
@Override
public int hashCode() {
return hasBackup() ? Objects.hash(primary) + Objects.hash(secondary) :
// Note: DisjointPathPair with primary and secondary swapped
// must result in same hashCode
return hasBackup() ? primary.hashCode() + secondary.hashCode() :
Objects.hash(primary);
}
......
/*
* Copyright 2015 Open Networking Laboratory
*
* Licensed 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.onlab.graph;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import static com.google.common.collect.ImmutableSet.of;
import static com.google.common.base.MoreObjects.toStringHelper;
public class DisjointPathPair<V extends Vertex, E extends Edge<V>> implements Path<V, E> {
public Path<V, E> path1, path2;
boolean usingPath1 = true;
<<<<<<< HEAD
/**
* Creates a Disjoint Path Pair from two paths.
*
* @param p1 first path
* @param p2 second path
*/
=======
>>>>>>> Disjoint Path Pairs (Suurballe) utils
public DisjointPathPair(Path<V, E> p1, Path<V, E> p2) {
path1 = p1;
path2 = p2;
}
<<<<<<< HEAD
@Override
=======
>>>>>>> Disjoint Path Pairs (Suurballe) utils
public V src() {
return path1.src();
}
<<<<<<< HEAD
@Override
public V dst() {
return path1.dst();
}
@Override
=======
public V dst() {
return path1.dst();
}
>>>>>>> Disjoint Path Pairs (Suurballe) utils
public double cost() {
if (!hasBackup()) {
return path1.cost();
}
return path1.cost() + path2.cost();
}
<<<<<<< HEAD
@Override
=======
>>>>>>> Disjoint Path Pairs (Suurballe) utils
public List<E> edges() {
if (usingPath1 || !hasBackup()) {
return path1.edges();
} else {
return path2.edges();
}
}
<<<<<<< HEAD
/**
* Checks if this path pair contains a backup/secondary path.
*
* @return boolean representing whether it has backup
*/
public boolean hasBackup() {
return path2 != null && path2.edges() != null;
}
/**
* Switches this disjoint path pair to using its backup path, instead of
* using its primary.
*/
public void useBackup() {
usingPath1 = !usingPath1;
}
@Override
=======
public boolean hasBackup() {
return path2 != null && path2.edges() != null;
}
public void useBackup() {
usingPath1 = !usingPath1;
}
>>>>>>> Disjoint Path Pairs (Suurballe) utils
public String toString() {
return toStringHelper(this)
.add("src", src())
.add("dst", dst())
.add("cost", cost())
.add("edges", edges())
.toString();
}
<<<<<<< HEAD
@Override
=======
>>>>>>> Disjoint Path Pairs (Suurballe) utils
public int hashCode() {
Set<Path<V, E>> paths;
if (!hasBackup()) {
paths = of(path1);
} else {
paths = of(path1, path2);
}
return Objects.hash(paths);
}
<<<<<<< HEAD
@Override
=======
>>>>>>> Disjoint Path Pairs (Suurballe) utils
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof DisjointPathPair) {
final DisjointPathPair other = (DisjointPathPair) obj;
return Objects.equals(this.src(), other.src()) &&
Objects.equals(this.dst(), other.dst()) &&
(Objects.equals(this.path1, other.path1) &&
Objects.equals(this.path2, other.path2)) ||
(Objects.equals(this.path1, other.path2) &&
Objects.equals(this.path2, other.path1));
}
return false;
}
<<<<<<< HEAD
/**
* Returns number of paths inside this path pair object.
*
* @return number of paths
*/
=======
>>>>>>> Disjoint Path Pairs (Suurballe) utils
public int size() {
if (hasBackup()) {
return 2;
}
return 1;
}
}
......@@ -18,8 +18,6 @@ package org.onlab.util;
import com.google.common.base.MoreObjects;
import com.google.common.collect.ComparisonChain;
import java.util.Objects;
/**
* Class representing frequency. This class is intended to be used for a value whose unit is Hz
* and its family (KHz, MHz, etc.).
......@@ -157,7 +155,7 @@ public final class Frequency implements RichComparable<Frequency> {
@Override
public int hashCode() {
return Objects.hash(frequency);
return Long.hashCode(frequency);
}
@Override
......
package org.onlab.graph;
import static org.junit.Assert.*;
import org.junit.Test;
import com.google.common.collect.ImmutableList;
import com.google.common.testing.EqualsTester;
/**
* Test of DisjointPathPair.
*/
public class DisjointPathPairTest {
private static final TestVertex A = new TestVertex("A");
private static final TestVertex B = new TestVertex("B");
private static final TestVertex C = new TestVertex("C");
private static final TestVertex D = new TestVertex("D");
private static final TestEdge AB = new TestEdge(A, B, 1.0);
private static final TestEdge BC = new TestEdge(B, C, 1.0);
private static final TestEdge AD = new TestEdge(A, D, 1.0);
private static final TestEdge DC = new TestEdge(D, C, 1.0);
private static final Path<TestVertex, TestEdge> ABC
= new DefaultPath<>(ImmutableList.of(AB, BC), 1.0);
private static final Path<TestVertex, TestEdge> ADC
= new DefaultPath<>(ImmutableList.of(AD, DC), 1.0);
@Test
public void testSwappingPrimarySecondaryDoesntImpactHashCode() {
assertEquals(new DisjointPathPair<>(ABC, ADC).hashCode(),
new DisjointPathPair<>(ADC, ABC).hashCode());
}
@Test
public void testSwappingPrimarySecondaryDoesntImpactEquality() {
new EqualsTester()
.addEqualityGroup(new DisjointPathPair<>(ABC, ADC),
new DisjointPathPair<>(ADC, ABC));
}
}
......@@ -30,7 +30,7 @@ public class TestVertex implements Vertex {
@Override
public int hashCode() {
return Objects.hash(name);
return name.hashCode();
}
@Override
......
......@@ -101,7 +101,7 @@ public class Step implements Vertex {
@Override
public int hashCode() {
return Objects.hash(name);
return name.hashCode();
}
@Override
......