/** * {@inheritDoc} */ @Override public List<IStorageDescriptor> query(IIndexQuery query) { List<IStorageDescriptor> list = new ArrayList<>(); for (SimpleStorageDescriptor simpleStorageDescriptor : descriptors) { list.add(new StorageDescriptor(id, simpleStorageDescriptor)); } return list; }
/** * Joins the information from the other storage descriptor 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 two descriptors are actually describing the data in the same channel that are * next to each other. There is no difference if the other descriptor is pointing to the data * after or before this descriptor. After successful join the joined data descriptor will be * represented by this descriptor. * * @param other * Descriptor information to join. * @return This method will return true if the join was successfully done, and false if no join * was done. */ public boolean join(IStorageDescriptor other) { if (this.getChannelId() != other.getChannelId()) { return false; } else { return join(other.getPosition(), other.getSize()); } }
for (IStorageDescriptor descriptor : entry.getValue()) { if (null == storageDescriptor) { storageDescriptor = new StorageDescriptor(entry.getKey()); storageDescriptor.setPositionAndSize(descriptor.getPosition(), descriptor.getSize()); } else { if (!storageDescriptor.join(descriptor)) { optimizedDescriptors.add(storageDescriptor); storageDescriptor = new StorageDescriptor(entry.getKey()); storageDescriptor.setPositionAndSize(descriptor.getPosition(), descriptor.getSize());
/** * {@inheritDoc} */ @Override public IStorageDescriptor put(E element) throws IndexingException { if (null == element) { throw new IndexingException("Element to index can not be null."); } else if (0 == element.getId()) { throw new IndexingException("Element to index can not have ID that is equal to zero."); } StorageDescriptor descriptor = new StorageDescriptor(this.id); if (insertIntoArrays(element.getId(), descriptor.getSimpleStorageDescriptor())) { return descriptor; } else { throw new IndexingException("Element already indexed."); } }
/** * {@inheritDoc} */ @Override public IStorageDescriptor get(E element) { readLock.lock(); try { int index = Arrays.binarySearch(idArray, 0, size, element.getId()); if (index >= 0) { SimpleStorageDescriptor simpleDescriptor = descriptorArray[index]; if (null != simpleDescriptor) { return new StorageDescriptor(this.id, simpleDescriptor); } else { return null; } } else { return null; } } finally { readLock.unlock(); } }
idArray[size] = 0; return new StorageDescriptor(id, simpleDescriptor); } finally { writeLock.unlock();
SimpleStorageDescriptor simpleDescriptor = descriptorArray[index]; if (null != simpleDescriptor) { returnList.add(new StorageDescriptor(this.id, simpleDescriptor));
SimpleStorageDescriptor simpleDescriptor = descriptorArray[index]; if (null != simpleDescriptor) { returnList.add(new StorageDescriptor(this.id, simpleDescriptor));
/** * Test that tests the functionality of {@link CombinedStorageQueryTask} */ @SuppressWarnings("unchecked") @Test public void queryCombinedStorageBranch() { List<IStorageDescriptor> testResultList = new ArrayList<>(); testResultList.add(new StorageDescriptor()); testResultList.add(new StorageDescriptor()); CombinedStorageQueryTestTask<DefaultData> testTask = new CombinedStorageQueryTestTask<>(testResultList); StorageBranch<DefaultData> mockedBranch1 = mock(StorageBranch.class); when(mockedBranch1.getTaskForForkJoinQuery(storageIndexQuery)).thenReturn(testTask); StorageBranch<DefaultData> mockedBranch2 = mock(StorageBranch.class); when(mockedBranch2.getTaskForForkJoinQuery(storageIndexQuery)).thenReturn(testTask); ArrayList<IStorageTreeComponent<DefaultData>> branches = new ArrayList<>(); branches.add(mockedBranch1); branches.add(mockedBranch2); IStorageTreeComponent<DefaultData> rootCombinedStoreBranch = new CombinedStorageBranch<>(branches); List<IStorageDescriptor> results = rootCombinedStoreBranch.query(storageIndexQuery, forkJoinPool); assertThat(results.size(), is(equalTo(4))); } }