Steven Burrows | 3a9a644 | 2016-05-05 15:31:16 +0100 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Steven Burrows | 3a9a644 | 2016-05-05 15:31:16 +0100 | [diff] [blame] | 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 | |
| 17 | package org.onosproject.ui; |
| 18 | |
Simon Hunt | 9bb8fb9 | 2017-05-26 16:49:05 -0700 | [diff] [blame] | 19 | import static com.google.common.base.MoreObjects.toStringHelper; |
chengfan | fdd497c | 2016-11-25 22:17:58 +0800 | [diff] [blame] | 20 | import static com.google.common.base.Preconditions.checkState; |
| 21 | |
Steven Burrows | 3a9a644 | 2016-05-05 15:31:16 +0100 | [diff] [blame] | 22 | /** |
Simon Hunt | 8add9ee | 2016-09-20 17:05:07 -0700 | [diff] [blame] | 23 | * Represents a geographically-based map to be used in the user interface |
| 24 | * topology view. Instances of this class are immutable. |
Steven Burrows | 3a9a644 | 2016-05-05 15:31:16 +0100 | [diff] [blame] | 25 | */ |
| 26 | public class UiTopoMap { |
| 27 | |
| 28 | private final String id; |
Simon Hunt | 8add9ee | 2016-09-20 17:05:07 -0700 | [diff] [blame] | 29 | private final String desc; |
Steven Burrows | 3a9a644 | 2016-05-05 15:31:16 +0100 | [diff] [blame] | 30 | private final String filePath; |
| 31 | private final double scale; |
chengfan | fdd497c | 2016-11-25 22:17:58 +0800 | [diff] [blame] | 32 | private static final int MAX_LENGTH = 32; |
| 33 | private static final String DES_EXC_LIM = "Description is too long"; |
Steven Burrows | 3a9a644 | 2016-05-05 15:31:16 +0100 | [diff] [blame] | 34 | |
| 35 | |
| 36 | /** |
| 37 | * Creates a new topology map. |
| 38 | * |
Simon Hunt | 9bb8fb9 | 2017-05-26 16:49:05 -0700 | [diff] [blame] | 39 | * @param id map identifier |
| 40 | * @param desc map description |
Simon Hunt | 8add9ee | 2016-09-20 17:05:07 -0700 | [diff] [blame] | 41 | * @param filePath map filePath |
Simon Hunt | 9bb8fb9 | 2017-05-26 16:49:05 -0700 | [diff] [blame] | 42 | * @param scale map scale |
Steven Burrows | 3a9a644 | 2016-05-05 15:31:16 +0100 | [diff] [blame] | 43 | */ |
Simon Hunt | 8add9ee | 2016-09-20 17:05:07 -0700 | [diff] [blame] | 44 | public UiTopoMap(String id, String desc, String filePath, double scale) { |
chengfan | fdd497c | 2016-11-25 22:17:58 +0800 | [diff] [blame] | 45 | checkState(desc.length() <= MAX_LENGTH, DES_EXC_LIM); |
Steven Burrows | 3a9a644 | 2016-05-05 15:31:16 +0100 | [diff] [blame] | 46 | this.id = id; |
Simon Hunt | 8add9ee | 2016-09-20 17:05:07 -0700 | [diff] [blame] | 47 | this.desc = desc; |
Steven Burrows | 3a9a644 | 2016-05-05 15:31:16 +0100 | [diff] [blame] | 48 | this.filePath = filePath; |
| 49 | this.scale = scale; |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * Returns the identifier for this map. |
| 54 | * |
| 55 | * @return the identifier |
| 56 | */ |
Simon Hunt | 8add9ee | 2016-09-20 17:05:07 -0700 | [diff] [blame] | 57 | public String id() { |
| 58 | return id; |
Steven Burrows | 3a9a644 | 2016-05-05 15:31:16 +0100 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | /** |
| 62 | * Returns the description for this map. |
| 63 | * |
| 64 | * @return the description |
| 65 | */ |
Simon Hunt | 8add9ee | 2016-09-20 17:05:07 -0700 | [diff] [blame] | 66 | public String description() { |
| 67 | return desc; |
Steven Burrows | 3a9a644 | 2016-05-05 15:31:16 +0100 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | /** |
| 71 | * Returns the filePath for this map. |
| 72 | * |
| 73 | * @return the filePath |
| 74 | */ |
Simon Hunt | 8add9ee | 2016-09-20 17:05:07 -0700 | [diff] [blame] | 75 | public String filePath() { |
| 76 | return filePath; |
Steven Burrows | 3a9a644 | 2016-05-05 15:31:16 +0100 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | /** |
| 80 | * Returns the scale for this map. |
| 81 | * |
| 82 | * @return the scale |
| 83 | */ |
Simon Hunt | 8add9ee | 2016-09-20 17:05:07 -0700 | [diff] [blame] | 84 | public double scale() { |
| 85 | return scale; |
Steven Burrows | 3a9a644 | 2016-05-05 15:31:16 +0100 | [diff] [blame] | 86 | } |
Simon Hunt | 9bb8fb9 | 2017-05-26 16:49:05 -0700 | [diff] [blame] | 87 | |
| 88 | @Override |
| 89 | public String toString() { |
| 90 | return toStringHelper(this) |
| 91 | .add("id", id) |
| 92 | .add("desc", desc) |
| 93 | .toString(); |
| 94 | } |
Steven Burrows | 3a9a644 | 2016-05-05 15:31:16 +0100 | [diff] [blame] | 95 | } |