blob: 525d09e1374d60a56d8369c2403c4e8d9b89ea23 [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
17package org.onosproject.net.intent.impl;
18
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
27/**
28 * Helper class for ResourceService related processes.
29 */
30@Beta
31public final class ResourceHelper {
32
33 // To avoid instantiation
34 private ResourceHelper() {
35 }
36
37 /**
38 * Creates IntentId object from given consumer ID.
39 *
40 * @param consumerId ConsumerId object
41 * @return Created IntentId object. null if failed to create or given consumer is not instance of IntentId.
42 */
43 public static Optional<IntentId> getIntentId(ResourceConsumerId consumerId) {
44 checkNotNull(consumerId);
45
46 if (!consumerId.isClassOf(IntentId.class)) {
47 return Optional.empty();
48 }
49
50 return Optional.of(IntentId.valueOf(consumerId.value()));
51 }
52
53}