blob: a89797554e71c503993709f2531e7f28e8dc85ed [file] [log] [blame]
Sho SHIMIZU76b30f72016-01-11 14:08:35 -08001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2014-present Open Networking Laboratory
Sho SHIMIZU76b30f72016-01-11 14:08:35 -08003 *
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 */
Sho SHIMIZUe18cb122016-02-22 21:04:56 -080016package org.onosproject.net.resource;
Sho SHIMIZU76b30f72016-01-11 14:08:35 -080017
18import com.google.common.annotations.Beta;
Sho SHIMIZU2486ddd2016-01-29 11:51:12 -080019import com.google.common.collect.ImmutableList;
Sho SHIMIZU76b30f72016-01-11 14:08:35 -080020
Sho SHIMIZU7dac8a42016-01-27 12:04:39 -080021import java.util.Optional;
Sho SHIMIZU76b30f72016-01-11 14:08:35 -080022
Sho SHIMIZU76b30f72016-01-11 14:08:35 -080023/**
24 * Represents identifier of resource.
Sho SHIMIZU76b30f72016-01-11 14:08:35 -080025 */
26@Beta
Sho SHIMIZU2d310222016-01-22 11:45:11 -080027public abstract class ResourceId {
Sho SHIMIZU2a704512016-01-26 14:41:34 -080028 static final DiscreteResourceId ROOT = new DiscreteResourceId();
Sho SHIMIZU76b30f72016-01-11 14:08:35 -080029
Sho SHIMIZU2486ddd2016-01-29 11:51:12 -080030 abstract ImmutableList<Object> components();
31
Sho SHIMIZU74ac9012016-02-12 10:03:21 -080032 abstract String simpleTypeName();
33
Sho SHIMIZUcaa2f7b2016-02-12 17:38:49 -080034 // caller must pass a non-null value
35 abstract boolean isTypeOf(Class<?> type);
36
37 // caller must pass a non-null value
38 abstract boolean isSubTypeOf(Class<?> ancestor);
39
Sho SHIMIZU7dac8a42016-01-27 12:04:39 -080040 /**
41 * Returns the parent resource ID of this instance.
42 *
Sho SHIMIZU19816f42016-01-29 11:32:02 -080043 * @return the parent resource ID of this instance.
Sho SHIMIZU7dac8a42016-01-27 12:04:39 -080044 * If there is no parent, empty instance will be returned.
45 */
46 public abstract Optional<DiscreteResourceId> parent();
Sho SHIMIZU76b30f72016-01-11 14:08:35 -080047
Sho SHIMIZU2d310222016-01-22 11:45:11 -080048 /**
49 * Returns a resource ID of a child of this resource based on the specified object.
Sho SHIMIZU2a704512016-01-26 14:41:34 -080050 * If the given object is a {@link Class} instance, {@link IllegalArgumentException} is thrown.
Sho SHIMIZU2d310222016-01-22 11:45:11 -080051 *
52 * @param child the last component of the child
53 * @return a child resource ID
54 */
Sho SHIMIZU2a704512016-01-26 14:41:34 -080055 public abstract DiscreteResourceId child(Object child);
Sho SHIMIZU2d310222016-01-22 11:45:11 -080056
Sho SHIMIZU2a704512016-01-26 14:41:34 -080057 /**
58 * Returns a resource ID of a child of this resource based on the specified object.
59 *
60 * @param child the last component of the child
61 * @return a child resource ID
62 */
63 public abstract ContinuousResourceId child(Class<?> child);
Sho SHIMIZU76b30f72016-01-11 14:08:35 -080064}