diff --git a/src/main/java/org/rometools/feed/module/sle/SimpleListExtensionImpl.java b/src/main/java/org/rometools/feed/module/sle/SimpleListExtensionImpl.java
index 301739c..63bb4f5 100644
--- a/src/main/java/org/rometools/feed/module/sle/SimpleListExtensionImpl.java
+++ b/src/main/java/org/rometools/feed/module/sle/SimpleListExtensionImpl.java
@@ -28,10 +28,9 @@ import com.sun.syndication.feed.module.ModuleImpl;
* @author Robert "kebernet" Cooper
*/
public class SimpleListExtensionImpl extends ModuleImpl implements SimpleListExtension {
- /**
- *
- */
+
private static final long serialVersionUID = 1L;
+
private String treatAs = "list";
private Group[] groupFields;
private Sort[] sortFields;
@@ -114,4 +113,5 @@ public class SimpleListExtensionImpl extends ModuleImpl implements SimpleListExt
setSortFields(sle.getSortFields().clone());
setTreatAs(sle.getTreatAs());
}
+
}
diff --git a/src/main/java/org/rometools/feed/module/sle/SleEntryImpl.java b/src/main/java/org/rometools/feed/module/sle/SleEntryImpl.java
index 002d5fe..6fe5480 100644
--- a/src/main/java/org/rometools/feed/module/sle/SleEntryImpl.java
+++ b/src/main/java/org/rometools/feed/module/sle/SleEntryImpl.java
@@ -27,8 +27,9 @@ import com.sun.syndication.feed.CopyFrom;
import com.sun.syndication.feed.impl.ObjectBean;
/**
- * This is a parse only module that holds the values of enternal fields declared in the SLE module. These will not be persisted on an output()
- * call, nor will changing a value here change a value in another module or a foreign markup tag.
+ * This is a parse only module that holds the values of enternal fields declared in the SLE
+ * module. These will not be persisted on an output() call, nor will changing a value
+ * here change a value in another module or a foreign markup tag.
*
* @author Robert "kebernet" Cooper
*/
@@ -72,13 +73,14 @@ public class SleEntryImpl implements SleEntry {
/**
* Returns the interface the copyFrom works on.
*
- * This is useful when dealing with properties that may have multiple implementations. For example, Module.
+ * This is useful when dealing with properties that may have multiple implementations. For
+ * example, Module.
*
*
* @return the interface the copyFrom works on.
*/
@Override
- public Class getInterface() {
+ public Class getInterface() {
return SleEntry.class;
}
@@ -128,8 +130,8 @@ public class SleEntryImpl implements SleEntry {
*
* Any existing properties in this bean are lost.
*
- * This method is useful for moving from one implementation of a bean interface to another. For example from the default SyndFeed bean implementation to a
- * Hibernate ready implementation.
+ * This method is useful for moving from one implementation of a bean interface to another. For
+ * example from the default SyndFeed bean implementation to a Hibernate ready implementation.
*
*
* @param obj the instance to copy properties from.
diff --git a/src/main/java/org/rometools/feed/module/sle/SleUtility.java b/src/main/java/org/rometools/feed/module/sle/SleUtility.java
index 0d71a79..b92ac6f 100644
--- a/src/main/java/org/rometools/feed/module/sle/SleUtility.java
+++ b/src/main/java/org/rometools/feed/module/sle/SleUtility.java
@@ -74,7 +74,12 @@ public final class SleUtility {
* @return Sorted list of values
*/
public static List sort(final List values, final Sort sort, final boolean ascending) {
- final SortableList list = values instanceof SortableList ? (SortableList) values : new SortableList(values);
+ final SortableList list;
+ if (values instanceof SortableList) {
+ list = (SortableList) values;
+ } else {
+ list = new SortableList(values);
+ }
list.sortOnProperty(sort, ascending, new SortStrategy());
return list;
}
@@ -104,10 +109,10 @@ public final class SleUtility {
// TODO: the null parameter below will break delegating parsers and generators
// final ModuleGenerators g = new ModuleGenerators(feed.getFeedType() +
// ITEM_MODULE_GENERATORS_POSFIX_KEY, null);
- final SyndFeedOutput o = new SyndFeedOutput();
- final Document d = o.outputJDom(feed);
- final SyndFeed feed2 = new SyndFeedInput().build(d);
- feed.copyFrom(feed2);
+ final SyndFeedOutput output = new SyndFeedOutput();
+ final Document document = output.outputJDom(feed);
+ final SyndFeed copy = new SyndFeedInput().build(document);
+ feed.copyFrom(copy);
}
}
diff --git a/src/test/java/org/rometools/feed/module/sle/GroupAndSortTest.java b/src/test/java/org/rometools/feed/module/sle/GroupAndSortTest.java
index e9a3a6e..e215175 100644
--- a/src/test/java/org/rometools/feed/module/sle/GroupAndSortTest.java
+++ b/src/test/java/org/rometools/feed/module/sle/GroupAndSortTest.java
@@ -1,10 +1,3 @@
-/*
- * GroupAndSortTest.java
- * JUnit based test
- *
- * Created on April 29, 2006, 8:56 PM
- */
-
package org.rometools.feed.module.sle;
import java.io.File;
@@ -33,63 +26,52 @@ public class GroupAndSortTest extends AbstractTestCase {
}
public static Test suite() {
- final TestSuite suite = new TestSuite(GroupAndSortTest.class);
-
- return suite;
+ return new TestSuite(GroupAndSortTest.class);
}
/**
* Test of sort method, of class com.sun.syndication.feed.module.sle.GroupAndSort.
*/
public void testSort() throws Exception {
- final SyndFeedInput input = new SyndFeedInput();
- final SyndFeed feed = input.build(new File(super.getTestFile("data/bookexample.xml")));
- final SimpleListExtension sle = (SimpleListExtension) feed.getModule(SimpleListExtension.URI);
- final List entries = new ArrayList(feed.getEntries());
+ final File testdata = new File(super.getTestFile("data/bookexample.xml"));
+ final SyndFeed feed = new SyndFeedInput().build(testdata);
+
+ final List feedEntries = feed.getEntries();
+ final List entries = new ArrayList(feedEntries);
+
+ final SimpleListExtension sle = (SimpleListExtension) feed.getModule(SimpleListExtension.URI);
final Sort[] sortFields = sle.getSortFields();
- final Sort sort = sortFields[1];
- List sortedEntries = SleUtility.sort(entries, sort, true);
+
+ final Sort sortByDate = sortFields[1];
+ final Sort sortByTitle = sortFields[2];
+
+ // sort by date ascending
+ List sortedEntries = SleUtility.sort(entries, sortByDate, true);
SyndEntry entry = (SyndEntry) sortedEntries.get(0);
assertEquals("Great Journeys of the Past", entry.getTitle());
- sortedEntries = SleUtility.sort(entries, sort, false);
+
+ // sort by date descending
+ sortedEntries = SleUtility.sort(entries, sortByDate, false);
entry = (SyndEntry) sortedEntries.get(0);
assertEquals("Horror Stories, vol 16", entry.getTitle());
- sortedEntries = SleUtility.sort(entries, sort, true);
- entry = (SyndEntry) sortedEntries.get(0);
+ // sort by date ascending
+ sortedEntries = SleUtility.sort(entries, sortByDate, true);
+ // update first entry and reinitialize
+ entry = (SyndEntry) sortedEntries.get(0);
entry.setTitle("ZZZZZ");
SleUtility.initializeForSorting(feed);
- System.out.println(entries.size() + " **Sorting on " + sortFields[2]);
- sortedEntries = SleUtility.sort(entries, sortFields[2], false);
- System.out.println("Sorted: " + sortedEntries.size());
- for (int i = 0; i < sortedEntries.size(); i++) {
- entry = (SyndEntry) sortedEntries.get(i);
- System.out.println(i + " -- " + entry.getTitle());
- final SleEntry slent = (SleEntry) entry.getModule(SleEntry.URI);
- for (int j = 0; j < slent.getSortValues().length; j++) {
- System.out.println(slent.getSortValues()[j].getElement() + " == " + slent.getSortValues()[j].getValue());
- }
-
- }
+ // sort by title desc
+ sortedEntries = SleUtility.sort(entries, sortByTitle, false);
entry = (SyndEntry) sortedEntries.get(0);
- System.out.println(entry.getTitle());
assertEquals("ZZZZZ", entry.getTitle());
- entry = (SyndEntry) sortedEntries.get(1);
- System.out.println(entry.getTitle());
- sortedEntries = SleUtility.sort(entries, sortFields[2], true);
+ // sort by title asc
+ sortedEntries = SleUtility.sort(entries, sortByTitle, true);
entry = (SyndEntry) sortedEntries.get(0);
- System.out.println(entry.getTitle());
- assertEquals("Horror Stories, vol 16", entry.getTitle());
- entry = (SyndEntry) sortedEntries.get(1);
- System.out.println(entry.getTitle());
-
- sortedEntries = SleUtility.sortAndGroup(entries, sle.getGroupFields(), sortFields[2], true);
- entry = (SyndEntry) sortedEntries.get(0);
- System.out.println(entry.getTitle());
assertEquals("Horror Stories, vol 16", entry.getTitle());
}
@@ -98,16 +80,18 @@ public class GroupAndSortTest extends AbstractTestCase {
* Test of sort method, of class com.sun.syndication.feed.module.sle.GroupAndSort.
*/
public void testSort2() throws Exception {
+
final SyndFeedInput input = new SyndFeedInput();
final SyndFeed feed = input.build(new File(super.getTestFile("data/YahooTopSongs.xml")));
final SimpleListExtension sle = (SimpleListExtension) feed.getModule(SimpleListExtension.URI);
- System.out.println("Sorting on " + sle.getSortFields()[0]);
+
final List entries = new ArrayList(feed.getEntries());
final List sortedEntries = SleUtility.sort(entries, sle.getSortFields()[0], true);
for (int i = 0; i < sortedEntries.size(); i++) {
final SyndEntry entry = (SyndEntry) sortedEntries.get(i);
System.out.println(entry.getTitle());
}
+
}
/**
@@ -120,8 +104,23 @@ public class GroupAndSortTest extends AbstractTestCase {
/**
* Test of sortAndGroup method, of class com.sun.syndication.feed.module.sle.GroupAndSort.
*/
- public void testSortAndGroup() {
- // TODO add your test code.
+ public void testSortAndGroup() throws Exception {
+
+ final File testdata = new File(super.getTestFile("data/bookexample.xml"));
+ final SyndFeed feed = new SyndFeedInput().build(testdata);
+
+ final List feedEntries = feed.getEntries();
+ final List entries = new ArrayList(feedEntries);
+
+ final SimpleListExtension sle = (SimpleListExtension) feed.getModule(SimpleListExtension.URI);
+ final Sort[] sortFields = sle.getSortFields();
+
+ final Sort sortByTitle = sortFields[2];
+
+ final List sortedEntries = SleUtility.sortAndGroup(entries, sle.getGroupFields(), sortByTitle, true);
+ final SyndEntry entry = (SyndEntry) sortedEntries.get(0);
+ assertEquals("Horror Stories, vol 16", entry.getTitle());
+
}
}