blob: b765e70fd320c01b4753e91da6d26ddb0bf8cc26 [file] [log] [blame]
Thomas Vachuska02aeb032015-01-06 22:36:30 -08001/*
2 * Copyright 2015 Open Networking Laboratory
3 *
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.core;
17
18import java.net.URI;
Thomas Vachuskaebf5e542015-02-03 19:38:13 -080019import java.util.List;
Thomas Vachuska02aeb032015-01-06 22:36:30 -080020import java.util.Objects;
21import java.util.Optional;
22import java.util.Set;
23
24import static com.google.common.base.MoreObjects.toStringHelper;
25import static com.google.common.base.Preconditions.checkArgument;
26import static com.google.common.base.Preconditions.checkNotNull;
27
28/**
29 * Default implementation of network control/management application descriptor.
30 */
31public class DefaultApplication implements Application {
32
33 private final ApplicationId appId;
34 private final Version version;
35 private final String description;
36 private final String origin;
37 private final Set<Permission> permissions;
38 private final Optional<URI> featuresRepo;
Thomas Vachuskaebf5e542015-02-03 19:38:13 -080039 private final List<String> features;
Thomas Vachuska02aeb032015-01-06 22:36:30 -080040
41 /**
42 * Creates a new application descriptor using the supplied data.
43 *
44 * @param appId application identifier
45 * @param version application version
46 * @param description application description
47 * @param origin origin company
48 * @param permissions requested permissions
49 * @param featuresRepo optional features repo URI
50 * @param features application features
51 */
52 public DefaultApplication(ApplicationId appId, Version version,
53 String description, String origin,
54 Set<Permission> permissions,
Thomas Vachuskaebf5e542015-02-03 19:38:13 -080055 Optional<URI> featuresRepo, List<String> features) {
Thomas Vachuska02aeb032015-01-06 22:36:30 -080056 this.appId = checkNotNull(appId, "ID cannot be null");
57 this.version = checkNotNull(version, "Version cannot be null");
58 this.description = checkNotNull(description, "Description cannot be null");
59 this.origin = checkNotNull(origin, "Origin cannot be null");
60 this.permissions = checkNotNull(permissions, "Permissions cannot be null");
61 this.featuresRepo = checkNotNull(featuresRepo, "Features repo cannot be null");
62 this.features = checkNotNull(features, "Features cannot be null");
63 checkArgument(!features.isEmpty(), "There must be at least one feature");
64 }
65
66 @Override
67 public ApplicationId id() {
68 return appId;
69 }
70
71 @Override
72 public Version version() {
73 return version;
74 }
75
76 @Override
77 public String description() {
78 return description;
79 }
80
81 @Override
82 public String origin() {
83 return origin;
84 }
85
86 @Override
87 public Set<Permission> permissions() {
88 return permissions;
89 }
90
91 @Override
92 public Optional<URI> featuresRepo() {
93 return featuresRepo;
94 }
95
96 @Override
Thomas Vachuskaebf5e542015-02-03 19:38:13 -080097 public List<String> features() {
Thomas Vachuska02aeb032015-01-06 22:36:30 -080098 return features;
99 }
100
101 @Override
102 public int hashCode() {
103 return Objects.hash(appId, version, description, origin, permissions,
104 featuresRepo, features);
105 }
106
107 @Override
108 public boolean equals(Object obj) {
109 if (this == obj) {
110 return true;
111 }
112 if (obj == null || getClass() != obj.getClass()) {
113 return false;
114 }
115 final DefaultApplication other = (DefaultApplication) obj;
116 return Objects.equals(this.appId, other.appId) &&
117 Objects.equals(this.version, other.version) &&
118 Objects.equals(this.description, other.description) &&
119 Objects.equals(this.origin, other.origin) &&
120 Objects.equals(this.permissions, other.permissions) &&
121 Objects.equals(this.featuresRepo, other.featuresRepo) &&
122 Objects.equals(this.features, other.features);
123 }
124
125 @Override
126 public String toString() {
127 return toStringHelper(this)
128 .add("appId", appId)
129 .add("version", version)
130 .add("description", description)
131 .add("origin", origin)
132 .add("permissions", permissions)
133 .add("featuresRepo", featuresRepo)
134 .add("features", features)
135 .toString();
136 }
137}