diff --git a/src/main/java/org/rometools/feed/module/sle/GroupStrategy.java b/src/main/java/org/rometools/feed/module/sle/GroupStrategy.java index f3eae59..4e966c1 100644 --- a/src/main/java/org/rometools/feed/module/sle/GroupStrategy.java +++ b/src/main/java/org/rometools/feed/module/sle/GroupStrategy.java @@ -9,18 +9,15 @@ import com.sun.syndication.feed.module.Extendable; class GroupStrategy implements ValueStrategy { @Override - public Comparable getValue(final Extendable o, final Object value) { - Comparable oc = null; + public EntryValue getValue(final Extendable extendable, final Object value) { try { final String uri = ModuleParser.TEMP.getURI(); - final SleEntry entry = (SleEntry) o.getModule(uri); + final SleEntry entry = (SleEntry) extendable.getModule(uri); final Group group = (Group) value; - final EntryValue entryValue = entry.getGroupByElement(group); - oc = entryValue.getValue(); + return entry.getGroupByElement(group); } catch (final NullPointerException npe) { - ; // watch it go by + return null; } - return oc; } } \ No newline at end of file diff --git a/src/main/java/org/rometools/feed/module/sle/SortStrategy.java b/src/main/java/org/rometools/feed/module/sle/SortStrategy.java index dee1fec..20d22e6 100644 --- a/src/main/java/org/rometools/feed/module/sle/SortStrategy.java +++ b/src/main/java/org/rometools/feed/module/sle/SortStrategy.java @@ -9,18 +9,15 @@ import com.sun.syndication.feed.module.Extendable; class SortStrategy implements ValueStrategy { @Override - public Comparable getValue(final Extendable o, final Object value) { - Comparable oc = null; + public EntryValue getValue(final Extendable extendable, final Object value) { try { final String uri = ModuleParser.TEMP.getURI(); - final SleEntry entry = (SleEntry) o.getModule(uri); + final SleEntry entry = (SleEntry) extendable.getModule(uri); final Sort sort = (Sort) value; - final EntryValue entryValue = entry.getSortByElement(sort); - oc = entryValue.getValue(); + return entry.getSortByElement(sort); } catch (final NullPointerException npe) { - ; // watch it go by + return null; } - return oc; } } \ No newline at end of file diff --git a/src/main/java/org/rometools/feed/module/sle/SortableList.java b/src/main/java/org/rometools/feed/module/sle/SortableList.java index fa585b8..123f2a9 100644 --- a/src/main/java/org/rometools/feed/module/sle/SortableList.java +++ b/src/main/java/org/rometools/feed/module/sle/SortableList.java @@ -3,6 +3,8 @@ package org.rometools.feed.module.sle; import java.util.ArrayList; import java.util.Collection; +import org.rometools.feed.module.sle.types.EntryValue; + import com.sun.syndication.feed.module.Extendable; class SortableList extends ArrayList { @@ -16,7 +18,7 @@ class SortableList extends ArrayList { /** * performs a selection sort on all the beans in the List */ - public synchronized void sortOnProperty(final Object value, final boolean ascending, final ValueStrategy strat) { + public synchronized void sortOnProperty(final Object value, final boolean ascending, final ValueStrategy strategy) { final int elementCount = size(); @@ -27,8 +29,8 @@ class SortableList extends ArrayList { final T entry1 = get(i); final T entry2 = get(j); - final Comparable oc1 = strat.getValue(entry1, value); - final Comparable oc2 = strat.getValue(entry2, value); + final EntryValue oc1 = strategy.getValue(entry1, value); + final EntryValue oc2 = strategy.getValue(entry2, value); if (oc1 != oc2) { final boolean bothNotNull = oc1 != null && oc2 != null; diff --git a/src/main/java/org/rometools/feed/module/sle/ValueStrategy.java b/src/main/java/org/rometools/feed/module/sle/ValueStrategy.java index 89c7dfa..ff7a484 100644 --- a/src/main/java/org/rometools/feed/module/sle/ValueStrategy.java +++ b/src/main/java/org/rometools/feed/module/sle/ValueStrategy.java @@ -1,9 +1,11 @@ package org.rometools.feed.module.sle; +import org.rometools.feed.module.sle.types.EntryValue; + import com.sun.syndication.feed.module.Extendable; interface ValueStrategy { - public Comparable getValue(Extendable o, Object valueName); + public EntryValue getValue(Extendable extendable, Object value); } \ No newline at end of file diff --git a/src/main/java/org/rometools/feed/module/sle/types/DateValue.java b/src/main/java/org/rometools/feed/module/sle/types/DateValue.java index 3966787..c243af2 100644 --- a/src/main/java/org/rometools/feed/module/sle/types/DateValue.java +++ b/src/main/java/org/rometools/feed/module/sle/types/DateValue.java @@ -28,67 +28,53 @@ import com.sun.syndication.feed.impl.ObjectBean; * * @author Robert "kebernet" Cooper */ -public class DateValue implements EntryValue { +public class DateValue implements EntryValue { private static final long serialVersionUID = 8864338943592633517L; private final ObjectBean obj = new ObjectBean(DateValue.class, this); - private Date value; + private String element; private String label; + private Date value; private Namespace namespace = Namespace.XML_NAMESPACE; - /** - * - * @param element - */ public void setElement(final String element) { this.element = element; } - /** - * - * @return - */ @Override public String getElement() { return element; } - /** - * - * @param label - */ public void setLabel(final String label) { this.label = label; } - /** - * - * @return - */ @Override public String getLabel() { return label; } - /** - * - * @param value - */ public void setValue(final Date value) { this.value = value; } - /** - * - * @return - */ @Override public Date getValue() { return value; } + @Override + public Namespace getNamespace() { + return namespace; + } + + public void setNamespace(final Namespace namespace) { + this.namespace = namespace == null ? Namespace.XML_NAMESPACE : namespace; + } + @Override public Object clone() { final DateValue clone = new DateValue(); @@ -115,11 +101,13 @@ public class DateValue implements EntryValue { } @Override - public Namespace getNamespace() { - return namespace; + public int compareTo(final EntryValue other) { + final Comparable otherValue = other.getValue(); + if (otherValue instanceof Date) { + return value.compareTo((Date) otherValue); + } else { + throw new RuntimeException("Can't compare different EntryValue types"); + } } - public void setNamespace(final Namespace namespace) { - this.namespace = namespace == null ? Namespace.XML_NAMESPACE : namespace; - } } diff --git a/src/main/java/org/rometools/feed/module/sle/types/EntryValue.java b/src/main/java/org/rometools/feed/module/sle/types/EntryValue.java index dbe6a33..8afd108 100644 --- a/src/main/java/org/rometools/feed/module/sle/types/EntryValue.java +++ b/src/main/java/org/rometools/feed/module/sle/types/EntryValue.java @@ -26,7 +26,7 @@ import org.jdom2.Namespace; * * @author Robert "kebernet" Cooper */ -public interface EntryValue> extends Serializable, Cloneable { +public interface EntryValue extends Serializable, Cloneable, Comparable { /** * Returns the name of the element. * @@ -46,7 +46,7 @@ public interface EntryValue> extends Serializable, Clone * * @return Returns the value of the element. */ - public T getValue(); + public Comparable getValue(); /** * Returns the namespace of the element. @@ -54,4 +54,5 @@ public interface EntryValue> extends Serializable, Clone * @return Returns the namespace of the element. */ public Namespace getNamespace(); + } diff --git a/src/main/java/org/rometools/feed/module/sle/types/NumberValue.java b/src/main/java/org/rometools/feed/module/sle/types/NumberValue.java index 78a6aad..5f12f83 100644 --- a/src/main/java/org/rometools/feed/module/sle/types/NumberValue.java +++ b/src/main/java/org/rometools/feed/module/sle/types/NumberValue.java @@ -28,14 +28,15 @@ import com.sun.syndication.feed.impl.ObjectBean; * * @author Robert "kebernet" Cooper */ -public class NumberValue implements EntryValue { +public class NumberValue implements EntryValue { private static final long serialVersionUID = 8043418996659222922L; private final ObjectBean obj = new ObjectBean(NumberValue.class, this); - private BigDecimal value; + private String element; private String label; + private BigDecimal value; private Namespace namespace = Namespace.XML_NAMESPACE; public void setElement(final String element) { @@ -65,6 +66,15 @@ public class NumberValue implements EntryValue { return value; } + @Override + public Namespace getNamespace() { + return namespace; + } + + public void setNamespace(final Namespace namespace) { + this.namespace = namespace == null ? Namespace.XML_NAMESPACE : namespace; + } + @Override public Object clone() { final NumberValue clone = new NumberValue(); @@ -72,7 +82,6 @@ public class NumberValue implements EntryValue { clone.setLabel(getLabel()); clone.setValue(value); clone.setNamespace(namespace); - return clone; } @@ -92,11 +101,13 @@ public class NumberValue implements EntryValue { } @Override - public Namespace getNamespace() { - return namespace; + public int compareTo(final EntryValue other) { + final Comparable otherValue = other.getValue(); + if (otherValue instanceof BigDecimal) { + return value.compareTo((BigDecimal) otherValue); + } else { + throw new RuntimeException("Can't compare different EntryValue types"); + } } - public void setNamespace(final Namespace namespace) { - this.namespace = namespace == null ? Namespace.XML_NAMESPACE : namespace; - } } diff --git a/src/main/java/org/rometools/feed/module/sle/types/StringValue.java b/src/main/java/org/rometools/feed/module/sle/types/StringValue.java index 8582868..2db8cf2 100644 --- a/src/main/java/org/rometools/feed/module/sle/types/StringValue.java +++ b/src/main/java/org/rometools/feed/module/sle/types/StringValue.java @@ -26,18 +26,19 @@ import com.sun.syndication.feed.impl.ObjectBean; * * @author Robert "kebernet" Cooper */ -public class StringValue implements EntryValue { +public class StringValue implements EntryValue { private static final long serialVersionUID = -8384073300710802173L; private final ObjectBean obj = new ObjectBean(StringValue.class, this); + private String element; private String label; private String value; private Namespace namespace = Namespace.XML_NAMESPACE; - public void setElement(final String element) { - this.element = element; + public void setValue(final String value) { + this.value = value; } @Override @@ -54,15 +55,24 @@ public class StringValue implements EntryValue { return label; } - public void setValue(final String value) { - this.value = value; - } - @Override public String getValue() { return value; } + public void setElement(final String element) { + this.element = element; + } + + @Override + public Namespace getNamespace() { + return namespace; + } + + public void setNamespace(final Namespace namespace) { + this.namespace = namespace == null ? Namespace.XML_NAMESPACE : namespace; + } + @Override public Object clone() { final StringValue clone = new StringValue(); @@ -70,7 +80,6 @@ public class StringValue implements EntryValue { clone.setLabel(getLabel()); clone.setValue(value); clone.setNamespace(namespace); - return clone; } @@ -90,11 +99,13 @@ public class StringValue implements EntryValue { } @Override - public Namespace getNamespace() { - return namespace; + public int compareTo(final EntryValue other) { + final Comparable otherValue = other.getValue(); + if (otherValue instanceof String) { + return value.compareTo((String) otherValue); + } else { + throw new RuntimeException("Can't compare different EntryValue types"); + } } - public void setNamespace(final Namespace namespace) { - this.namespace = namespace == null ? Namespace.XML_NAMESPACE : namespace; - } }