use of com.google.storage.onestore.v3.OnestoreEntity.Index in project appengine-java-standard by GoogleCloudPlatform.
the class EntityStorageConversions method restoreStashedProperties.
/**
* Moves stashed properties back from raw properties to properties.
*
* <p>Note: this piece of code assumes that stashed properties appear in the raw property list in
* stashed index order.
*
* @param storageEntity The EntityProto to modify.
*/
static void restoreStashedProperties(EntityProto storageEntity) {
ImmutableList<Property> properties = ImmutableList.copyOf(storageEntity.propertys());
ImmutableList<Property> rawProperties = ImmutableList.copyOf(storageEntity.rawPropertys());
ImmutableList.Builder<Property> badlyStashedProperties = ImmutableList.builder();
int propertyListIndex = 0;
storageEntity.clearProperty();
storageEntity.clearRawProperty();
for (Property rawProperty : rawProperties) {
if (rawProperty.hasStashed()) {
int stashed = rawProperty.getStashed();
int advance = stashed - storageEntity.propertySize();
if (// Not at the end (out-of-order, duplicate)
stashed < storageEntity.propertySize() || propertyListIndex + advance > properties.size()) {
// Past the end
// The value of stashed is bad.
badlyStashedProperties.add(rawProperty.clearStashed());
} else {
// Copy until before the position where the stashed property needs to be restored.
if (advance > 0) {
storageEntity.mutablePropertys().addAll(properties.subList(propertyListIndex, propertyListIndex + advance));
propertyListIndex = propertyListIndex + advance;
}
storageEntity.addProperty(rawProperty.clearStashed());
}
} else {
storageEntity.addRawProperty(rawProperty);
}
}
storageEntity.mutablePropertys().addAll(properties.subList(propertyListIndex, properties.size()));
storageEntity.mutablePropertys().addAll(badlyStashedProperties.build());
}
Aggregations