blob: 492750e088346b6daa335d569034a5f35bd4f58e [file] [log] [blame]
alshabibeadfc8e2015-08-18 15:40:46 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
alshabibeadfc8e2015-08-18 15:40:46 -07003 *
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 */
alshabib10c810b2015-08-18 16:59:04 -070016package org.onosproject.net.meter;
alshabibeadfc8e2015-08-18 15:40:46 -070017
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}