package ecologylab.bigsemantics.metametadata.fieldops;

import java.util.HashMap;

import ecologylab.net.ParsedURL;
import ecologylab.serialization.annotations.simpl_scalar;

/**
 * 
 * @author quyin
 */
public class SetParam implements FieldOp
{

  @simpl_scalar
  private String  name;

  @simpl_scalar
  private String  value;

  @simpl_scalar
  private boolean onlyWhenNotSet;

  public String getName()
  {
    return name;
  }

  public void setName(String name)
  {
    this.name = name;
  }

  public String getValue()
  {
    return value;
  }

  public void setValue(String value)
  {
    this.value = value;
  }

  @Override
  public Object operateOn(Object rawValue)
  {
    if (rawValue != null && name != null && value != null)
    {
      ParsedURL purl = (rawValue instanceof ParsedURL)
          ? ((ParsedURL) rawValue)
          : ParsedURL.getAbsolute(rawValue.toString());
      HashMap<String, String> params = purl.extractParams(true);
      if (!onlyWhenNotSet || !params.containsKey(name))
      {
        params.put(name, value);
      }
      return purl.updateParams(params);
    }
    return rawValue;
  }

}

@@ -174,17 +174,16 @@
 %0A%0A/**%0A *
- 
 %0A * @aut
@@ -947,24 +947,90 @@
 rams(true);%0A
+      if (params == null) params = new HashMap%3CString, String%3E();%0A
       if (!o

fix npe