blob: bff757bd861047534462ac8cf89acd0fc449a832 [file] [log] [blame]
alshabib1d2bc402015-07-31 17:04:11 -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 static com.google.common.base.Preconditions.checkArgument;
19
20/**
21 * A default implementation for a Band.
22 */
23public final class DefaultBand implements Band {
24
25 private final Type type;
26 private final long rate;
27 private final long burstSize;
28 private final short prec;
29
30 public DefaultBand(Type type, long rate,
31 long burstSize, short prec) {
32 this.type = type;
33 this.rate = rate;
34 this.burstSize = burstSize;
35 this.prec = prec;
36 }
37
38 @Override
39 public long rate() {
40 return rate;
41 }
42
43 @Override
44 public long burst() {
45 return burstSize;
46 }
47
48 @Override
49 public short dropPrecedence() {
50 return prec;
51 }
52
53 @Override
54 public Type type() {
55 return type;
56 }
57
58 public static Builder builder() {
59 return new Builder();
60 }
61
62 public static final class Builder implements Band.Builder {
63
64 private long rate;
65 private long burstSize;
66 private Short prec;
67 private Type type;
68
69 @Override
70 public Band.Builder withRate(long rate) {
71 this.rate = rate;
72 return this;
73 }
74
75 @Override
76 public Band.Builder burstSize(long burstSize) {
77 this.burstSize = burstSize;
78 return this;
79 }
80
81 @Override
82 public Band.Builder dropPrecedence(short prec) {
83 this.prec = prec;
84 return this;
85 }
86
87 @Override
88 public Band.Builder ofType(Type type) {
89 this.type = type;
90 return this;
91 }
92
93 @Override
94 public Band build() {
95 checkArgument(prec != null && type == Type.REMARK,
96 "Only REMARK bands can have a precendence.");
97
98 return new DefaultBand(type, rate, burstSize, prec);
99 }
100
101
102 }
103}