Committed by
Gerrit Code Review
Change the return type of ResourceId#parent()
Change-Id: Ice8c46f4dca02cfc24f85a6758a8536872b4c262
Showing
5 changed files
with
20 additions
and
11 deletions
... | @@ -92,7 +92,7 @@ public final class ContinuousResource implements Resource { | ... | @@ -92,7 +92,7 @@ public final class ContinuousResource implements Resource { |
92 | 92 | ||
93 | @Override | 93 | @Override |
94 | public Optional<DiscreteResource> parent() { | 94 | public Optional<DiscreteResource> parent() { |
95 | - return Optional.ofNullable(id.parent()).map(DiscreteResource::new); | 95 | + return id.parent().map(DiscreteResource::new); |
96 | } | 96 | } |
97 | 97 | ||
98 | @Override | 98 | @Override | ... | ... |
... | @@ -19,6 +19,7 @@ import com.google.common.annotations.Beta; | ... | @@ -19,6 +19,7 @@ import com.google.common.annotations.Beta; |
19 | import com.google.common.collect.ImmutableList; | 19 | import com.google.common.collect.ImmutableList; |
20 | 20 | ||
21 | import java.util.Objects; | 21 | import java.util.Objects; |
22 | +import java.util.Optional; | ||
22 | 23 | ||
23 | import static com.google.common.base.Preconditions.checkNotNull; | 24 | import static com.google.common.base.Preconditions.checkNotNull; |
24 | 25 | ||
... | @@ -72,14 +73,14 @@ public final class ContinuousResourceId extends ResourceId { | ... | @@ -72,14 +73,14 @@ public final class ContinuousResourceId extends ResourceId { |
72 | } | 73 | } |
73 | 74 | ||
74 | @Override | 75 | @Override |
75 | - DiscreteResourceId parent() { | 76 | + public Optional<DiscreteResourceId> parent() { |
76 | if (components.size() == 0) { | 77 | if (components.size() == 0) { |
77 | - return null; | 78 | + return Optional.empty(); |
78 | } | 79 | } |
79 | if (components.size() == 1) { | 80 | if (components.size() == 1) { |
80 | - return ROOT; | 81 | + return Optional.of(ROOT); |
81 | } else { | 82 | } else { |
82 | - return new DiscreteResourceId(components.subList(0, components.size() - 1)); | 83 | + return Optional.of(new DiscreteResourceId(components.subList(0, components.size() - 1))); |
83 | } | 84 | } |
84 | } | 85 | } |
85 | 86 | ... | ... |
... | @@ -90,7 +90,7 @@ public final class DiscreteResource implements Resource { | ... | @@ -90,7 +90,7 @@ public final class DiscreteResource implements Resource { |
90 | 90 | ||
91 | @Override | 91 | @Override |
92 | public Optional<DiscreteResource> parent() { | 92 | public Optional<DiscreteResource> parent() { |
93 | - return Optional.ofNullable(id.parent()).map(DiscreteResource::new); | 93 | + return id.parent().map(DiscreteResource::new); |
94 | } | 94 | } |
95 | 95 | ||
96 | @Override | 96 | @Override | ... | ... |
... | @@ -19,6 +19,7 @@ import com.google.common.annotations.Beta; | ... | @@ -19,6 +19,7 @@ import com.google.common.annotations.Beta; |
19 | import com.google.common.collect.ImmutableList; | 19 | import com.google.common.collect.ImmutableList; |
20 | 20 | ||
21 | import java.util.Objects; | 21 | import java.util.Objects; |
22 | +import java.util.Optional; | ||
22 | 23 | ||
23 | import static com.google.common.base.Preconditions.checkArgument; | 24 | import static com.google.common.base.Preconditions.checkArgument; |
24 | import static com.google.common.base.Preconditions.checkNotNull; | 25 | import static com.google.common.base.Preconditions.checkNotNull; |
... | @@ -63,14 +64,14 @@ public final class DiscreteResourceId extends ResourceId { | ... | @@ -63,14 +64,14 @@ public final class DiscreteResourceId extends ResourceId { |
63 | } | 64 | } |
64 | 65 | ||
65 | @Override | 66 | @Override |
66 | - DiscreteResourceId parent() { | 67 | + public Optional<DiscreteResourceId> parent() { |
67 | if (components.size() == 0) { | 68 | if (components.size() == 0) { |
68 | - return null; | 69 | + return Optional.empty(); |
69 | } | 70 | } |
70 | if (components.size() == 1) { | 71 | if (components.size() == 1) { |
71 | - return ROOT; | 72 | + return Optional.of(ROOT); |
72 | } else { | 73 | } else { |
73 | - return new DiscreteResourceId(components.subList(0, components.size() - 1)); | 74 | + return Optional.of(new DiscreteResourceId(components.subList(0, components.size() - 1))); |
74 | } | 75 | } |
75 | } | 76 | } |
76 | 77 | ... | ... |
... | @@ -21,6 +21,7 @@ import org.onosproject.net.DeviceId; | ... | @@ -21,6 +21,7 @@ import org.onosproject.net.DeviceId; |
21 | import org.onosproject.net.PortNumber; | 21 | import org.onosproject.net.PortNumber; |
22 | 22 | ||
23 | import java.util.Arrays; | 23 | import java.util.Arrays; |
24 | +import java.util.Optional; | ||
24 | 25 | ||
25 | import static com.google.common.base.Preconditions.checkArgument; | 26 | import static com.google.common.base.Preconditions.checkArgument; |
26 | 27 | ||
... | @@ -66,7 +67,13 @@ public abstract class ResourceId { | ... | @@ -66,7 +67,13 @@ public abstract class ResourceId { |
66 | .add(Arrays.copyOfRange(components, 0, components.length - 1)), (Class<?>) last); | 67 | .add(Arrays.copyOfRange(components, 0, components.length - 1)), (Class<?>) last); |
67 | } | 68 | } |
68 | 69 | ||
69 | - abstract DiscreteResourceId parent(); | 70 | + /** |
71 | + * Returns the parent resource ID of this instance. | ||
72 | + * | ||
73 | + * @return the parent resource path of this instance. | ||
74 | + * If there is no parent, empty instance will be returned. | ||
75 | + */ | ||
76 | + public abstract Optional<DiscreteResourceId> parent(); | ||
70 | 77 | ||
71 | /** | 78 | /** |
72 | * Returns a resource ID of a child of this resource based on the specified object. | 79 | * Returns a resource ID of a child of this resource based on the specified object. | ... | ... |
-
Please register or login to post a comment