RuneHive-Game
Loading...
Searching...
No Matches
Index.java
Go to the documentation of this file.
1package com.runehive.fs.cache;
2
3import com.runehive.fs.util.ByteBufferUtil;
4
5import java.nio.ByteBuffer;
6
7/**
8 * Represents an index within some {@link Cache}.
9 *
10 * @author Ryley Kimmel <ryley.kimmel@live.com>
11 * @author Artem Batutin <artembatutin@gmail.com>
12 */
13public final class Index {
14
15 /** The length of the index. */
16 private final int length;
17
18 /** The id of the index. */
19 private final int id;
20
21 /**
22 * Constructs a new {@link Index} with the expected length and id. This
23 * constructor is marked {@code private} and should not be modified to be
24 * invoked directly, use {@link Index#decode(ByteBuffer)} instead.
25 *
26 * @param length The length of the index.
27 * @param id The id of the index.
28 */
29 private Index(int length, int id) {
30 this.length = length;
31 this.id = id;
32 }
33
34 /**
35 * Decodes an {@link Index} from the specified {@link ByteBuffer}.
36 *
37 * @param buffer The {@link ByteBuffer} to get the index from.
38 * @return The decoded index.
39 */
40 public static Index decode(ByteBuffer buffer) {
41 int length = ByteBufferUtil.getMedium(buffer);
42 int id = ByteBufferUtil.getMedium(buffer);
43 return new Index(length, id);
44 }
45
46 /** Returns the id of this index. */
47 public int getId() {
48 return id;
49 }
50
51 /** Returns the length of this index. */
52 public int getLength() {
53 return length;
54 }
55
56 /** Tests whether or not this index is valid. */
57 public boolean check() {
58 return length > 0;
59 }
60
61}
int getLength()
Returns the length of this index.
Definition Index.java:52
boolean check()
Tests whether or not this index is valid.
Definition Index.java:57
final int id
The id of the index.
Definition Index.java:19
final int length
The length of the index.
Definition Index.java:16
int getId()
Returns the id of this index.
Definition Index.java:47
static Index decode(ByteBuffer buffer)
Decodes an Index from the specified ByteBuffer.
Definition Index.java:40
Index(int length, int id)
Constructs a new Index with the expected length and id.
Definition Index.java:29
A static-utility class containing extension or helper methods for ByteBuffers.
static int getMedium(ByteBuffer buffer)
Gets a 24-bit medium integer from the specified ByteBuffer, this method does not mark the ByteBuffers...