Sho SHIMIZU | f33b893 | 2016-01-25 18:43:32 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 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.net.newresource; |
| 17 | |
| 18 | import com.google.common.annotations.Beta; |
| 19 | import com.google.common.collect.ImmutableList; |
| 20 | |
| 21 | import static com.google.common.base.Preconditions.checkNotNull; |
| 22 | |
| 23 | /** |
| 24 | * ResourceId for {@link ContinuousResource} |
| 25 | * |
| 26 | * Note: This class is exposed to the public, but intended to be used in the resource API |
| 27 | * implementation only. It is not for resource API user. |
| 28 | */ |
| 29 | @Beta |
| 30 | // TODO: consider how to restrict the visibility |
| 31 | public final class ContinuousResourceId extends ResourceId { |
| 32 | // for printing purpose only (used in toString() implementation) |
| 33 | private final String name; |
| 34 | |
| 35 | ContinuousResourceId(ImmutableList<Object> components, String name) { |
| 36 | super(components); |
| 37 | this.name = checkNotNull(name); |
| 38 | } |
| 39 | |
| 40 | @Override |
| 41 | public String toString() { |
| 42 | // due to performance consideration, the value might need to be stored in a field |
| 43 | return ImmutableList.builder() |
| 44 | .addAll(components.subList(0, components.size() - 1)) |
| 45 | .add(name) |
| 46 | .build().toString(); |
| 47 | } |
| 48 | } |