Return-Path: X-Original-To: apmail-brooklyn-commits-archive@minotaur.apache.org Delivered-To: apmail-brooklyn-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id C9CED172E6 for ; Thu, 9 Oct 2014 08:43:49 +0000 (UTC) Received: (qmail 25214 invoked by uid 500); 9 Oct 2014 08:43:49 -0000 Delivered-To: apmail-brooklyn-commits-archive@brooklyn.apache.org Received: (qmail 25190 invoked by uid 500); 9 Oct 2014 08:43:49 -0000 Mailing-List: contact commits-help@brooklyn.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@brooklyn.incubator.apache.org Delivered-To: mailing list commits@brooklyn.incubator.apache.org Received: (qmail 25181 invoked by uid 99); 9 Oct 2014 08:43:49 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 09 Oct 2014 08:43:49 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED,T_RP_MATCHES_RCVD X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO mail.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with SMTP; Thu, 09 Oct 2014 08:43:45 +0000 Received: (qmail 25020 invoked by uid 99); 9 Oct 2014 08:43:25 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 09 Oct 2014 08:43:25 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 942C39959B8; Thu, 9 Oct 2014 08:43:25 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: aledsage@apache.org To: commits@brooklyn.incubator.apache.org Date: Thu, 09 Oct 2014 08:43:26 -0000 Message-Id: <8bbdcacb69b84ba8b03ff22a839967df@git.apache.org> In-Reply-To: <96d392650f664e08a9a7dba8caacd8ea@git.apache.org> References: <96d392650f664e08a9a7dba8caacd8ea@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [2/6] Replaces all tab characters in java files with four spaces X-Virus-Checked: Checked by ClamAV on apache.org http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/a2da61d1/utils/common/src/main/java/brooklyn/util/text/QuotedStringTokenizer.java ---------------------------------------------------------------------- diff --git a/utils/common/src/main/java/brooklyn/util/text/QuotedStringTokenizer.java b/utils/common/src/main/java/brooklyn/util/text/QuotedStringTokenizer.java index 4673458..1946235 100644 --- a/utils/common/src/main/java/brooklyn/util/text/QuotedStringTokenizer.java +++ b/utils/common/src/main/java/brooklyn/util/text/QuotedStringTokenizer.java @@ -28,54 +28,54 @@ import java.util.StringTokenizer; */ public class QuotedStringTokenizer { - final StringTokenizer delegate; - final String quoteChars; - final boolean includeQuotes; - final String delimiters; - final boolean includeDelimiters; + final StringTokenizer delegate; + final String quoteChars; + final boolean includeQuotes; + final String delimiters; + final boolean includeDelimiters; - public static String DEFAULT_QUOTE_CHARS = "\"\'"; - - - protected String DEFAULT_QUOTE_CHARS() { - return DEFAULT_QUOTE_CHARS; - } - - public final static String DEFAULT_DELIMITERS = " \t\n\r\f"; - - /** default quoted tokenizer, using single and double quotes as quote chars and returning quoted results - * (use unquoteToken to unquote), and using whitespace chars as delimeters (not included as tokens); - * string may be null if the nothing will be tokenized and the class is used only for - * quoteToken(String) and unquote(String). - */ - public QuotedStringTokenizer(String stringToTokenize) { - this(stringToTokenize, true); - } - public QuotedStringTokenizer(String stringToTokenize, boolean includeQuotes) { - this(stringToTokenize, null, includeQuotes); - } - public QuotedStringTokenizer(String stringToTokenize, String quoteChars, boolean includeQuotes) { - this(stringToTokenize, quoteChars, includeQuotes, null, false); - } + public static String DEFAULT_QUOTE_CHARS = "\"\'"; + + + protected String DEFAULT_QUOTE_CHARS() { + return DEFAULT_QUOTE_CHARS; + } + + public final static String DEFAULT_DELIMITERS = " \t\n\r\f"; + + /** default quoted tokenizer, using single and double quotes as quote chars and returning quoted results + * (use unquoteToken to unquote), and using whitespace chars as delimeters (not included as tokens); + * string may be null if the nothing will be tokenized and the class is used only for + * quoteToken(String) and unquote(String). + */ + public QuotedStringTokenizer(String stringToTokenize) { + this(stringToTokenize, true); + } + public QuotedStringTokenizer(String stringToTokenize, boolean includeQuotes) { + this(stringToTokenize, null, includeQuotes); + } + public QuotedStringTokenizer(String stringToTokenize, String quoteChars, boolean includeQuotes) { + this(stringToTokenize, quoteChars, includeQuotes, null, false); + } - public QuotedStringTokenizer(String stringToTokenize, String quoteChars, boolean includeQuotes, String delimiters, boolean includeDelimiters) { - delegate = new StringTokenizer(stringToTokenize==null ? "" : stringToTokenize, (delimiters==null ? DEFAULT_DELIMITERS : delimiters), true); - this.quoteChars = quoteChars==null ? DEFAULT_QUOTE_CHARS() : quoteChars; - this.includeQuotes = includeQuotes; - this.delimiters = delimiters==null ? DEFAULT_DELIMITERS : delimiters; - this.includeDelimiters = includeDelimiters; - updateNextToken(); - } - - public static class Builder { - private String quoteChars = DEFAULT_QUOTE_CHARS; - private boolean includeQuotes=true; - private String delimiterChars=DEFAULT_DELIMITERS; - private boolean includeDelimiters=false; + public QuotedStringTokenizer(String stringToTokenize, String quoteChars, boolean includeQuotes, String delimiters, boolean includeDelimiters) { + delegate = new StringTokenizer(stringToTokenize==null ? "" : stringToTokenize, (delimiters==null ? DEFAULT_DELIMITERS : delimiters), true); + this.quoteChars = quoteChars==null ? DEFAULT_QUOTE_CHARS() : quoteChars; + this.includeQuotes = includeQuotes; + this.delimiters = delimiters==null ? DEFAULT_DELIMITERS : delimiters; + this.includeDelimiters = includeDelimiters; + updateNextToken(); + } + + public static class Builder { + private String quoteChars = DEFAULT_QUOTE_CHARS; + private boolean includeQuotes=true; + private String delimiterChars=DEFAULT_DELIMITERS; + private boolean includeDelimiters=false; - public QuotedStringTokenizer build(String stringToTokenize) { - return new QuotedStringTokenizer(stringToTokenize, quoteChars, includeQuotes, delimiterChars, includeDelimiters); - } + public QuotedStringTokenizer build(String stringToTokenize) { + return new QuotedStringTokenizer(stringToTokenize, quoteChars, includeQuotes, delimiterChars, includeDelimiters); + } public List buildList(String stringToTokenize) { return new QuotedStringTokenizer(stringToTokenize, quoteChars, includeQuotes, delimiterChars, includeDelimiters).remainderAsList(); } @@ -86,73 +86,73 @@ public class QuotedStringTokenizer { public Builder delimiterChars(String delimiterChars) { this.delimiterChars = delimiterChars; return this; } public Builder addDelimiterChars(String delimiterChars) { this.delimiterChars = this.delimiterChars + delimiterChars; return this; } public Builder includeDelimiters(boolean includeDelimiters) { this.includeDelimiters = includeDelimiters; return this; } - } + } public static Builder builder() { return new Builder(); } - String peekedNextToken = null; - - public synchronized boolean hasMoreTokens() { - return peekedNextToken!=null; - } - - public synchronized String nextToken() { - if (peekedNextToken==null) throw new NoSuchElementException(); - String lastToken = peekedNextToken; - updateNextToken(); - return includeQuotes ? lastToken : unquoteToken(lastToken); - } + String peekedNextToken = null; + + public synchronized boolean hasMoreTokens() { + return peekedNextToken!=null; + } + + public synchronized String nextToken() { + if (peekedNextToken==null) throw new NoSuchElementException(); + String lastToken = peekedNextToken; + updateNextToken(); + return includeQuotes ? lastToken : unquoteToken(lastToken); + } - /** this method removes all unescaped quote chars, i.e. quote chars preceded by no backslashes (or a larger even number of them); - * it also unescapes '\\' as '\'. it does no other unescaping. */ - public String unquoteToken(String word) { - // ( (\\A|[^\\\\]) (\\\\\\\\)* ) [ Pattern.quote(quoteChars) ] $1 - word = word.replaceAll( - "((\\A|[^\\\\])(\\\\\\\\)*)["+ - //Pattern.quote( - quoteChars - //) - +"]+", - "$1"); - //above pattern removes any quote preceded by even number of backslashes - //now it is safe to replace any \c by c - word = word.replaceAll("\\\\"+"([\\\\"+ - //Pattern.quote( - quoteChars - //) - +"])", "$1"); - - return word; - } - - /** returns the input text escaped for use with unquoteTokens, and wrapped in the quoteChar[0] (usu a double quote) */ - public String quoteToken(String unescapedText) { - String result = unescapedText; - //replace every backslash by two backslashes - result = result.replaceAll("\\\\", "\\\\\\\\"); - //now replace every quote char by backslash quote char - result = result.replaceAll("(["+quoteChars+"])", "\\\\$1"); - //then wrap in quote - result = quoteChars.charAt(0) + result + quoteChars.charAt(0); - return result; - } + /** this method removes all unescaped quote chars, i.e. quote chars preceded by no backslashes (or a larger even number of them); + * it also unescapes '\\' as '\'. it does no other unescaping. */ + public String unquoteToken(String word) { + // ( (\\A|[^\\\\]) (\\\\\\\\)* ) [ Pattern.quote(quoteChars) ] $1 + word = word.replaceAll( + "((\\A|[^\\\\])(\\\\\\\\)*)["+ + //Pattern.quote( + quoteChars + //) + +"]+", + "$1"); + //above pattern removes any quote preceded by even number of backslashes + //now it is safe to replace any \c by c + word = word.replaceAll("\\\\"+"([\\\\"+ + //Pattern.quote( + quoteChars + //) + +"])", "$1"); + + return word; + } + + /** returns the input text escaped for use with unquoteTokens, and wrapped in the quoteChar[0] (usu a double quote) */ + public String quoteToken(String unescapedText) { + String result = unescapedText; + //replace every backslash by two backslashes + result = result.replaceAll("\\\\", "\\\\\\\\"); + //now replace every quote char by backslash quote char + result = result.replaceAll("(["+quoteChars+"])", "\\\\$1"); + //then wrap in quote + result = quoteChars.charAt(0) + result + quoteChars.charAt(0); + return result; + } - protected synchronized void updateNextToken() { - peekedNextToken = null; - String token; - do { - if (!delegate.hasMoreTokens()) return; - token = delegate.nextToken(); - //skip delimeters - } while (!includeDelimiters && token.matches("["+delimiters+"]+")); - - StringBuffer nextToken = new StringBuffer(token); - pullUntilValid(nextToken); - peekedNextToken = nextToken.toString(); - } + protected synchronized void updateNextToken() { + peekedNextToken = null; + String token; + do { + if (!delegate.hasMoreTokens()) return; + token = delegate.nextToken(); + //skip delimeters + } while (!includeDelimiters && token.matches("["+delimiters+"]+")); + + StringBuffer nextToken = new StringBuffer(token); + pullUntilValid(nextToken); + peekedNextToken = nextToken.toString(); + } - private void pullUntilValid(StringBuffer nextToken) { + private void pullUntilValid(StringBuffer nextToken) { while (hasOpenQuote(nextToken.toString(), quoteChars) && delegate.hasMoreTokens()) { //keep appending until the quote is ended or there are no more quotes nextToken.append(delegate.nextToken()); @@ -160,37 +160,37 @@ public class QuotedStringTokenizer { } public static boolean hasOpenQuote(String stringToCheck) { - return hasOpenQuote(stringToCheck, DEFAULT_QUOTE_CHARS); - } + return hasOpenQuote(stringToCheck, DEFAULT_QUOTE_CHARS); + } - public static boolean hasOpenQuote(String stringToCheck, String quoteChars) { - String x = stringToCheck; - if (x==null) return false; + public static boolean hasOpenQuote(String stringToCheck, String quoteChars) { + String x = stringToCheck; + if (x==null) return false; - StringBuffer xi = new StringBuffer(); - for (int i=0; i=0) { - xi.append(c); - } - } - x = xi.toString(); - - while (x.length()>0) { - char c = x.charAt(0); - int match = x.indexOf(c, 1); - if (match==-1) return true; - x = x.substring(match+1); - } - return false; - } + StringBuffer xi = new StringBuffer(); + for (int i=0; i=0) { + xi.append(c); + } + } + x = xi.toString(); + + while (x.length()>0) { + char c = x.charAt(0); + int match = x.indexOf(c, 1); + if (match==-1) return true; + x = x.substring(match+1); + } + return false; + } - public List remainderAsList() { - List l = new ArrayList(); - while (hasMoreTokens()) - l.add(nextToken()); - return l; - } + public List remainderAsList() { + List l = new ArrayList(); + while (hasMoreTokens()) + l.add(nextToken()); + return l; + } } http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/a2da61d1/utils/common/src/main/java/brooklyn/util/text/Strings.java ---------------------------------------------------------------------- diff --git a/utils/common/src/main/java/brooklyn/util/text/Strings.java b/utils/common/src/main/java/brooklyn/util/text/Strings.java index 98ef7bd..528fa72 100644 --- a/utils/common/src/main/java/brooklyn/util/text/Strings.java +++ b/utils/common/src/main/java/brooklyn/util/text/Strings.java @@ -353,8 +353,7 @@ public class Strings { * @return such a string */ public static String makeRealString(double x, int maxlen, int prec, int leftPadLen, double skipDecimalThreshhold, boolean useEForSmallNumbers) { - if (x<0) return - "-"+makeRealString(-x, maxlen, prec, leftPadLen); + if (x<0) return "-"+makeRealString(-x, maxlen, prec, leftPadLen); NumberFormat df = DecimalFormat.getInstance(); //df.setMaximumFractionDigits(maxlen); df.setMinimumFractionDigits(0); http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/a2da61d1/utils/common/src/main/java/brooklyn/util/time/Time.java ---------------------------------------------------------------------- diff --git a/utils/common/src/main/java/brooklyn/util/time/Time.java b/utils/common/src/main/java/brooklyn/util/time/Time.java index 7fb5e1b..921c973 100644 --- a/utils/common/src/main/java/brooklyn/util/time/Time.java +++ b/utils/common/src/main/java/brooklyn/util/time/Time.java @@ -38,23 +38,23 @@ import com.google.common.base.Stopwatch; public class Time { public static final String DATE_FORMAT_PREFERRED = "yyyy-MM-dd HH:mm:ss.SSS"; - public static final String DATE_FORMAT_STAMP = "yyyyMMdd-HHmmssSSS"; + public static final String DATE_FORMAT_STAMP = "yyyyMMdd-HHmmssSSS"; - public static final long MILLIS_IN_SECOND = 1000; - public static final long MILLIS_IN_MINUTE = 60*MILLIS_IN_SECOND; - public static final long MILLIS_IN_HOUR = 60*MILLIS_IN_MINUTE; - public static final long MILLIS_IN_DAY = 24*MILLIS_IN_HOUR; - public static final long MILLIS_IN_YEAR = 365*MILLIS_IN_DAY; - + public static final long MILLIS_IN_SECOND = 1000; + public static final long MILLIS_IN_MINUTE = 60*MILLIS_IN_SECOND; + public static final long MILLIS_IN_HOUR = 60*MILLIS_IN_MINUTE; + public static final long MILLIS_IN_DAY = 24*MILLIS_IN_HOUR; + public static final long MILLIS_IN_YEAR = 365*MILLIS_IN_DAY; + /** returns the current time in YYYY-MM-DD HH:MM:SS.mss format */ public static String makeDateString() { return makeDateString(System.currentTimeMillis()); } - /** returns the time in YYYY-MM-DD HH:MM:SS.mss format, given a long (e.g. returned by System.currentTimeMillis) */ - public static String makeDateString(long date) { - return new SimpleDateFormat(DATE_FORMAT_PREFERRED).format(new Date(date)); - } + /** returns the time in YYYY-MM-DD HH:MM:SS.mss format, given a long (e.g. returned by System.currentTimeMillis) */ + public static String makeDateString(long date) { + return new SimpleDateFormat(DATE_FORMAT_PREFERRED).format(new Date(date)); + } public static Function toDateString() { return dateString; } private static Function dateString = new Function() { @@ -120,47 +120,47 @@ public class Time { return makeTimeStringNanoRounded(d.toNanoseconds()); } /** given an elapsed time, makes it readable, eg 44d 6h, or 8s 923ms, optionally rounding */ - public static String makeTimeString(long t, boolean round) { - return makeTimeStringNano(t*1000000L, round); - } + public static String makeTimeString(long t, boolean round) { + return makeTimeStringNano(t*1000000L, round); + } /** @see #makeTimeString(long, boolean) */ - public static String makeTimeStringNanoExact(long tn) { - return makeTimeStringNano(tn, false); - } + public static String makeTimeStringNanoExact(long tn) { + return makeTimeStringNano(tn, false); + } /** @see #makeTimeString(long, boolean) */ - public static String makeTimeStringNanoRounded(long tn) { - return makeTimeStringNano(tn, true); - } + public static String makeTimeStringNanoRounded(long tn) { + return makeTimeStringNano(tn, true); + } /** @see #makeTimeString(long, boolean) */ - public static String makeTimeStringNano(long tn, boolean round) { - if (tn<0) return "-"+makeTimeStringNano(-tn, round); - if (tn==0) return "0"; - - long tnm = tn % 1000000; - long t = tn/1000000; - String result = ""; - - long d = t/MILLIS_IN_DAY; t %= MILLIS_IN_DAY; - long h = t/MILLIS_IN_HOUR; t %= MILLIS_IN_HOUR; - long m = t/MILLIS_IN_MINUTE; t %= MILLIS_IN_MINUTE; - long s = t/MILLIS_IN_SECOND; t %= MILLIS_IN_SECOND; - long ms = t; - - int segments = 0; - if (d>0) { result += d+"d "; segments++; } - if (h>0) { result += h+"h "; segments++; } - if (round && segments>=2) return Strings.removeAllFromEnd(result, " "); - if (m>0) { result += m+"m "; segments++; } - if (round && (segments>=2 || d>0)) return Strings.removeAllFromEnd(result, " "); - if (s>0) { - if (ms==0 && tnm==0) { - result += s+"s"; segments++; + public static String makeTimeStringNano(long tn, boolean round) { + if (tn<0) return "-"+makeTimeStringNano(-tn, round); + if (tn==0) return "0"; + + long tnm = tn % 1000000; + long t = tn/1000000; + String result = ""; + + long d = t/MILLIS_IN_DAY; t %= MILLIS_IN_DAY; + long h = t/MILLIS_IN_HOUR; t %= MILLIS_IN_HOUR; + long m = t/MILLIS_IN_MINUTE; t %= MILLIS_IN_MINUTE; + long s = t/MILLIS_IN_SECOND; t %= MILLIS_IN_SECOND; + long ms = t; + + int segments = 0; + if (d>0) { result += d+"d "; segments++; } + if (h>0) { result += h+"h "; segments++; } + if (round && segments>=2) return Strings.removeAllFromEnd(result, " "); + if (m>0) { result += m+"m "; segments++; } + if (round && (segments>=2 || d>0)) return Strings.removeAllFromEnd(result, " "); + if (s>0) { + if (ms==0 && tnm==0) { + result += s+"s"; segments++; return result; - } - if (round && segments>0) { - result += s+"s"; segments++; - return result; - } + } + if (round && segments>0) { + result += s+"s"; segments++; + return result; + } if (round && s>10) { result += toDecimal(s, ms/1000.0, 1)+"s"; segments++; return result; @@ -170,10 +170,10 @@ public class Time { return result; } result += s+"s "; - } - if (round && segments>0) - return Strings.removeAllFromEnd(result, " "); - if (ms>0) { + } + if (round && segments>0) + return Strings.removeAllFromEnd(result, " "); + if (ms>0) { if (tnm==0) { result += ms+"ms"; segments++; return result; @@ -191,16 +191,16 @@ public class Time { return result; } result += ms+"ms "; - } - - long us = tnm/1000; - long ns = tnm % 1000; + } + + long us = tnm/1000; + long ns = tnm % 1000; - if (us>0) { - if (ns==0) { - result += us+"us"; segments++; - return result; - } + if (us>0) { + if (ns==0) { + result += us+"us"; segments++; + return result; + } if (round && us>=100) { result += toDecimal(us, ns/1000.0, 1)+"us"; segments++; return result; @@ -209,16 +209,16 @@ public class Time { result += toDecimal(us, ns/1000.0, 2)+"us"; segments++; return result; } - if (round) { - result += toDecimal(us, ns/1000.0, 3)+"us"; segments++; - return result; - } - result += us+"us "; - } + if (round) { + result += toDecimal(us, ns/1000.0, 3)+"us"; segments++; + return result; + } + result += us+"us "; + } - if (ns>0) result += ns+"ns"; - return Strings.removeAllFromEnd(result, " "); - } + if (ns>0) result += ns+"ns"; + return Strings.removeAllFromEnd(result, " "); + } public static Function fromLongToTimeStringExact() { return LONG_TO_TIME_STRING_EXACT; } private static final Function LONG_TO_TIME_STRING_EXACT = new FunctionLongToTimeStringExact(); @@ -274,35 +274,35 @@ public class Time { } } - private static String toDecimal(long intPart, double fracPart, int decimalPrecision) { - long powTen = 1; - for (int i=0; ii) { - char c = s.charAt(i); - if (c=='.' || Character.isDigit(c)) i++; - else break; - } - String num = s.substring(0, i); - if (i==0) { - num = Strings.getLastWord(timeString).toLowerCase(); - timeString = timeString.substring(0, timeString.length()-num.length()).trim(); - } else { - s = s.substring(i); - } - long multiplier = 0; - if (num.length()==0) { - //must be never or something - if (s.equalsIgnoreCase("never") || s.equalsIgnoreCase("off") || s.equalsIgnoreCase("false")) - return -1; - throw new NumberFormatException("unrecognised word '"+s+"' in time string"); - } - if (s.equalsIgnoreCase("ms") || s.equalsIgnoreCase("milli") || s.equalsIgnoreCase("millis") - || s.equalsIgnoreCase("millisec") || s.equalsIgnoreCase("millisecs") - || s.equalsIgnoreCase("millisecond") || s.equalsIgnoreCase("milliseconds")) - multiplier = 1; - else if (s.equalsIgnoreCase("s") || s.equalsIgnoreCase("sec") || s.equalsIgnoreCase("secs") - || s.equalsIgnoreCase("second") || s.equalsIgnoreCase("seconds")) - multiplier = 1000; - else if (s.equalsIgnoreCase("m") || s.equalsIgnoreCase("min") || s.equalsIgnoreCase("mins") - || s.equalsIgnoreCase("minute") || s.equalsIgnoreCase("minutes")) - multiplier = 60*1000; - else if (s.equalsIgnoreCase("h") || s.equalsIgnoreCase("hr") || s.equalsIgnoreCase("hrs") - || s.equalsIgnoreCase("hour") || s.equalsIgnoreCase("hours")) - multiplier = 60*60*1000; - else if (s.equalsIgnoreCase("d") || s.equalsIgnoreCase("day") || s.equalsIgnoreCase("days")) - multiplier = 24*60*60*1000; - else - throw new NumberFormatException("unknown unit '"+s+"' in time string"); - double d = Double.parseDouble(num); - double dd = 0; - if (timeString.length()>0) { - dd = parseTimeStringAsDouble(timeString); - if (dd==-1) { - throw new NumberFormatException("cannot combine '"+timeString+"' with '"+num+" "+s+"'"); - } - } - return d*multiplier + dd; - } - } + */ + public static double parseTimeStringAsDouble(String timeString) { + if (timeString==null) + throw new NumberFormatException("GeneralHelper.parseTimeString cannot parse a null string"); + try { + double d = Double.parseDouble(timeString); + return d; + } catch (NumberFormatException e) { + //look for a type marker + timeString = timeString.trim(); + String s = Strings.getLastWord(timeString).toLowerCase(); + timeString = timeString.substring(0, timeString.length()-s.length()).trim(); + int i=0; + while (s.length()>i) { + char c = s.charAt(i); + if (c=='.' || Character.isDigit(c)) i++; + else break; + } + String num = s.substring(0, i); + if (i==0) { + num = Strings.getLastWord(timeString).toLowerCase(); + timeString = timeString.substring(0, timeString.length()-num.length()).trim(); + } else { + s = s.substring(i); + } + long multiplier = 0; + if (num.length()==0) { + //must be never or something + if (s.equalsIgnoreCase("never") || s.equalsIgnoreCase("off") || s.equalsIgnoreCase("false")) + return -1; + throw new NumberFormatException("unrecognised word '"+s+"' in time string"); + } + if (s.equalsIgnoreCase("ms") || s.equalsIgnoreCase("milli") || s.equalsIgnoreCase("millis") + || s.equalsIgnoreCase("millisec") || s.equalsIgnoreCase("millisecs") + || s.equalsIgnoreCase("millisecond") || s.equalsIgnoreCase("milliseconds")) + multiplier = 1; + else if (s.equalsIgnoreCase("s") || s.equalsIgnoreCase("sec") || s.equalsIgnoreCase("secs") + || s.equalsIgnoreCase("second") || s.equalsIgnoreCase("seconds")) + multiplier = 1000; + else if (s.equalsIgnoreCase("m") || s.equalsIgnoreCase("min") || s.equalsIgnoreCase("mins") + || s.equalsIgnoreCase("minute") || s.equalsIgnoreCase("minutes")) + multiplier = 60*1000; + else if (s.equalsIgnoreCase("h") || s.equalsIgnoreCase("hr") || s.equalsIgnoreCase("hrs") + || s.equalsIgnoreCase("hour") || s.equalsIgnoreCase("hours")) + multiplier = 60*60*1000; + else if (s.equalsIgnoreCase("d") || s.equalsIgnoreCase("day") || s.equalsIgnoreCase("days")) + multiplier = 24*60*60*1000; + else + throw new NumberFormatException("unknown unit '"+s+"' in time string"); + double d = Double.parseDouble(num); + double dd = 0; + if (timeString.length()>0) { + dd = parseTimeStringAsDouble(timeString); + if (dd==-1) { + throw new NumberFormatException("cannot combine '"+timeString+"' with '"+num+" "+s+"'"); + } + } + return d*multiplier + dd; + } + } - /** - * Parses the given date, accepting either a UTC timestamp (i.e. a long), or a formatted date. - * @param dateString - * @param format - * @return - */ + /** + * Parses the given date, accepting either a UTC timestamp (i.e. a long), or a formatted date. + * @param dateString + * @param format + * @return + */ public static Date parseDateString(String dateString, DateFormat format) { if (dateString == null) throw new NumberFormatException("GeneralHelper.parseDateString cannot parse a null string"); http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/a2da61d1/utils/common/src/test/java/brooklyn/util/internal/CommandLineUtilTest.java ---------------------------------------------------------------------- diff --git a/utils/common/src/test/java/brooklyn/util/internal/CommandLineUtilTest.java b/utils/common/src/test/java/brooklyn/util/internal/CommandLineUtilTest.java index bac53da..642ef7b 100644 --- a/utils/common/src/test/java/brooklyn/util/internal/CommandLineUtilTest.java +++ b/utils/common/src/test/java/brooklyn/util/internal/CommandLineUtilTest.java @@ -31,35 +31,35 @@ import com.google.common.collect.Lists; public class CommandLineUtilTest { - @Test - public void testGetCommandReturnsDefaultIfNotPresent() throws Exception { - List args = Lists.newArrayList("k1", "v1"); - String result = CommandLineUtil.getCommandLineOption(args, "notthere", "mydefault"); - assertEquals(result, "mydefault"); - assertEquals(args, Arrays.asList("k1", "v1")); - } - - @Test - public void testGetCommandReturnsParamAndRemovesIt() throws Exception { - List args = Lists.newArrayList("k1", "v1"); - String result = CommandLineUtil.getCommandLineOption(args, "k1"); - assertEquals(result, "v1"); - assertEquals(args, Arrays.asList()); - } - - @Test - public void testGetCommandReturnsParamAndRemovesItButLeavesOtherVals() throws Exception { - List args = Lists.newArrayList("k1", "v1", "k2", "v2"); - String result = CommandLineUtil.getCommandLineOption(args, "k1"); - assertEquals(result, "v1"); - assertEquals(args, Arrays.asList("k2", "v2")); - } - - @Test - public void testGetCommandReturnsParamAndRemovesItButLeavesOtherValsWhenDuplicateVals() throws Exception { - List args = Lists.newArrayList("k1", "vdup", "k2", "v2", "k3", "vdup"); - String result = CommandLineUtil.getCommandLineOption(args, "k3"); - assertEquals(result, "vdup"); - assertEquals(args, Arrays.asList("k1", "vdup", "k2", "v2")); - } + @Test + public void testGetCommandReturnsDefaultIfNotPresent() throws Exception { + List args = Lists.newArrayList("k1", "v1"); + String result = CommandLineUtil.getCommandLineOption(args, "notthere", "mydefault"); + assertEquals(result, "mydefault"); + assertEquals(args, Arrays.asList("k1", "v1")); + } + + @Test + public void testGetCommandReturnsParamAndRemovesIt() throws Exception { + List args = Lists.newArrayList("k1", "v1"); + String result = CommandLineUtil.getCommandLineOption(args, "k1"); + assertEquals(result, "v1"); + assertEquals(args, Arrays.asList()); + } + + @Test + public void testGetCommandReturnsParamAndRemovesItButLeavesOtherVals() throws Exception { + List args = Lists.newArrayList("k1", "v1", "k2", "v2"); + String result = CommandLineUtil.getCommandLineOption(args, "k1"); + assertEquals(result, "v1"); + assertEquals(args, Arrays.asList("k2", "v2")); + } + + @Test + public void testGetCommandReturnsParamAndRemovesItButLeavesOtherValsWhenDuplicateVals() throws Exception { + List args = Lists.newArrayList("k1", "vdup", "k2", "v2", "k3", "vdup"); + String result = CommandLineUtil.getCommandLineOption(args, "k3"); + assertEquals(result, "vdup"); + assertEquals(args, Arrays.asList("k1", "vdup", "k2", "v2")); + } } http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/a2da61d1/utils/common/src/test/java/brooklyn/util/repeat/RepeaterTest.java ---------------------------------------------------------------------- diff --git a/utils/common/src/test/java/brooklyn/util/repeat/RepeaterTest.java b/utils/common/src/test/java/brooklyn/util/repeat/RepeaterTest.java index 1109dec..1be68dd 100644 --- a/utils/common/src/test/java/brooklyn/util/repeat/RepeaterTest.java +++ b/utils/common/src/test/java/brooklyn/util/repeat/RepeaterTest.java @@ -217,18 +217,18 @@ public class RepeaterTest { @Test public void testNoRethrowsException() { try { - boolean result = new Repeater("throwRuntimeException") - .every(Duration.millis(10)) - .until(callableThrowingUnsupportedFail()) - .limitIterationsTo(2) - .run(); - assertFalse(result); + boolean result = new Repeater("throwRuntimeException") + .every(Duration.millis(10)) + .until(callableThrowingUnsupportedFail()) + .limitIterationsTo(2) + .run(); + assertFalse(result); } catch (RuntimeException re) { fail("Exception should not have been thrown: " + re.getMessage()); } } - - private static Callable callableThrowingUnsupportedFail() { + + private static Callable callableThrowingUnsupportedFail() { return new Callable() { @Override public Boolean call() throws Exception { @@ -236,5 +236,5 @@ public class RepeaterTest { } }; } - + } http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/a2da61d1/utils/common/src/test/java/brooklyn/util/text/StringEscapesTest.java ---------------------------------------------------------------------- diff --git a/utils/common/src/test/java/brooklyn/util/text/StringEscapesTest.java b/utils/common/src/test/java/brooklyn/util/text/StringEscapesTest.java index a9a83b2..3b326b6 100644 --- a/utils/common/src/test/java/brooklyn/util/text/StringEscapesTest.java +++ b/utils/common/src/test/java/brooklyn/util/text/StringEscapesTest.java @@ -33,19 +33,19 @@ public class StringEscapesTest { } - @Test - public void testBashEscaping() { - Assert.assertEquals( - BashStringEscapes.doubleQuoteLiteralsForBash("-Dname=Bob Johnson", "-Dnet.worth=$100"), - "\"-Dname=Bob Johnson\" \"-Dnet.worth=\\$100\""); - } + @Test + public void testBashEscaping() { + Assert.assertEquals( + BashStringEscapes.doubleQuoteLiteralsForBash("-Dname=Bob Johnson", "-Dnet.worth=$100"), + "\"-Dname=Bob Johnson\" \"-Dnet.worth=\\$100\""); + } - @Test - public void testBashEscapable() { - Assert.assertTrue(BashStringEscapes.isValidForDoubleQuotingInBash("Bob Johnson")); - Assert.assertFalse(BashStringEscapes.isValidForDoubleQuotingInBash("\"")); - Assert.assertTrue(BashStringEscapes.isValidForDoubleQuotingInBash("\\\"")); - } + @Test + public void testBashEscapable() { + Assert.assertTrue(BashStringEscapes.isValidForDoubleQuotingInBash("Bob Johnson")); + Assert.assertFalse(BashStringEscapes.isValidForDoubleQuotingInBash("\"")); + Assert.assertTrue(BashStringEscapes.isValidForDoubleQuotingInBash("\\\"")); + } /** Bash handles ampersand in double quoted strings without escaping. */ @Test http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/a2da61d1/utils/common/src/test/java/brooklyn/util/text/WildcardGlobsTest.java ---------------------------------------------------------------------- diff --git a/utils/common/src/test/java/brooklyn/util/text/WildcardGlobsTest.java b/utils/common/src/test/java/brooklyn/util/text/WildcardGlobsTest.java index 95aee44..1417cfe 100644 --- a/utils/common/src/test/java/brooklyn/util/text/WildcardGlobsTest.java +++ b/utils/common/src/test/java/brooklyn/util/text/WildcardGlobsTest.java @@ -32,205 +32,205 @@ import brooklyn.util.text.WildcardGlobs.SpecialistGlobExpander; public class WildcardGlobsTest extends Assert { @Test - public void testBasic() throws InvalidPatternException { - assertTrue(WildcardGlobs.isGlobMatched("a?{ex,in}", "akin")); - assertTrue(WildcardGlobs.isGlobMatched("a?{ex,in}", "alex")); - assertFalse(WildcardGlobs.isGlobMatched("a?{ex,in}", "appin")); - } - - @Test - public void testEmpty() throws InvalidPatternException { - assertTrue(WildcardGlobs.isGlobMatched("a{,?}{,b}", "a")); - assertTrue(WildcardGlobs.isGlobMatched("a{,?}{,b}", "ab")); - assertTrue(WildcardGlobs.isGlobMatched("a{,?}{,b}", "ac")); - assertTrue(WildcardGlobs.isGlobMatched("a{,?}{,b}", "acb")); - assertFalse(WildcardGlobs.isGlobMatched("a{,?}{,b}", "abc")); - assertFalse(WildcardGlobs.isGlobMatched("a{,?}{,b}", "accb")); - } - - @Test - public void testNum() throws InvalidPatternException { - assertTrue(newGlobExpander().isGlobMatchedNumeric("{1-3}", "1")); - assertTrue(newGlobExpander().isGlobMatchedNumeric("a{1-3}", "a1")); - assertTrue(newGlobExpander().isGlobMatchedNumeric("a{1-3,5}", "a1")); - assertTrue(newGlobExpander().isGlobMatchedNumeric("a{1-3,5}", "a3")); - assertTrue(newGlobExpander().isGlobMatchedNumeric("a{1-3,5}", "a5")); - assertFalse(newGlobExpander().isGlobMatchedNumeric("a{1-3,5}", "a4")); - assertFalse(newGlobExpander().isGlobMatchedNumeric("a{1-3,5}", "a01")); - } - - @Test - public void testNumLeadZero() throws InvalidPatternException { - assertTrue(newGlobExpander().isGlobMatchedNumeric("a{01-03,05}", "a01")); - assertTrue(newGlobExpander().isGlobMatchedNumeric("a{ 01 - 03 , 05 }", "a01")); - assertTrue(newGlobExpander().isGlobMatchedNumeric("a{ 01 - 03 , 05 }", "a02")); - assertTrue(newGlobExpander().isGlobMatchedNumeric("a{ 01 - 03 , 05 }", "a03")); - assertTrue(newGlobExpander().isGlobMatchedNumeric("a{ 01 - 03 , 05 }", "a 05 ")); - assertTrue(newGlobExpander().isGlobMatchedNumeric("a{01-03,05}", "a05")); - assertFalse(newGlobExpander().isGlobMatchedNumeric("a{01-03,05}", "a04")); - assertFalse(newGlobExpander().isGlobMatchedNumeric("a{01-03,05}", "a3")); - } - - @Test - public void testOrder() throws InvalidPatternException { - List result; - result = newGlobExpander().expand("{a,b}"); - assertEquals(result, Arrays.asList("a","b"), "Expansion was "+result); - result = newGlobExpander().expand("{{a},b}"); - assertEquals(result, Arrays.asList("a","b"), "Expansion was "+result); + public void testBasic() throws InvalidPatternException { + assertTrue(WildcardGlobs.isGlobMatched("a?{ex,in}", "akin")); + assertTrue(WildcardGlobs.isGlobMatched("a?{ex,in}", "alex")); + assertFalse(WildcardGlobs.isGlobMatched("a?{ex,in}", "appin")); + } + + @Test + public void testEmpty() throws InvalidPatternException { + assertTrue(WildcardGlobs.isGlobMatched("a{,?}{,b}", "a")); + assertTrue(WildcardGlobs.isGlobMatched("a{,?}{,b}", "ab")); + assertTrue(WildcardGlobs.isGlobMatched("a{,?}{,b}", "ac")); + assertTrue(WildcardGlobs.isGlobMatched("a{,?}{,b}", "acb")); + assertFalse(WildcardGlobs.isGlobMatched("a{,?}{,b}", "abc")); + assertFalse(WildcardGlobs.isGlobMatched("a{,?}{,b}", "accb")); + } + + @Test + public void testNum() throws InvalidPatternException { + assertTrue(newGlobExpander().isGlobMatchedNumeric("{1-3}", "1")); + assertTrue(newGlobExpander().isGlobMatchedNumeric("a{1-3}", "a1")); + assertTrue(newGlobExpander().isGlobMatchedNumeric("a{1-3,5}", "a1")); + assertTrue(newGlobExpander().isGlobMatchedNumeric("a{1-3,5}", "a3")); + assertTrue(newGlobExpander().isGlobMatchedNumeric("a{1-3,5}", "a5")); + assertFalse(newGlobExpander().isGlobMatchedNumeric("a{1-3,5}", "a4")); + assertFalse(newGlobExpander().isGlobMatchedNumeric("a{1-3,5}", "a01")); + } + + @Test + public void testNumLeadZero() throws InvalidPatternException { + assertTrue(newGlobExpander().isGlobMatchedNumeric("a{01-03,05}", "a01")); + assertTrue(newGlobExpander().isGlobMatchedNumeric("a{ 01 - 03 , 05 }", "a01")); + assertTrue(newGlobExpander().isGlobMatchedNumeric("a{ 01 - 03 , 05 }", "a02")); + assertTrue(newGlobExpander().isGlobMatchedNumeric("a{ 01 - 03 , 05 }", "a03")); + assertTrue(newGlobExpander().isGlobMatchedNumeric("a{ 01 - 03 , 05 }", "a 05 ")); + assertTrue(newGlobExpander().isGlobMatchedNumeric("a{01-03,05}", "a05")); + assertFalse(newGlobExpander().isGlobMatchedNumeric("a{01-03,05}", "a04")); + assertFalse(newGlobExpander().isGlobMatchedNumeric("a{01-03,05}", "a3")); + } + + @Test + public void testOrder() throws InvalidPatternException { + List result; + result = newGlobExpander().expand("{a,b}"); + assertEquals(result, Arrays.asList("a","b"), "Expansion was "+result); + result = newGlobExpander().expand("{{a},b}"); + assertEquals(result, Arrays.asList("a","b"), "Expansion was "+result); result = newGlobExpander().expand("{a,b}{1,2}"); assertEquals(result, Arrays.asList("a1","a2","b1","b2"), "Expansion was "+result); - result = newGlobExpander().expand("{80{8{1,2},90},8000+}"); - assertEquals(result, Arrays.asList("8081","8082","8090","8000+"), "Expansion was "+result); - } - - @Test - public void testQuotes() throws InvalidPatternException { - List result; - SpecialistGlobExpander notSpecial = new SpecialistGlobExpander(true, PhraseTreatment.NOT_A_SPECIAL_CHAR, PhraseTreatment.NOT_A_SPECIAL_CHAR); - result = notSpecial.expand("hello \"{1-3}\""); - assertEquals(3, result.size()); - assertEquals("hello \"1\"", result.get(0)); - - SpecialistGlobExpander expanding = new SpecialistGlobExpander(true, PhraseTreatment.INTERIOR_EXPANDABLE, PhraseTreatment.NOT_A_SPECIAL_CHAR); - result = expanding.expand("hello \"{1-3}\""); - assertEquals(3, result.size()); - assertEquals("hello \"1\"", result.get(0)); - result = expanding.expand("hello \"{1,2-3}\""); - assertEquals(3, result.size()); - assertEquals("hello \"2\"", result.get(1)); - - SpecialistGlobExpander notExpanding = new SpecialistGlobExpander(true, PhraseTreatment.INTERIOR_NOT_EXPANDABLE, PhraseTreatment.NOT_A_SPECIAL_CHAR); - result = notExpanding.expand("hello \"{1,2-3}\""); - assertEquals(1, result.size()); - assertEquals("hello \"{1,2-3}\"", result.get(0)); - - - result = notSpecial.expand("hello {\"1,2,3\"}"); - assertEquals(3, result.size()); - assertEquals("hello \"1", result.get(0)); - - result = expanding.expand("hello {\"1,2,3\"}"); - assertEquals(1, result.size()); - assertEquals("hello \"1,2,3\"", result.get(0)); - - result = notExpanding.expand("hello {\"1,2,3\"}"); - assertEquals(1, result.size()); - assertEquals("hello \"1,2,3\"", result.get(0)); - - - result = notSpecial.expand("hello {\"1,{02-03,04}\"}"); - assertEquals(4, result.size()); - assertEquals("hello \"1", result.get(0)); - assertEquals("hello 03\"", result.get(2)); - - result = expanding.expand("hello {\"1,{02-03,04}\"}"); - assertEquals(3, result.size()); - assertEquals("hello \"1,02\"", result.get(0)); - - result = notExpanding.expand("hello {\"1,{02-03,04}\"}"); - assertEquals(1, result.size()); - assertEquals("hello \"1,{02-03,04}\"", result.get(0)); - - //no exception - notSpecial.expand("{\"}"); - notSpecial.expand("\"{\"}"); - //exceptions - try { - expanding.expand("\""); - fail("exception expected"); - } catch (InvalidPatternException e) { /* expected */ } - try { - expanding.expand("{\"}"); - fail("exception expected"); - } catch (InvalidPatternException e) { /* expected */ } - try { - expanding.expand("\"{\""); - fail("exception expected"); - } catch (InvalidPatternException e) { /* expected */ } - try { - notExpanding.expand("\""); - fail("exception expected"); - } catch (InvalidPatternException e) { /* expected */ } - try { - notExpanding.expand("{\"}"); - fail("exception expected"); - } catch (InvalidPatternException e) { /* expected */ } - //no exception - notExpanding.expand("\"{\""); - } - - @Test - public void testParen() throws InvalidPatternException { - List result; - SpecialistGlobExpander notSpecial = new SpecialistGlobExpander(true, PhraseTreatment.NOT_A_SPECIAL_CHAR, PhraseTreatment.NOT_A_SPECIAL_CHAR); - result = notSpecial.expand("hello ({1-3})"); - assertEquals(3, result.size()); - assertEquals("hello (1)", result.get(0)); - - SpecialistGlobExpander expanding = new SpecialistGlobExpander(true, PhraseTreatment.INTERIOR_NOT_EXPANDABLE, PhraseTreatment.INTERIOR_EXPANDABLE); - result = expanding.expand("hello ({1-3})"); - assertEquals(3, result.size()); - assertEquals("hello (1)", result.get(0)); - result = expanding.expand("hello ({1,2-3})"); - assertEquals(3, result.size()); - assertEquals("hello (2)", result.get(1)); - - SpecialistGlobExpander notExpanding = new SpecialistGlobExpander(true, PhraseTreatment.INTERIOR_EXPANDABLE, PhraseTreatment.INTERIOR_NOT_EXPANDABLE); - result = notExpanding.expand("hello ({1,2-3})"); - assertEquals(1, result.size()); - assertEquals("hello ({1,2-3})", result.get(0)); - - result = notSpecial.expand("hello {(1,2,3)}"); - assertEquals(3, result.size()); - assertEquals("hello (1", result.get(0)); - - result = expanding.expand("hello {(1,2,3)}"); - assertEquals(1, result.size()); - assertEquals("hello (1,2,3)", result.get(0)); - - result = notExpanding.expand("hello {(1,2,3)}"); - assertEquals(1, result.size()); - assertEquals("hello (1,2,3)", result.get(0)); - - - result = notSpecial.expand("hello {(1,{02-03,04})}"); - assertEquals(4, result.size()); - assertEquals("hello (1", result.get(0)); - assertEquals("hello 03)", result.get(2)); - - result = expanding.expand("hello {(1,{02-03,04})}"); - assertEquals(3, result.size()); - assertEquals("hello (1,02)", result.get(0)); - - result = notExpanding.expand("hello {(1,{02-03,04})}"); - assertEquals(1, result.size()); - assertEquals("hello (1,{02-03,04})", result.get(0)); - - try { - notExpanding.expand("{(}"); - fail("exception expected"); - } catch (InvalidPatternException e) { /* expected */ } - try { - notExpanding.expand("(()"); - fail("exception expected"); - } catch (InvalidPatternException e) { /* expected */ } - notExpanding.expand("({())"); - } - - @Test - public void testQuotesAndParen() throws InvalidPatternException { - List result; - SpecialistGlobExpander special = new SpecialistGlobExpander(true, PhraseTreatment.INTERIOR_EXPANDABLE, PhraseTreatment.INTERIOR_NOT_EXPANDABLE); - result = special.expand("\"{hello,goodbye}{1-2,({3-4}),(\")}\""); - assertEquals(8, result.size()); - assertTrue(result.contains("\"goodbye2\"")); - assertTrue(result.contains("\"hello({3-4})\"")); - assertTrue(result.contains("\"goodbye(\")\"")); - } - - private SpecialistGlobExpander newGlobExpander() { - return new SpecialistGlobExpander(true, PhraseTreatment.NOT_A_SPECIAL_CHAR, PhraseTreatment.NOT_A_SPECIAL_CHAR); - } + result = newGlobExpander().expand("{80{8{1,2},90},8000+}"); + assertEquals(result, Arrays.asList("8081","8082","8090","8000+"), "Expansion was "+result); + } + + @Test + public void testQuotes() throws InvalidPatternException { + List result; + SpecialistGlobExpander notSpecial = new SpecialistGlobExpander(true, PhraseTreatment.NOT_A_SPECIAL_CHAR, PhraseTreatment.NOT_A_SPECIAL_CHAR); + result = notSpecial.expand("hello \"{1-3}\""); + assertEquals(3, result.size()); + assertEquals("hello \"1\"", result.get(0)); + + SpecialistGlobExpander expanding = new SpecialistGlobExpander(true, PhraseTreatment.INTERIOR_EXPANDABLE, PhraseTreatment.NOT_A_SPECIAL_CHAR); + result = expanding.expand("hello \"{1-3}\""); + assertEquals(3, result.size()); + assertEquals("hello \"1\"", result.get(0)); + result = expanding.expand("hello \"{1,2-3}\""); + assertEquals(3, result.size()); + assertEquals("hello \"2\"", result.get(1)); + + SpecialistGlobExpander notExpanding = new SpecialistGlobExpander(true, PhraseTreatment.INTERIOR_NOT_EXPANDABLE, PhraseTreatment.NOT_A_SPECIAL_CHAR); + result = notExpanding.expand("hello \"{1,2-3}\""); + assertEquals(1, result.size()); + assertEquals("hello \"{1,2-3}\"", result.get(0)); + + + result = notSpecial.expand("hello {\"1,2,3\"}"); + assertEquals(3, result.size()); + assertEquals("hello \"1", result.get(0)); + + result = expanding.expand("hello {\"1,2,3\"}"); + assertEquals(1, result.size()); + assertEquals("hello \"1,2,3\"", result.get(0)); + + result = notExpanding.expand("hello {\"1,2,3\"}"); + assertEquals(1, result.size()); + assertEquals("hello \"1,2,3\"", result.get(0)); + + + result = notSpecial.expand("hello {\"1,{02-03,04}\"}"); + assertEquals(4, result.size()); + assertEquals("hello \"1", result.get(0)); + assertEquals("hello 03\"", result.get(2)); + + result = expanding.expand("hello {\"1,{02-03,04}\"}"); + assertEquals(3, result.size()); + assertEquals("hello \"1,02\"", result.get(0)); + + result = notExpanding.expand("hello {\"1,{02-03,04}\"}"); + assertEquals(1, result.size()); + assertEquals("hello \"1,{02-03,04}\"", result.get(0)); + + //no exception + notSpecial.expand("{\"}"); + notSpecial.expand("\"{\"}"); + //exceptions + try { + expanding.expand("\""); + fail("exception expected"); + } catch (InvalidPatternException e) { /* expected */ } + try { + expanding.expand("{\"}"); + fail("exception expected"); + } catch (InvalidPatternException e) { /* expected */ } + try { + expanding.expand("\"{\""); + fail("exception expected"); + } catch (InvalidPatternException e) { /* expected */ } + try { + notExpanding.expand("\""); + fail("exception expected"); + } catch (InvalidPatternException e) { /* expected */ } + try { + notExpanding.expand("{\"}"); + fail("exception expected"); + } catch (InvalidPatternException e) { /* expected */ } + //no exception + notExpanding.expand("\"{\""); + } + + @Test + public void testParen() throws InvalidPatternException { + List result; + SpecialistGlobExpander notSpecial = new SpecialistGlobExpander(true, PhraseTreatment.NOT_A_SPECIAL_CHAR, PhraseTreatment.NOT_A_SPECIAL_CHAR); + result = notSpecial.expand("hello ({1-3})"); + assertEquals(3, result.size()); + assertEquals("hello (1)", result.get(0)); + + SpecialistGlobExpander expanding = new SpecialistGlobExpander(true, PhraseTreatment.INTERIOR_NOT_EXPANDABLE, PhraseTreatment.INTERIOR_EXPANDABLE); + result = expanding.expand("hello ({1-3})"); + assertEquals(3, result.size()); + assertEquals("hello (1)", result.get(0)); + result = expanding.expand("hello ({1,2-3})"); + assertEquals(3, result.size()); + assertEquals("hello (2)", result.get(1)); + + SpecialistGlobExpander notExpanding = new SpecialistGlobExpander(true, PhraseTreatment.INTERIOR_EXPANDABLE, PhraseTreatment.INTERIOR_NOT_EXPANDABLE); + result = notExpanding.expand("hello ({1,2-3})"); + assertEquals(1, result.size()); + assertEquals("hello ({1,2-3})", result.get(0)); + + result = notSpecial.expand("hello {(1,2,3)}"); + assertEquals(3, result.size()); + assertEquals("hello (1", result.get(0)); + + result = expanding.expand("hello {(1,2,3)}"); + assertEquals(1, result.size()); + assertEquals("hello (1,2,3)", result.get(0)); + + result = notExpanding.expand("hello {(1,2,3)}"); + assertEquals(1, result.size()); + assertEquals("hello (1,2,3)", result.get(0)); + + + result = notSpecial.expand("hello {(1,{02-03,04})}"); + assertEquals(4, result.size()); + assertEquals("hello (1", result.get(0)); + assertEquals("hello 03)", result.get(2)); + + result = expanding.expand("hello {(1,{02-03,04})}"); + assertEquals(3, result.size()); + assertEquals("hello (1,02)", result.get(0)); + + result = notExpanding.expand("hello {(1,{02-03,04})}"); + assertEquals(1, result.size()); + assertEquals("hello (1,{02-03,04})", result.get(0)); + + try { + notExpanding.expand("{(}"); + fail("exception expected"); + } catch (InvalidPatternException e) { /* expected */ } + try { + notExpanding.expand("(()"); + fail("exception expected"); + } catch (InvalidPatternException e) { /* expected */ } + notExpanding.expand("({())"); + } + + @Test + public void testQuotesAndParen() throws InvalidPatternException { + List result; + SpecialistGlobExpander special = new SpecialistGlobExpander(true, PhraseTreatment.INTERIOR_EXPANDABLE, PhraseTreatment.INTERIOR_NOT_EXPANDABLE); + result = special.expand("\"{hello,goodbye}{1-2,({3-4}),(\")}\""); + assertEquals(8, result.size()); + assertTrue(result.contains("\"goodbye2\"")); + assertTrue(result.contains("\"hello({3-4})\"")); + assertTrue(result.contains("\"goodbye(\")\"")); + } + + private SpecialistGlobExpander newGlobExpander() { + return new SpecialistGlobExpander(true, PhraseTreatment.NOT_A_SPECIAL_CHAR, PhraseTreatment.NOT_A_SPECIAL_CHAR); + } } http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/a2da61d1/utils/jmx/jmxrmi-agent/src/main/java/brooklyn/util/jmx/jmxrmi/JmxRmiAgent.java ---------------------------------------------------------------------- diff --git a/utils/jmx/jmxrmi-agent/src/main/java/brooklyn/util/jmx/jmxrmi/JmxRmiAgent.java b/utils/jmx/jmxrmi-agent/src/main/java/brooklyn/util/jmx/jmxrmi/JmxRmiAgent.java index b504ae7..089de45 100644 --- a/utils/jmx/jmxrmi-agent/src/main/java/brooklyn/util/jmx/jmxrmi/JmxRmiAgent.java +++ b/utils/jmx/jmxrmi-agent/src/main/java/brooklyn/util/jmx/jmxrmi/JmxRmiAgent.java @@ -170,8 +170,8 @@ public class JmxRmiAgent { String hostname = properties == null ? null : properties.getProperty(RMI_HOSTNAME_PROPERTY); if ("0.0.0.0".equals(hostname)) { System.err.println("WARN: invalid hostname 0.0.0.0 specified for JmxRmiAgent; " + - "it typically must be an address or hostname which is bindable on the machine where " + - "this service is running AND accessible by a client machine (access will likely be impossible)"); + "it typically must be an address or hostname which is bindable on the machine where " + + "this service is running AND accessible by a client machine (access will likely be impossible)"); } if (hostname == null || hostname.isEmpty()) { hostname = InetAddress.getLocalHost().getHostName(); http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/a2da61d1/utils/test-support/src/main/java/brooklyn/test/StatusListener.java ---------------------------------------------------------------------- diff --git a/utils/test-support/src/main/java/brooklyn/test/StatusListener.java b/utils/test-support/src/main/java/brooklyn/test/StatusListener.java index 85a7b2f..ec044e9 100644 --- a/utils/test-support/src/main/java/brooklyn/test/StatusListener.java +++ b/utils/test-support/src/main/java/brooklyn/test/StatusListener.java @@ -35,9 +35,9 @@ import org.testng.ITestResult; * normally not used, preferring instead LoggingVerboseReporter which prints out config info */ public class StatusListener implements ITestListener { - - public static final Logger log = LoggerFactory.getLogger(StatusListener.class); - + + public static final Logger log = LoggerFactory.getLogger(StatusListener.class); + /** * Holds test classes actually running in all threads. */ @@ -50,7 +50,7 @@ public class StatusListener implements ITestListener { //TODO instead of system.out.println we should log -- *and* perhaps write to sysout if logger doesn't? protected static void log(String msg) { - log.info(msg); + log.info(msg); } public void onTestStart(ITestResult res) {