Use ConcurrentNavigableMap
[controller.git] / third-party / atomix / storage / src / main / java / io / atomix / storage / journal / Indexed.java
1 /*
2  * Copyright 2017-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  */
16 package io.atomix.storage.journal;
17
18 import static com.google.common.base.MoreObjects.toStringHelper;
19
20 /**
21  * Indexed journal entry.
22  */
23 public class Indexed<E> {
24   private final long index;
25   private final E entry;
26   private final int size;
27
28   public Indexed(long index, E entry, int size) {
29     this.index = index;
30     this.entry = entry;
31     this.size = size;
32   }
33
34   /**
35    * Returns the entry index.
36    *
37    * @return The entry index.
38    */
39   public long index() {
40     return index;
41   }
42
43   /**
44    * Returns the indexed entry.
45    *
46    * @return The indexed entry.
47    */
48   public E entry() {
49     return entry;
50   }
51
52   /**
53    * Returns the serialized entry size.
54    *
55    * @return The serialized entry size.
56    */
57   public int size() {
58     return size;
59   }
60
61   /**
62    * Returns the entry type class.
63    *
64    * @return The entry class.
65    */
66   public Class<?> type() {
67     return entry.getClass();
68   }
69
70   @Override
71   public String toString() {
72     return toStringHelper(this)
73         .add("index", index)
74         .add("entry", entry)
75         .toString();
76   }
77 }