blob: 4d1a8d1f4e4b2fc978371d8d1ca52179eaaaa4ec [file] [log] [blame]
Naoki Shiotabd1974c2016-04-29 18:44:17 -07001/*
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
Yuta HIGUCHId95d5902016-06-27 00:18:45 -070017package org.onosproject.net.optical.intent.impl.compiler;
Naoki Shiotabd1974c2016-04-29 18:44:17 -070018
19import com.google.common.annotations.Beta;
20import org.onosproject.net.intent.IntentId;
21import org.onosproject.net.resource.ResourceConsumerId;
22
23import java.util.Optional;
24
25import static com.google.common.base.Preconditions.checkNotNull;
26
Yuta HIGUCHId95d5902016-06-27 00:18:45 -070027// TODO consider moving this to api bundle.
Naoki Shiotabd1974c2016-04-29 18:44:17 -070028/**
29 * Helper class for ResourceService related processes.
30 */
31@Beta
32public 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}