/** * Joins the position and size information if possible. This method will return true if the join * was successfully done, and false if no join was done. The join is possible only if the given * position and size is pointing to the data that is next to the data currently described in * {@link StorageDescriptor}. * * @param otherPosition * Position * @param otherSize * Size * @return This method will return true if the join was successfully done, and false if no join * was done. */ public boolean join(long otherPosition, long otherSize) { return simpleStorageDescriptor.join(otherPosition, otherSize); }
/** * Optimizes the list of the descriptors so that necessary joining is done. This method will * also assure that no descriptor has bigger size than {@value #MAX_RANGE_SIZE} bytes, as * defined in {@link #MAX_RANGE_SIZE}. * * @param descriptorList * List of {@link StorageDescriptor}s to optimize. */ private void optimiseDescriptors(List<SimpleStorageDescriptor> descriptorList) { for (int i = 0; i < (descriptorList.size() - 1); i++) { for (int j = i + 1; j < descriptorList.size(); j++) { SimpleStorageDescriptor descriptor = descriptors.get(i); SimpleStorageDescriptor other = descriptors.get(j); if (((descriptor.getSize() + other.getSize()) < MAX_RANGE_SIZE) && descriptor.join(other)) { descriptorList.remove(j); j--; } } } }
/** * Adds the written position and size by updating the existing {@link #descriptors} list. * * @param position * Position that was written. * @param size * Size. */ private synchronized void addPositionAndSize(long position, long size) { for (SimpleStorageDescriptor storageDescriptor : descriptors) { if (((storageDescriptor.getSize() + size) < MAX_RANGE_SIZE) && storageDescriptor.join(position, size)) { return; } } SimpleStorageDescriptor storageDescriptor = new SimpleStorageDescriptor(position, (int) size); descriptors.add(storageDescriptor); }
/** * Joins the position and size information if possible contained in other descriptor. This * method will return true if the join was successfully done, and false if no join was done. The * join is possible only if the given position and size is pointing to the data that is next to * the data currently described in {@link SimpleStorageDescriptor}. * * @param other * Descriptor to join * @return This method will return true if the join was successfully done, and false if no join * was done. */ public boolean join(SimpleStorageDescriptor other) { return join(other.getPosition(), other.getSize()); }