2 * Sixth Data. Author: Svjatoslav Agejenko.
3 * This project is released under Creative Commons Zero (CC0) license.
7 package eu.svjatoslav.sixth.data.store.file;
9 import java.io.IOException;
11 class EntryRecord implements Comparable<EntryRecord> {
12 public static final int ENTRY_RECORD_LENGTH = 12;
17 public EntryRecord(final FileDataStore dataStore, final int id)
22 final long entryRecordLocation = dataStore.entryAllocationTable
23 .getEntryRecordLocation(id);
25 location = dataStore.readLong(entryRecordLocation);
28 length = dataStore.readInt(entryRecordLocation + 8);
31 public EntryRecord(final int id, final long location, final int length) {
33 this.location = location;
43 public boolean equals(final Object o) {
44 if (o == null) return false;
45 return o instanceof EntryRecord && compareTo((EntryRecord) o) == 0;
49 public int compareTo(final EntryRecord o) {
50 if (location < o.location)
52 if (location > o.location)
64 public int hashCode() {
66 result = 31 * result + (int) (location ^ (location >>> 32));
70 public boolean isUsed() {
75 public void save(final FileDataStore dataStore) throws IOException {
77 final long entryRecordLocation = dataStore.entryAllocationTable
78 .getEntryRecordLocation(id);
80 dataStore.writeLong(entryRecordLocation, location);
81 dataStore.writeInt(entryRecordLocation + 8, length);