apex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From david...@apache.org
Subject [3/5] incubator-apex-malhar git commit: MLHR-1808 Added the ability to sort schemas returned in a schema result.
Date Sat, 29 Aug 2015 01:50:24 GMT
MLHR-1808 Added the ability to sort schemas returned in a schema result.


Project: http://git-wip-us.apache.org/repos/asf/incubator-apex-malhar/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-apex-malhar/commit/ee92fc99
Tree: http://git-wip-us.apache.org/repos/asf/incubator-apex-malhar/tree/ee92fc99
Diff: http://git-wip-us.apache.org/repos/asf/incubator-apex-malhar/diff/ee92fc99

Branch: refs/heads/feature-AppData
Commit: ee92fc99176155590382a7855b628a861a898c42
Parents: caf85bb
Author: Timothy Farkas <tim@datatorrent.com>
Authored: Thu Aug 13 11:10:46 2015 -0700
Committer: David Yan <david@datatorrent.com>
Committed: Fri Aug 28 18:49:52 2015 -0700

----------------------------------------------------------------------
 .../appdata/schemas/SchemaRegistryMultiple.java | 28 +++++++++++++++++---
 1 file changed, 24 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-apex-malhar/blob/ee92fc99/library/src/main/java/com/datatorrent/lib/appdata/schemas/SchemaRegistryMultiple.java
----------------------------------------------------------------------
diff --git a/library/src/main/java/com/datatorrent/lib/appdata/schemas/SchemaRegistryMultiple.java
b/library/src/main/java/com/datatorrent/lib/appdata/schemas/SchemaRegistryMultiple.java
index 9833e94..832cf0a 100644
--- a/library/src/main/java/com/datatorrent/lib/appdata/schemas/SchemaRegistryMultiple.java
+++ b/library/src/main/java/com/datatorrent/lib/appdata/schemas/SchemaRegistryMultiple.java
@@ -15,8 +15,11 @@
  */
 package com.datatorrent.lib.appdata.schemas;
 
+import com.google.common.base.Preconditions;
 import java.io.Serializable;
 
+import java.util.Collections;
+import java.util.Comparator;
 import java.util.List;
 import java.util.Map;
 
@@ -35,6 +38,7 @@ public class SchemaRegistryMultiple implements SchemaRegistry, Serializable
    * The dimensional table which holds the mapping from schema keys to schemas.
    */
   private DimensionalTable<Schema> table;
+  private Comparator<Schema> schemaComparator;
 
   /**
    * Constructor for serialization.
@@ -53,20 +57,36 @@ public class SchemaRegistryMultiple implements SchemaRegistry, Serializable
     table = new DimensionalTable<Schema>(schemaKeys);
   }
 
+  /**
+   * The names of all the schema keys for all schemas in this registry.
+   * @param schemaKeys The names of all the schema keys for all schemas in this registry.
+   * @param schemaComparator The comparator used to order the schemas returned in the {@link
SchemaResult} produced
+   * by {@link SchemaRegistryMultiple#getSchemaResult(com.datatorrent.lib.appdata.schemas.SchemaQuery)}
+   */
+  public SchemaRegistryMultiple(List<String> schemaKeys,
+                                Comparator<Schema> schemaComparator)
+  {
+    this(schemaKeys);
+    this.schemaComparator = Preconditions.checkNotNull(schemaComparator);
+  }
+
   @Override
   public SchemaResult getSchemaResult(SchemaQuery schemaQuery)
   {
     Map<String, String> schemaKeys = schemaQuery.getSchemaKeys();
     List<Schema> data = null;
 
-    if(schemaKeys == null) {
+    if (schemaKeys == null) {
       data = table.getAllDataPoints();
-    }
-    else {
+    } else {
       data = table.getDataPoints(schemaKeys);
     }
 
-    if(data.isEmpty()) {
+    if (schemaComparator != null) {
+      Collections.sort(data, schemaComparator);
+    }
+
+    if (data.isEmpty()) {
       return null;
     }
 


Mime
View raw message