blob: b67b2f4e8263169bd24798154fc10c7d3cc844af [file] [log] [blame]
Henry Yu4b4a7eb2016-11-09 20:07:53 -05001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016 Open Networking Foundation
Henry Yu4b4a7eb2016-11-09 20:07:53 -05003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.onosproject.tetopology.management.api;
17
18import com.google.common.base.MoreObjects;
19import com.google.common.base.Objects;
20import com.google.common.collect.ImmutableList;
21import com.google.common.collect.Lists;
22
23import java.util.List;
24
25/**
26 * Default Networks implementation.
27 */
28public class DefaultNetworks implements Networks {
29 private final List<Network> networks;
30
31 /**
32 * Creates an instance of DefaultNetworks.
33 *
34 * @param networks list of networks
35 */
36 public DefaultNetworks(List<Network> networks) {
37 this.networks = networks != null ?
38 Lists.newArrayList(networks) : null;
39 }
40
41 @Override
42 public List<Network> networks() {
43 if (networks == null) {
44 return null;
45 }
46 return ImmutableList.copyOf(networks);
47 }
48
49 @Override
50 public int hashCode() {
51 return Objects.hashCode(networks);
52 }
53
54 @Override
55 public boolean equals(Object object) {
56 if (this == object) {
57 return true;
58 }
59 if (object instanceof DefaultNetworks) {
60 DefaultNetworks that = (DefaultNetworks) object;
61 return Objects.equal(networks, that.networks);
62 }
63 return false;
64 }
65
66 @Override
67 public String toString() {
68 return MoreObjects.toStringHelper(this)
69 .add("networks", networks)
70 .toString();
71 }
72
73}