blob: b5453e5baed4b6648aa3584a142b2967121a5ac9 [file] [log] [blame]
Jordan Halterman281dbf32018-06-15 17:46:28 -07001/*
2 * Copyright 2018-present Open Networking Foundation
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.store.flow.impl;
17
18import java.util.Objects;
19
20import org.onosproject.store.LogicalTimestamp;
21
22/**
23 * Flow bucket digest.
24 */
25public class FlowBucketDigest {
26 private final int bucket;
27 private final long term;
28 private final LogicalTimestamp timestamp;
29
30 FlowBucketDigest(int bucket, long term, LogicalTimestamp timestamp) {
31 this.bucket = bucket;
32 this.term = term;
33 this.timestamp = timestamp;
34 }
35
36 /**
37 * Returns the bucket identifier.
38 *
39 * @return the bucket identifier
40 */
41 public int bucket() {
42 return bucket;
43 }
44
45 /**
46 * Returns the bucket term.
47 *
48 * @return the bucket term
49 */
50 public long term() {
51 return term;
52 }
53
54 /**
55 * Returns the bucket timestamp.
56 *
57 * @return the bucket timestamp
58 */
59 public LogicalTimestamp timestamp() {
60 return timestamp;
61 }
62
63 /**
64 * Returns a boolean indicating whether this digest is newer than the given digest.
65 *
66 * @param digest the digest to check
67 * @return indicates whether this digest is newer than the given digest
68 */
69 public boolean isNewerThan(FlowBucketDigest digest) {
70 return digest == null || term() > digest.term() || timestamp().isNewerThan(digest.timestamp());
71 }
72
73 @Override
74 public int hashCode() {
75 return Objects.hash(bucket);
76 }
77
78 @Override
79 public boolean equals(Object object) {
80 return object instanceof FlowBucketDigest
81 && ((FlowBucketDigest) object).bucket == bucket;
82 }
83}