You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apex.apache.org by da...@apache.org on 2015/08/29 03:11:12 UTC

[22/25] incubator-apex-malhar git commit: Added the ability to sort schemas returned in a schema result.

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/d19f7463
Tree: http://git-wip-us.apache.org/repos/asf/incubator-apex-malhar/tree/d19f7463
Diff: http://git-wip-us.apache.org/repos/asf/incubator-apex-malhar/diff/d19f7463

Branch: refs/heads/feature-AppData
Commit: d19f7463a34ae216aab605c3d16b6bdfdfa78b29
Parents: 819e175
Author: Timothy Farkas <ti...@datatorrent.com>
Authored: Thu Aug 13 11:10:46 2015 -0700
Committer: David Yan <da...@datatorrent.com>
Committed: Fri Aug 28 18:09:32 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/d19f7463/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;
     }