You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by el...@apache.org on 2013/10/04 00:04:54 UTC
svn commit: r1529020 - in /lucene/dev/branches/branch_4x: ./ solr/ solr/core/
solr/core/src/java/org/apache/solr/update/processor/FieldMutatingUpdateProcessorFactory.java
solr/solrj/ solr/solrj/src/java/org/apache/solr/common/util/NamedList.java
Author: elyograg
Date: Thu Oct 3 22:04:54 2013
New Revision: 1529020
URL: http://svn.apache.org/r1529020
Log:
SOLR-5264: merge trunk r1528976, move getBooleanArg to NamedList#removeBooleanArg
Modified:
lucene/dev/branches/branch_4x/ (props changed)
lucene/dev/branches/branch_4x/solr/ (props changed)
lucene/dev/branches/branch_4x/solr/core/ (props changed)
lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/update/processor/FieldMutatingUpdateProcessorFactory.java
lucene/dev/branches/branch_4x/solr/solrj/ (props changed)
lucene/dev/branches/branch_4x/solr/solrj/src/java/org/apache/solr/common/util/NamedList.java
Modified: lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/update/processor/FieldMutatingUpdateProcessorFactory.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/update/processor/FieldMutatingUpdateProcessorFactory.java?rev=1529020&r1=1529019&r2=1529020&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/update/processor/FieldMutatingUpdateProcessorFactory.java (original)
+++ lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/update/processor/FieldMutatingUpdateProcessorFactory.java Thu Oct 3 22:04:54 2013
@@ -160,8 +160,8 @@ public abstract class FieldMutatingUpdat
// resolve this into actual Class objects later
params.typeClass = args.removeConfigArgs("typeClass");
- // getBooleanArg() returns null if the arg is not specified
- params.fieldNameMatchesSchemaField = getBooleanArg(args, "fieldNameMatchesSchemaField");
+ // Returns null if the arg is not specified
+ params.fieldNameMatchesSchemaField = args.removeBooleanArg("fieldNameMatchesSchemaField");
return params;
}
@@ -288,7 +288,10 @@ public abstract class FieldMutatingUpdat
* Removes the first instance of the key from NamedList, returning the Boolean
* that key referred to, or null if the key is not specified.
* @exception SolrException invalid type or structure
+ * @deprecated Use {@link NamedList#removeBooleanArg} instead. Will be
+ * removed in 5.0.
*/
+ @Deprecated
public static Boolean getBooleanArg(final NamedList args, final String key) {
Boolean bool;
List values = args.getAll(key);
Modified: lucene/dev/branches/branch_4x/solr/solrj/src/java/org/apache/solr/common/util/NamedList.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/solrj/src/java/org/apache/solr/common/util/NamedList.java?rev=1529020&r1=1529019&r2=1529020&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/solrj/src/java/org/apache/solr/common/util/NamedList.java (original)
+++ lucene/dev/branches/branch_4x/solr/solrj/src/java/org/apache/solr/common/util/NamedList.java Thu Oct 3 22:04:54 2013
@@ -494,7 +494,8 @@ public class NamedList<T> implements Clo
* Removes and returns all values for the specified name. Returns null if
* no matches found. This method will return all matching objects,
* regardless of data type. If you are parsing Solr config options, the
- * {@link #removeConfigArgs(String)} method will probably work better.
+ * {@link #removeConfigArgs(String)} or {@link #removeBooleanArg(String)}
+ * methods will probably work better.
*
* @param name Name
* @return List of values
@@ -510,6 +511,46 @@ public class NamedList<T> implements Clo
}
/**
+ * Used for getting a boolean argument from a NamedList object. If the name
+ * is not present, returns null. If there is more than one value with that
+ * name, or if the value found is not a Boolean or a String, throws an
+ * exception. If there is only one value present and it is a Boolean or a
+ * String, the value is removed and returned as a Boolean. If an exception
+ * is thrown, the NamedList is not modified. See {@link #removeAll(String)}
+ * and {@link #removeConfigArgs(String)} for additional ways of gathering
+ * configuration information from a NamedList.
+ *
+ * @param name
+ * The key to look up in the NamedList.
+ * @return The boolean value found.
+ * @throws SolrException
+ * If multiple values are found for the name or the value found is
+ * not a Boolean or a String.
+ */
+ public Boolean removeBooleanArg(final String name) {
+ Boolean bool;
+ List<T> values = getAll(name);
+ if (0 == values.size()) {
+ return null;
+ }
+ if (values.size() > 1) {
+ throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,
+ "Only one '" + name + "' is allowed");
+ }
+ Object o = get(name);
+ if (o instanceof Boolean) {
+ bool = (Boolean)o;
+ } else if (o instanceof CharSequence) {
+ bool = Boolean.parseBoolean(o.toString());
+ } else {
+ throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,
+ "'" + name + "' must have type 'bool' or 'str'; found " + o.getClass());
+ }
+ remove(name);
+ return bool;
+ }
+
+ /**
* Used for getting one or many arguments from NamedList objects that hold
* configuration parameters. Finds all entries in the NamedList that match
* the given name. If they are all strings or arrays of strings, remove them
@@ -520,6 +561,8 @@ public class NamedList<T> implements Clo
* thrown, the NamedList is not modified. Returns an empty collection if no
* matches found. If you need to remove and retrieve all matching items from
* the NamedList regardless of data type, use {@link #removeAll(String)} instead.
+ * The {@link #removeBooleanArg(String)} method can be used for retrieving a
+ * boolean argument.
*
* @param name
* The key to look up in the NamedList.