Author: ssmiweve
Date: 2009-07-14 11:42:56 +0200 (Tue, 14 Jul 2009)
New Revision: 7233
Modified:
branches/2.18/result-spi/src/main/java/no/sesat/search/result/BasicResultItem.java
Log:
> debug: with assertions enabled you get to see which field is causing any
> ClassCastException
strengthen these assertions some.
make getInteger and getMultivaluedField methods able to return string values as
either parsed int or Collections.<String>singletonList(..) respectively.
Modified:
branches/2.18/result-spi/src/main/java/no/sesat/search/result/BasicResultItem.java
===================================================================
---
branches/2.18/result-spi/src/main/java/no/sesat/search/result/BasicResultItem.java
2009-07-14 09:10:04 UTC (rev 7232)
+++
branches/2.18/result-spi/src/main/java/no/sesat/search/result/BasicResultItem.java
2009-07-14 09:42:56 UTC (rev 7233)
@@ -89,7 +89,10 @@
*/
public String getField(final String field) {
- assert fields.get(field) instanceof String : field + " is not a
String. Use instead getObjectField";
+ assert null == fields.get(field) || fields.get(field) instanceof String
+ : field + " is not a String. It is a "
+ + (null != fields.get(field) ?
fields.get(field).getClass().getSimpleName() : "null");
+
final String fieldValue = (String) fields.get(field);
return fieldValue != null && fieldValue.trim().length() > 0 ?
fieldValue : null;
}
@@ -131,9 +134,15 @@
*/
public Integer getInteger(final String field) {
- assert fields.get(field) instanceof Integer : field + " is not a
Integer. Use instead getObjectField?";
- final String fieldValue = (String) fields.get(field);
- return null != fieldValue ? Integer.parseInt(fieldValue) : null;
+ assert null == fields.get(field) || fields.get(field) instanceof
Integer || fields.get(field) instanceof String
+ : field + " is not a Integer (or String). It is a "
+ + (null != fields.get(field) ?
fields.get(field).getClass().getSimpleName() : "null");
+
+ return null != fields.get(field)
+ ? fields.get(field) instanceof Integer
+ ? (Integer)fields.get(field)
+ : Integer.parseInt((String) fields.get(field))
+ : null;
}
/**
@@ -144,7 +153,10 @@
*/
public String getField(final String field, final int maxLength) {
- assert fields.get(field) instanceof String : field + " is not a
String. Use instead getObjectField?";
+ assert null == fields.get(field) || fields.get(field) instanceof String
+ : field + " is not a String. It is a "
+ + (null != fields.get(field) ?
fields.get(field).getClass().getSimpleName() : "null");
+
final String fieldValue = (String) fields.get(field);
return fieldValue != null && fieldValue.trim().length() > 0
@@ -163,13 +175,20 @@
/** Returns a live copy of the field's collection.
*
+ * If field is of String type, it is wrapped in a collection as a single
entry.
+ *
* @param field
* @return
*/
public Collection<String> getMultivaluedField(final String field) {
- assert fields.get(field) instanceof Collection : field + " is not a
Collection. Use instead getObjectField?";
- return (Collection<String>) fields.get(field);
+ assert null == fields.get(field) || fields.get(field) instanceof
Collection || fields.get(field) instanceof String
+ : field + " is not a Collection (or String). It is a "
+ + (null != fields.get(field) ?
fields.get(field).getClass().getSimpleName() : "null");
+
+ return fields.get(field) instanceof Collection
+ ? (Collection<String>) fields.get(field)
+ : Collections.singletonList((String)fields.get(field));
}
/**
@@ -196,7 +215,6 @@
if( obj instanceof ResultItem ){
final ResultItem other = (ResultItem) obj;
- // FIXME very specific undocumented stuff here
if (other.getField("recordid") != null && getField("recordid") !=
null) {
result =
getField("recordid").equals(other.getField("recordid"));
}else{
_______________________________________________
Kernel-commits mailing list
[email protected]
http://sesat.no/mailman/listinfo/kernel-commits