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