Пример #1
0
 public void index(Record record) {
   final Long recordId = record.getId();
   if (record.isActive()) {
     final Record anotherRecord = records.putIfAbsent(recordId, record);
     if (anotherRecord != null) {
       record = anotherRecord;
     } else {
       size.incrementAndGet();
     }
   } else {
     remove(record);
   }
   if (indexValue != null) {
     Long newValueIndex = -1L;
     if (record.isActive() && record.hasValueData()) {
       newValueIndex = (long) record.getValueData().hashCode();
     }
     indexValue.index(newValueIndex, record);
   }
   Long[] indexValues = record.getIndexes();
   if (indexValues != null && hasIndexedAttributes) {
     byte[] indexTypes = record.getIndexTypes();
     if (indexTypes == null || indexValues.length != indexTypes.length) {
       throw new IllegalArgumentException(
           "index and types don't match " + Arrays.toString(indexTypes));
     }
     Collection<Index> indexes = mapIndexes.values();
     for (Index index : indexes) {
       if (indexValues.length > index.getAttributeIndex()) {
         Long newValue = indexValues[index.getAttributeIndex()];
         index.index(newValue, record);
       }
     }
   }
 }
Пример #2
0
 public Long[] getIndexValues(Object value) {
   if (hasIndexedAttributes) {
     int indexCount = mapIndexes.size();
     Long[] newIndexes = new Long[indexCount];
     if (value instanceof Data) {
       value = toObject((Data) value);
     }
     Collection<Index> indexes = mapIndexes.values();
     for (Index index : indexes) {
       int attributedIndex = index.getAttributeIndex();
       newIndexes[attributedIndex] = index.extractLongValue(value);
     }
     byte[] _indexTypes = indexTypes;
     if (_indexTypes == null || _indexTypes.length != indexCount) {
       synchronized (indexTypesLock) {
         _indexTypes = indexTypes;
         if (_indexTypes == null || _indexTypes.length != indexCount) {
           _indexTypes = new byte[indexCount];
           for (Index index : indexes) {
             int attributedIndex = index.getAttributeIndex();
             _indexTypes[attributedIndex] = index.getIndexType();
           }
           indexTypes = _indexTypes;
         }
       }
     }
     return newIndexes;
   }
   return null;
 }
Пример #3
0
 public Index[] getIndexesInOrder() {
   if (mapIndexes.size() == 0) return null;
   Index[] indexes = new Index[mapIndexes.size()];
   for (Index index : mapIndexes.values()) {
     indexes[index.getAttributeIndex()] = index;
   }
   return indexes;
 }