Пример #1
0
 /**
  * Translates a feature pointed by a node from its original feature type to a given one, using
  * values from those attributes that exist in both original and destination feature type. New
  * attributes are populated with null values
  *
  * @param node The node that points to the feature. No checking is performed to ensure the node
  *     points to a feature instead of other type
  * @param featureType the destination feature type
  * @return a feature with the passed feature type and data taken from the input feature
  */
 private Feature alter(NodeRef node, RevFeatureType featureType) {
   RevFeature oldFeature =
       command(RevObjectParse.class).setObjectId(node.objectId()).call(RevFeature.class).get();
   RevFeatureType oldFeatureType;
   oldFeatureType =
       command(RevObjectParse.class)
           .setObjectId(node.getMetadataId())
           .call(RevFeatureType.class)
           .get();
   ImmutableList<PropertyDescriptor> oldAttributes = oldFeatureType.sortedDescriptors();
   ImmutableList<PropertyDescriptor> newAttributes = featureType.sortedDescriptors();
   ImmutableList<Optional<Object>> oldValues = oldFeature.getValues();
   List<Optional<Object>> newValues = Lists.newArrayList();
   for (int i = 0; i < newAttributes.size(); i++) {
     int idx = oldAttributes.indexOf(newAttributes.get(i));
     if (idx != -1) {
       Optional<Object> oldValue = oldValues.get(idx);
       newValues.add(oldValue);
     } else {
       newValues.add(Optional.absent());
     }
   }
   RevFeature newFeature = RevFeature.build(ImmutableList.copyOf(newValues));
   FeatureBuilder featureBuilder = new FeatureBuilder(featureType);
   Feature feature = featureBuilder.build(node.name(), newFeature);
   return feature;
 }
Пример #2
0
 /**
  * Tests equality over another {@code NodeRef} based on {@link #getParentPath() parent path},
  * {@link #getNode() node} name and id, and {@link #getMetadataId()}
  */
 @Override
 public boolean equals(Object o) {
   if (!(o instanceof NodeRef)) {
     return false;
   }
   NodeRef r = (NodeRef) o;
   return parentPath.equals(r.parentPath)
       && node.equals(r.node)
       && getMetadataId().equals(r.getMetadataId());
 }