Naoki Shiota | bd1974c | 2016-04-29 18:44:17 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 0a4e674 | 2016-09-15 23:03:10 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Laboratory |
Naoki Shiota | bd1974c | 2016-04-29 18:44:17 -0700 | [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 | |
Yuta HIGUCHI | d95d590 | 2016-06-27 00:18:45 -0700 | [diff] [blame] | 17 | package org.onosproject.net.optical.intent.impl.compiler; |
Naoki Shiota | bd1974c | 2016-04-29 18:44:17 -0700 | [diff] [blame] | 18 | |
| 19 | import com.google.common.annotations.Beta; |
| 20 | import org.onosproject.net.intent.IntentId; |
| 21 | import org.onosproject.net.resource.ResourceConsumerId; |
| 22 | |
| 23 | import java.util.Optional; |
| 24 | |
| 25 | import static com.google.common.base.Preconditions.checkNotNull; |
| 26 | |
Yuta HIGUCHI | d95d590 | 2016-06-27 00:18:45 -0700 | [diff] [blame] | 27 | // TODO consider moving this to api bundle. |
Naoki Shiota | bd1974c | 2016-04-29 18:44:17 -0700 | [diff] [blame] | 28 | /** |
| 29 | * Helper class for ResourceService related processes. |
| 30 | */ |
| 31 | @Beta |
| 32 | public final class ResourceHelper { |
| 33 | |
| 34 | // To avoid instantiation |
| 35 | private ResourceHelper() { |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * Creates IntentId object from given consumer ID. |
| 40 | * |
| 41 | * @param consumerId ConsumerId object |
| 42 | * @return Created IntentId object. null if failed to create or given consumer is not instance of IntentId. |
| 43 | */ |
| 44 | public static Optional<IntentId> getIntentId(ResourceConsumerId consumerId) { |
| 45 | checkNotNull(consumerId); |
| 46 | |
| 47 | if (!consumerId.isClassOf(IntentId.class)) { |
| 48 | return Optional.empty(); |
| 49 | } |
| 50 | |
| 51 | return Optional.of(IntentId.valueOf(consumerId.value())); |
| 52 | } |
| 53 | |
| 54 | } |