Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[hk] validatation of constructor args #10

Merged
merged 1 commit into from
May 16, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import org.locationtech.udig.project.command.provider.EditFeatureProvider;
import org.locationtech.udig.project.command.provider.EditLayerProvider;
import org.locationtech.udig.project.internal.Messages;

import org.apache.commons.lang.Validate;
import org.eclipse.core.runtime.IProgressMonitor;
import org.geotools.data.FeatureStore;
import org.geotools.factory.CommonFactoryFinder;
Expand All @@ -34,7 +34,7 @@

/**
* This command modifies an attribute of the current editFeature(the victim that is currently
* edittable).
* editable).
*
* @author jeichar
* @since 0.3
Expand All @@ -53,31 +53,38 @@ public class SetAttributesCommand extends AbstractEditCommand implements Undoabl
* Creates a new instance of SetAttributeCommand.
*
* @param feature the feature to modify
* @param layer to ask for object
* @param xpath the xpath that identifies an attribute in the current edit feature.
* @param value the value that will replace the old attribute value.
*/
public SetAttributesCommand( IBlockingProvider<SimpleFeature> feature, IBlockingProvider<ILayer> layer, String xpath[],
Object value[] ) {
public SetAttributesCommand(IBlockingProvider<SimpleFeature> feature,
IBlockingProvider<ILayer> layer, String xpath[], Object value[]) {
Validate.notNull(xpath);
Validate.notNull(value);
Validate.isTrue(xpath.length == value.length, "xpath and values do not have same lenght");
this.xpath = xpath;
this.value = value;
this.oldValue = new Object[value.length];
this.oldValue = new Object[xpath.length];
editFeature = feature;
editLayer = layer;
}

/**
* Creates a new instance of SetAttributeCommand.
*
* @param feature the feature to modify
* @param xpath the xpath that identifies an attribute in the current edit feature.
* @param value the value that will replace the old attribute value.
*/
public SetAttributesCommand( String xpath[], Object value[] ) {
editFeature=new EditFeatureProvider(this);
editLayer=new EditLayerProvider(this);
this.oldValue = new Object[value.length];
this.xpath=xpath;
this.value=value;
public SetAttributesCommand(String xpath[], Object value[]) {
Validate.notNull(xpath);
Validate.notNull(value);
Validate.isTrue(xpath.length == value.length, "xpath and values do not have same lenght");
editFeature = new EditFeatureProvider(this);
editLayer = new EditLayerProvider(this);
this.oldValue = new Object[xpath.length];
this.xpath = xpath;
this.value = value;
}

/**
Expand Down Expand Up @@ -138,8 +145,7 @@ public void rollback( IProgressMonitor monitor ) throws Exception {
AttributeDescriptor[] array = attributeList.toArray( new AttributeDescriptor[attributeList.size()]);

FilterFactory filterFactory = CommonFactoryFinder.getFilterFactory(GeoTools.getDefaultHints());
Id id = filterFactory.id(
FeatureUtils.stringToId(filterFactory, feature.getID()));
Id id = filterFactory.id(FeatureUtils.stringToId(filterFactory, feature.getID()));
resource.modifyFeatures(array, oldValue, id);
}

Expand All @@ -148,7 +154,7 @@ public void rollback( IProgressMonitor monitor ) throws Exception {
*/
public String getName() {
return MessageFormat.format(
Messages.SetAttributeCommand_setFeatureAttribute, new Object[]{xpath});
Messages.SetAttributeCommand_setFeatureAttribute, new Object[]{xpath});
}

@Override
Expand Down