You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2017/05/15 10:00:11 UTC
[3/3] camel git commit: CAMEL-11220: camel-twitter - allow to sort
tweets by id so oldest is before newest.
CAMEL-11220: camel-twitter - allow to sort tweets by id so oldest is before newest.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/f2cfc358
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/f2cfc358
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/f2cfc358
Branch: refs/heads/master
Commit: f2cfc35822cadd5dc0a86713b3a059d8bc34badd
Parents: e3c42ab
Author: Claus Ibsen <da...@apache.org>
Authored: Mon May 15 11:55:07 2017 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Mon May 15 11:57:16 2017 +0200
----------------------------------------------------------------------
.../twitter/consumer/TwitterConsumerPolling.java | 9 ---------
.../component/twitter/consumer/TwitterEventType.java | 5 +++++
.../camel/component/twitter/util/TwitterSorter.java | 11 ++++++++---
3 files changed, 13 insertions(+), 12 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/f2cfc358/components/camel-twitter/src/main/java/org/apache/camel/component/twitter/consumer/TwitterConsumerPolling.java
----------------------------------------------------------------------
diff --git a/components/camel-twitter/src/main/java/org/apache/camel/component/twitter/consumer/TwitterConsumerPolling.java b/components/camel-twitter/src/main/java/org/apache/camel/component/twitter/consumer/TwitterConsumerPolling.java
index a088c92..368d6ef 100644
--- a/components/camel-twitter/src/main/java/org/apache/camel/component/twitter/consumer/TwitterConsumerPolling.java
+++ b/components/camel-twitter/src/main/java/org/apache/camel/component/twitter/consumer/TwitterConsumerPolling.java
@@ -65,8 +65,6 @@ public class TwitterConsumerPolling extends ScheduledPollConsumer {
protected int poll() throws Exception {
List<Exchange> exchanges = twitter4jConsumer.pollConsume();
- exchanges = sort(exchanges);
-
int index = 0;
for (; index < exchanges.size(); index++) {
getProcessor().process(exchanges.get(index));
@@ -75,11 +73,4 @@ public class TwitterConsumerPolling extends ScheduledPollConsumer {
return index;
}
- protected List<Exchange> sort(List<Exchange> exchanges) {
- if (getEndpoint().isSortById()) {
- return TwitterSorter.sortBySinceId(exchanges);
- }
- return exchanges;
- }
-
}
http://git-wip-us.apache.org/repos/asf/camel/blob/f2cfc358/components/camel-twitter/src/main/java/org/apache/camel/component/twitter/consumer/TwitterEventType.java
----------------------------------------------------------------------
diff --git a/components/camel-twitter/src/main/java/org/apache/camel/component/twitter/consumer/TwitterEventType.java b/components/camel-twitter/src/main/java/org/apache/camel/component/twitter/consumer/TwitterEventType.java
index 77600d2..000b344 100644
--- a/components/camel-twitter/src/main/java/org/apache/camel/component/twitter/consumer/TwitterEventType.java
+++ b/components/camel-twitter/src/main/java/org/apache/camel/component/twitter/consumer/TwitterEventType.java
@@ -23,6 +23,7 @@ import java.util.List;
import org.apache.camel.Exchange;
import org.apache.camel.component.twitter.TwitterConstants;
import org.apache.camel.component.twitter.TwitterEndpoint;
+import org.apache.camel.component.twitter.util.TwitterSorter;
public enum TwitterEventType {
STATUS,
@@ -72,6 +73,10 @@ public enum TwitterEventType {
}
}
+ if (!exchanges.isEmpty() && endpoint.getProperties().isSortById()) {
+ exchanges = TwitterSorter.sortByStatusId(exchanges);
+ }
+
return exchanges;
}
}
http://git-wip-us.apache.org/repos/asf/camel/blob/f2cfc358/components/camel-twitter/src/main/java/org/apache/camel/component/twitter/util/TwitterSorter.java
----------------------------------------------------------------------
diff --git a/components/camel-twitter/src/main/java/org/apache/camel/component/twitter/util/TwitterSorter.java b/components/camel-twitter/src/main/java/org/apache/camel/component/twitter/util/TwitterSorter.java
index 9137e6c..2559d49 100644
--- a/components/camel-twitter/src/main/java/org/apache/camel/component/twitter/util/TwitterSorter.java
+++ b/components/camel-twitter/src/main/java/org/apache/camel/component/twitter/util/TwitterSorter.java
@@ -27,15 +27,20 @@ import twitter4j.Status;
*/
public final class TwitterSorter {
- public static List<Exchange> sortBySinceId(List<Exchange> exchanges) {
+ private TwitterSorter() {
+ }
+
+ /**
+ * Sorts the tweets by {@link Status#getId()}.
+ */
+ public static List<Exchange> sortByStatusId(List<Exchange> exchanges) {
return exchanges.stream().sorted((e1, e2) -> {
Object b1 = e1.getIn().getBody();
Object b2 = e2.getIn().getBody();
if (b1 instanceof Status && b2 instanceof Status) {
Status s1 = (Status) b1;
Status s2 = (Status) b2;
- // we want lowest values first (eg oldest before newest)
- return -1 * Long.compare(s1.getId(), s2.getId());
+ return Long.compare(s1.getId(), s2.getId());
}
return 0;
}).collect(Collectors.toList());