2 * Sixth Data. Copyright ©2012-2018, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of version 3 of the GNU Lesser General Public License
6 * or later as published by the Free Software Foundation.
9 package eu.svjatoslav.sixth.data.store.file;
11 import java.io.IOException;
13 class EntryRecord implements Comparable<EntryRecord> {
14 public static final int ENTRY_RECORD_LENGTH = 12;
19 public EntryRecord(final FileDataStore dataStore, final int id)
24 final long entryRecordLocation = dataStore.entryAllocationTable
25 .getEntryRecordLocation(id);
27 location = dataStore.readLong(entryRecordLocation);
30 length = dataStore.readInt(entryRecordLocation + 8);
33 public EntryRecord(final int id, final long location, final int length) {
35 this.location = location;
45 public boolean equals(final Object o) {
46 if (o == null) return false;
47 return o instanceof EntryRecord && compareTo((EntryRecord) o) == 0;
51 public int compareTo(final EntryRecord o) {
52 if (location < o.location)
54 if (location > o.location)
66 public int hashCode() {
68 result = 31 * result + (int) (location ^ (location >>> 32));
72 public boolean isUsed() {
77 public void save(final FileDataStore dataStore) throws IOException {
79 final long entryRecordLocation = dataStore.entryAllocationTable
80 .getEntryRecordLocation(id);
82 dataStore.writeLong(entryRecordLocation, location);
83 dataStore.writeInt(entryRecordLocation + 8, length);