2 * Sixth - System for data storage, computation, exploration and interaction.
3 * Copyright ©2012-2016, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of version 3 of the GNU Lesser General Public License
7 * or later as published by the Free Software Foundation.
10 package eu.svjatoslav.sixth.data.store.file;
12 import java.io.IOException;
14 class EntryRecord implements Comparable<EntryRecord> {
15 public static final int ENTRY_RECORD_LENGTH = 12;
20 public EntryRecord(final FileDataStore dataStore, final int id)
25 final long entryRecordLocation = dataStore.entryAllocationTable
26 .getEntryRecordLocation(id);
28 location = dataStore.readLong(entryRecordLocation);
31 length = dataStore.readInt(entryRecordLocation + 8);
34 public EntryRecord(final int id, final long location, final int length) {
36 this.location = location;
46 public boolean equals(final Object o) {
47 if (o == null) return false;
48 return o instanceof EntryRecord && compareTo((EntryRecord) o) == 0;
52 public int compareTo(final EntryRecord o) {
53 if (location < o.location)
55 if (location > o.location)
67 public int hashCode() {
69 result = 31 * result + (int) (location ^ (location >>> 32));
73 public boolean isUsed() {
78 public void save(final FileDataStore dataStore) throws IOException {
80 final long entryRecordLocation = dataStore.entryAllocationTable
81 .getEntryRecordLocation(id);
83 dataStore.writeLong(entryRecordLocation, location);
84 dataStore.writeInt(entryRecordLocation + 8, length);