blob: 8ad5aa672faee3510c5afefb4c749d74ba8a5a98 [file] [log] [blame]
alshabibeadfc8e2015-08-18 15:40:46 -07001/*
2 * Copyright 2015 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 */
16package org.onosproject.incubator.net.meter;
17
18import java.util.Optional;
19
20/**
21 * An entity used to indicate whether the store operation passed.
22 */
23public final class MeterStoreResult {
24
25
26 private final Type type;
27 private final Optional<MeterFailReason> reason;
28
29 public enum Type {
30 SUCCESS,
31 FAIL
32 }
33
34 private MeterStoreResult(Type type, MeterFailReason reason) {
35 this.type = type;
36 this.reason = Optional.ofNullable(reason);
37 }
38
39 public Type type() {
40 return type;
41 }
42
43 public Optional<MeterFailReason> reason() {
44 return reason;
45 }
46
47 /**
48 * A successful store opertion.
49 *
50 * @return a meter store result
51 */
52 public static MeterStoreResult success() {
53 return new MeterStoreResult(Type.SUCCESS, null);
54 }
55
56 /**
57 * A failed store operation.
58 *
59 * @param reason a failure reason
60 * @return a meter store result
61 */
62 public static MeterStoreResult fail(MeterFailReason reason) {
63 return new MeterStoreResult(Type.FAIL, reason);
64 }
65
66}