diff options
author | James Moger <james.moger@gitblit.com> | 2011-05-29 11:19:30 -0400 |
---|---|---|
committer | James Moger <james.moger@gitblit.com> | 2011-05-29 11:19:30 -0400 |
commit | ec97f716023c0bbd6a9e11cbe7144973cf1c103d (patch) | |
tree | 134278a3d32bb6418ed2f413f8ad500580f384e8 /src | |
parent | 28d6b2a860740557bf93dd0f9a48d059379ed696 (diff) | |
download | gitblit-ec97f716023c0bbd6a9e11cbe7144973cf1c103d.tar.gz gitblit-ec97f716023c0bbd6a9e11cbe7144973cf1c103d.zip |
Unit testing.
Diffstat (limited to 'src')
-rw-r--r-- | src/com/gitblit/utils/ByteFormat.java | 45 | ||||
-rw-r--r-- | src/com/gitblit/utils/DiffUtils.java | 15 | ||||
-rw-r--r-- | src/com/gitblit/utils/StringUtils.java | 2 | ||||
-rw-r--r-- | src/com/gitblit/utils/TimeUtils.java | 4 |
4 files changed, 24 insertions, 42 deletions
diff --git a/src/com/gitblit/utils/ByteFormat.java b/src/com/gitblit/utils/ByteFormat.java index 92a8e46d..fee645c7 100644 --- a/src/com/gitblit/utils/ByteFormat.java +++ b/src/com/gitblit/utils/ByteFormat.java @@ -20,46 +20,20 @@ import java.text.FieldPosition; import java.text.Format; import java.text.ParsePosition; -/** - * A formatter for formatting byte sizes. For example, formatting 12345 byes - * results in "12.1 K" and 1234567 results in "1.18 MB". - * - */ public class ByteFormat extends Format { private static final long serialVersionUID = 1L; public ByteFormat() { } - - /** - * Formats a long which represent a number of bytes. - */ - public String format(long bytes) { - return format(Long.valueOf(bytes)); + + public String format(long value) { + return format(new Long(value)); } - /** - * Formats a long which represent a number of kilobytes. - */ - public String formatKB(long kilobytes) { - return format(Long.valueOf(kilobytes * 1024)); - } - - /** - * Format the given object (must be a Long). - * - * @param obj - * assumed to be the number of bytes as a Long. - * @param buf - * the StringBuffer to append to. - * @param pos - * @return A formatted string representing the given bytes in more - * human-readable form. - */ public StringBuffer format(Object obj, StringBuffer buf, FieldPosition pos) { - if (obj instanceof Long) { - long numBytes = ((Long) obj).longValue(); + if (obj instanceof Number) { + long numBytes = ((Number) obj).longValue(); if (numBytes < 1024) { DecimalFormat formatter = new DecimalFormat("#,##0"); buf.append(formatter.format((double) numBytes)).append(" b"); @@ -77,14 +51,7 @@ public class ByteFormat extends Format { } return buf; } - - /** - * In this implementation, returns null always. - * - * @param source - * @param pos - * @return returns null in this implementation. - */ + public Object parseObject(String source, ParsePosition pos) { return null; } diff --git a/src/com/gitblit/utils/DiffUtils.java b/src/com/gitblit/utils/DiffUtils.java index d7a4a632..c9d0fc36 100644 --- a/src/com/gitblit/utils/DiffUtils.java +++ b/src/com/gitblit/utils/DiffUtils.java @@ -1,3 +1,18 @@ +/*
+ * Copyright 2011 gitblit.com.
+ *
+ * Licensed 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 com.gitblit.utils;
import java.io.ByteArrayOutputStream;
diff --git a/src/com/gitblit/utils/StringUtils.java b/src/com/gitblit/utils/StringUtils.java index 4a9c88d5..fd6ca98b 100644 --- a/src/com/gitblit/utils/StringUtils.java +++ b/src/com/gitblit/utils/StringUtils.java @@ -130,7 +130,7 @@ public class StringUtils { public static String getRootPath(String path) {
if (path.indexOf('/') > -1) {
- return path.substring(0, path.indexOf('/'));
+ return path.substring(0, path.lastIndexOf('/'));
}
return "";
}
diff --git a/src/com/gitblit/utils/TimeUtils.java b/src/com/gitblit/utils/TimeUtils.java index ac8e2098..805b44f5 100644 --- a/src/com/gitblit/utils/TimeUtils.java +++ b/src/com/gitblit/utils/TimeUtils.java @@ -137,7 +137,7 @@ public class TimeUtils { int days = daysAgo(date, true);
if (days < 365) {
if (days <= 30) {
- ago = days + " day" + (days > 1 ? "s" : "") + " ago";
+ ago = days + " days ago";
} else if (days <= 90) {
int weeks = days / 7;
if (weeks == 12) {
@@ -151,7 +151,7 @@ public class TimeUtils { if (weeks >= 2) {
months++;
}
- ago = months + " month" + (months > 1 ? "s" : "") + " ago";
+ ago = months + " months ago";
}
} else if (days == 365) {
ago = "1 year ago";
|