You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@accumulo.apache.org by ec...@apache.org on 2014/12/12 22:30:45 UTC

[2/2] accumulo git commit: ACCUMULO-3408 fixed PreciseNumberType and wrote a unit test to make sure it really does precise numbers

ACCUMULO-3408 fixed PreciseNumberType and wrote a unit test to make sure it really does precise numbers


Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo
Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/81d25bc2
Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/81d25bc2
Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/81d25bc2

Branch: refs/heads/1.6
Commit: 81d25bc24b55b4418c0296de81cdf213ef7e8eac
Parents: 9980d4a
Author: Eric C. Newton <er...@gmail.com>
Authored: Fri Dec 12 16:30:15 2014 -0500
Committer: Eric C. Newton <er...@gmail.com>
Committed: Fri Dec 12 16:30:15 2014 -0500

----------------------------------------------------------------------
 .../monitor/servlets/PreciseNumberType.java     | 15 ++++++---
 .../monitor/util/celltypes/NumberType.java      |  2 +-
 .../util/celltypes/PreciseNumberTypeTest.java   | 35 ++++++++++++++++++++
 3 files changed, 47 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/accumulo/blob/81d25bc2/server/monitor/src/main/java/org/apache/accumulo/monitor/servlets/PreciseNumberType.java
----------------------------------------------------------------------
diff --git a/server/monitor/src/main/java/org/apache/accumulo/monitor/servlets/PreciseNumberType.java b/server/monitor/src/main/java/org/apache/accumulo/monitor/servlets/PreciseNumberType.java
index 66f97e1..1642fc2 100644
--- a/server/monitor/src/main/java/org/apache/accumulo/monitor/servlets/PreciseNumberType.java
+++ b/server/monitor/src/main/java/org/apache/accumulo/monitor/servlets/PreciseNumberType.java
@@ -24,9 +24,16 @@ public class PreciseNumberType extends NumberType<Integer> {
     super(warnMin, warnMax, errMin, errMax);
   }
   
-  public PreciseNumberType() {}
-  
-  public static String bigNumber(long big, String[] SUFFIXES, long base) {
-    return String.format("%,d", big);
+  @Override
+  public String format(Object obj) {
+    int i = (Integer)obj;
+    String display = String.format("%,d", obj);
+    if (i < errMin || i > errMax)
+      return String.format("<span class='error'>%s</span>", display);
+    if (i < warnMin || i > warnMax)
+      return String.format("<span class='warning'>%s</span>", display);
+    return display;
   }
+
+  public PreciseNumberType() {}
 }

http://git-wip-us.apache.org/repos/asf/accumulo/blob/81d25bc2/server/monitor/src/main/java/org/apache/accumulo/monitor/util/celltypes/NumberType.java
----------------------------------------------------------------------
diff --git a/server/monitor/src/main/java/org/apache/accumulo/monitor/util/celltypes/NumberType.java b/server/monitor/src/main/java/org/apache/accumulo/monitor/util/celltypes/NumberType.java
index d311603..b285727 100644
--- a/server/monitor/src/main/java/org/apache/accumulo/monitor/util/celltypes/NumberType.java
+++ b/server/monitor/src/main/java/org/apache/accumulo/monitor/util/celltypes/NumberType.java
@@ -20,7 +20,7 @@ import static org.apache.accumulo.core.util.NumUtil.bigNumberForQuantity;
 
 public class NumberType<T extends Number> extends CellType<T> {
   
-  private T warnMin, warnMax, errMin, errMax;
+  protected final T warnMin, warnMax, errMin, errMax;
   
   public NumberType(T warnMin, T warnMax, T errMin, T errMax) {
     this.warnMin = warnMin;

http://git-wip-us.apache.org/repos/asf/accumulo/blob/81d25bc2/server/monitor/src/test/java/org/apache/accumulo/monitor/util/celltypes/PreciseNumberTypeTest.java
----------------------------------------------------------------------
diff --git a/server/monitor/src/test/java/org/apache/accumulo/monitor/util/celltypes/PreciseNumberTypeTest.java b/server/monitor/src/test/java/org/apache/accumulo/monitor/util/celltypes/PreciseNumberTypeTest.java
new file mode 100644
index 0000000..38d3d2b
--- /dev/null
+++ b/server/monitor/src/test/java/org/apache/accumulo/monitor/util/celltypes/PreciseNumberTypeTest.java
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.accumulo.monitor.util.celltypes;
+
+import org.apache.accumulo.monitor.servlets.PreciseNumberType;
+
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+public class PreciseNumberTypeTest {
+  
+  @Test
+  public void test() {
+    PreciseNumberType p = new PreciseNumberType(500, 5000, 100, 6000);
+    assertEquals("1,000", p.format(1000));
+    assertEquals("<span class='error'>1</span>", p.format(1));
+    assertEquals("<span class='warning'>5,005</span>", p.format(5005));
+    assertEquals("<span class='error'>10,000</span>", p.format(10000));
+  }
+  
+}