brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rich...@apache.org
Subject [09/14] git commit: Sorts output
Date Mon, 08 Sep 2014 12:39:09 GMT
Sorts output


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

Branch: refs/heads/master
Commit: f14a64b61d771b9b5eb8ffb9fdfb7f208ac32e8c
Parents: 2157c98
Author: Martin Harris <github@nakomis.com>
Authored: Tue Sep 2 18:13:47 2014 +0100
Committer: Martin Harris <github@nakomis.com>
Committed: Mon Sep 8 11:20:34 2014 +0100

----------------------------------------------------------------------
 .../cli/itemlister/ItemDescriptors.java         | 36 ++++++++++++++++++
 .../brooklyn/cli/itemlister/ItemLister.java     | 40 ++++++++++----------
 .../main/resources/brooklyn-object-list.html    |  6 +--
 3 files changed, 59 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/f14a64b6/usage/cli/src/main/java/brooklyn/cli/itemlister/ItemDescriptors.java
----------------------------------------------------------------------
diff --git a/usage/cli/src/main/java/brooklyn/cli/itemlister/ItemDescriptors.java b/usage/cli/src/main/java/brooklyn/cli/itemlister/ItemDescriptors.java
index ecb2264..f909524 100644
--- a/usage/cli/src/main/java/brooklyn/cli/itemlister/ItemDescriptors.java
+++ b/usage/cli/src/main/java/brooklyn/cli/itemlister/ItemDescriptors.java
@@ -18,6 +18,8 @@
  */
 package brooklyn.cli.itemlister;
 
+import java.util.Collections;
+import java.util.Comparator;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -41,6 +43,7 @@ import brooklyn.rest.transform.EffectorTransformer;
 import brooklyn.rest.transform.EntityTransformer;
 import brooklyn.rest.transform.SensorTransformer;
 
+import com.google.common.base.Strings;
 import com.google.common.collect.Lists;
 import com.google.common.collect.Maps;
 import com.google.common.collect.Sets;
@@ -48,6 +51,10 @@ import com.google.common.collect.Sets;
 public class ItemDescriptors {
 
     public static List<Map<String, Object>> toItemDescriptors(Iterable<? extends
Class<? extends BrooklynObject>> types, boolean headingsOnly) {
+        return toItemDescriptors(types, headingsOnly, null);
+    }
+    
+    public static List<Map<String, Object>> toItemDescriptors(Iterable<? extends
Class<? extends BrooklynObject>> types, boolean headingsOnly, final String sortField)
{
         List<Map<String, Object>> itemDescriptors = Lists.newArrayList();
         
         for (Class<? extends BrooklynObject> type : types) {
@@ -55,6 +62,22 @@ public class ItemDescriptors {
             itemDescriptors.add(itemDescriptor);
         }
         
+        if (!Strings.isNullOrEmpty(sortField)) {
+            Collections.sort(itemDescriptors, new Comparator<Map<String, Object>>()
{
+                @Override public int compare(Map<String, Object> id1, Map<String,
Object> id2) {
+                    Object o1 = id1.get(sortField);
+                    Object o2 = id2.get(sortField);
+                    if (o1 == null) {
+                        return o2 == null ? 0 : 1;
+                    }
+                    if (o2 == null) {
+                        return -1;
+                    }
+                    return o1.toString().compareTo(o2.toString());
+                }
+            });
+        }
+        
         return itemDescriptors;
     }
     
@@ -107,10 +130,23 @@ public class ItemDescriptors {
     }
     
     public static Object toItemDescriptors(List<LocationResolver> resolvers) {
+        return toItemDescriptors(resolvers, false);
+    }
+    
+    public static Object toItemDescriptors(List<LocationResolver> resolvers, Boolean
sort) {
         List<Object> result = Lists.newArrayList();
         for (LocationResolver resolver : resolvers) {
             result.add(toItemDescriptor(resolver));
         }
+        if (sort) {
+            Collections.sort(result, new Comparator<Object>() {
+                @Override public int compare(Object o1, Object o2) {
+                    String s1 = o1 == null ? "" : o1.toString();
+                    String s2 = o2 == null ? "" : o2.toString();
+                    return s1.compareTo(s2);
+                }
+            });
+        }
         return result;
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/f14a64b6/usage/cli/src/main/java/brooklyn/cli/itemlister/ItemLister.java
----------------------------------------------------------------------
diff --git a/usage/cli/src/main/java/brooklyn/cli/itemlister/ItemLister.java b/usage/cli/src/main/java/brooklyn/cli/itemlister/ItemLister.java
index 8ee267f..0dfec16 100644
--- a/usage/cli/src/main/java/brooklyn/cli/itemlister/ItemLister.java
+++ b/usage/cli/src/main/java/brooklyn/cli/itemlister/ItemLister.java
@@ -18,6 +18,21 @@
  */
 package brooklyn.cli.itemlister;
 
+import io.airlift.command.Cli;
+import io.airlift.command.Cli.CliBuilder;
+import io.airlift.command.Command;
+import io.airlift.command.Option;
+
+import java.io.File;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.List;
+import java.util.Map;
+import java.util.ServiceLoader;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
 import brooklyn.basic.BrooklynObject;
 import brooklyn.catalog.Catalog;
 import brooklyn.cli.AbstractMain;
@@ -46,21 +61,6 @@ import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.Lists;
 import com.google.common.io.Files;
 
-import io.airlift.command.Cli;
-import io.airlift.command.Cli.CliBuilder;
-import io.airlift.command.Command;
-import io.airlift.command.Option;
-
-import java.io.File;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.List;
-import java.util.Map;
-import java.util.ServiceLoader;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
 public class ItemLister extends AbstractMain {
     
     private static final Logger LOG = LoggerFactory.getLogger(ItemLister.class);
@@ -103,11 +103,11 @@ public class ItemLister extends AbstractMain {
             List<Class<? extends Location>> locationTypes = getTypes(urls, Location.class,
Boolean.FALSE);
 
             Map<String, Object> result = ImmutableMap.<String, Object>builder()
-                    .put("entities", ItemDescriptors.toItemDescriptors(entityTypes, headingsOnly))
-                    .put("policies", ItemDescriptors.toItemDescriptors(policyTypes, headingsOnly))
-                    .put("enrichers", ItemDescriptors.toItemDescriptors(enricherTypes, headingsOnly))
-                    .put("locations", ItemDescriptors.toItemDescriptors(locationTypes, headingsOnly))
-                    .put("locationResolvers", ItemDescriptors.toItemDescriptors(ImmutableList.copyOf(ServiceLoader.load(LocationResolver.class))))
+                    .put("entities", ItemDescriptors.toItemDescriptors(entityTypes, headingsOnly,
"name"))
+                    .put("policies", ItemDescriptors.toItemDescriptors(policyTypes, headingsOnly,
"name"))
+                    .put("enrichers", ItemDescriptors.toItemDescriptors(enricherTypes, headingsOnly,
"name"))
+                    .put("locations", ItemDescriptors.toItemDescriptors(locationTypes, headingsOnly,
"type"))
+                    .put("locationResolvers", ItemDescriptors.toItemDescriptors(ImmutableList.copyOf(ServiceLoader.load(LocationResolver.class)),
true))
                     .build();
 
             String json = toJson(result);

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/f14a64b6/usage/cli/src/main/resources/brooklyn-object-list.html
----------------------------------------------------------------------
diff --git a/usage/cli/src/main/resources/brooklyn-object-list.html b/usage/cli/src/main/resources/brooklyn-object-list.html
index 8a5863c..8ec86fb 100644
--- a/usage/cli/src/main/resources/brooklyn-object-list.html
+++ b/usage/cli/src/main/resources/brooklyn-object-list.html
@@ -111,13 +111,13 @@ under the License.
 
         $(document).ready(function () {
             items.entities.forEach(function (element) {
-                $("#entityTable").find("tr:last").after("<tr><td>" + element.name
+ "</td><td><a href='entities/" + element.type + ".html'>" + element.type
+ "</a></td><td class='wordWrap'>" + element.description + "</td></tr>")
+                $("#entityTable").find("tr:last").after("<tr><td class='wordWrap'>"
+ element.name + "</td><td><a href='entities/" + element.type + ".html'>"
+ element.type + "</a></td><td class='wordWrap'>" + element.description
+ "</td></tr>")
             });
             items.policies.forEach(function (element) {
-                $("#policyTable").find("tr:last").after("<tr><td>" + element.name
+ "</td><td><a href='policies/" + element.type + ".html'>" + element.type
+ "</a></td><td class='wordWrap'>" + element.description + "</td></tr>")
+                $("#policyTable").find("tr:last").after("<tr><td class='wordWrap'>"
+ element.name + "</td><td><a href='policies/" + element.type + ".html'>"
+ element.type + "</a></td><td class='wordWrap'>" + element.description
+ "</td></tr>")
             });
             items.enrichers.forEach(function (element) {
-                $("#enricherTable").find("tr:last").after("<tr><td>" + element.name
+ "</td><td><a href='enrichers/" + element.type + ".html'>" + element.type
+ "</a></td><td class='wordWrap'>" + element.description + "</td></tr>")
+                $("#enricherTable").find("tr:last").after("<tr><td class='wordWrap'>"
+ element.name + "</td><td><a href='enrichers/" + element.type + ".html'>"
+ element.type + "</a></td><td class='wordWrap'>" + element.description
+ "</td></tr>")
             });
             items.locations.forEach(function (element) {
                 $("#locationTable").find("tr:last").after("<tr><td class='location'><a
href='locations/" + element.type + ".html'>" + element.type + "</a></td></tr>")


Mime
View raw message