Github user revans2 commented on a diff in the pull request:

    https://github.com/apache/storm/pull/1043#discussion_r50898645
  
    --- Diff: storm-core/src/jvm/org/apache/storm/utils/Utils.java ---
    @@ -1382,5 +1422,438 @@ public static TopologyInfo getTopologyInfo(String 
name, String asUser, Map storm
         public static int toPositive(int number) {
             return number & Integer.MAX_VALUE;
         }
    -}
     
    +
    +
    +    //Everything from here on is translated from the old util.clj 
(storm-core/src/clj/backtype.storm/util.clj)
    +
    +    //Wraps an exception in a RuntimeException if needed
    +    public static Exception wrapInRuntime (Exception e) {
    +        if (e instanceof RuntimeException) {
    +            return e;
    +        } else {
    +            return (new RuntimeException(e));
    +        }
    +    }
    +
    +    public static final boolean isOnWindows = 
"Windows_NT".equals(System.getenv("OS"));
    +
    +    public static final String filePathSeparator = 
System.getProperty("file.separator");
    +
    +    public static final String classPathSeparator = 
System.getProperty("path.separator");
    +
    +
    +    /*
    +        Returns the first item of coll for which (pred item) returns 
logical true.
    +        Consumes sequences up to the first match, will consume the entire 
sequence
    +        and return nil if no match is found.
    +     */
    +    public static Object findFirst (IPredicate pred, Collection coll) {
    +        if (coll == null || pred == null) {
    +            return null;
    +        } else {
    +            Iterator<Object> iter = coll.iterator();
    +            if (iter==null || !iter.hasNext()) {
    +                return null;
    +            } else {
    +                do {
    +                    Object obj = iter.next();
    +                    if (pred.test(obj)) {
    +                        return obj;
    +                    }
    +                } while (iter.hasNext());
    +                return null;
    +            }
    +        }
    +    }
    +
    +    public static Object findFirst (IPredicate pred, Map map) {
    +        if (map == null || pred == null) {
    +            return null;
    +        } else {
    +            Iterator<Object> iter = map.entrySet().iterator();
    +            if (iter==null || !iter.hasNext()) {
    +                return null;
    +            } else {
    +                do {
    +                    Object obj = iter.next();
    +                    if (pred.test(obj)) {
    +                        return obj;
    +                    }
    +                } while (iter.hasNext());
    +                return null;
    +            }
    +        }
    +    }
    +    /*
    +        Note: since the following functions are nowhere used in Storm, 
they were not translated:
    +        dissoc-in
    +        indexed
    +        positions
    +        assoc-conj
    +        set-delta
    +
    +        clojurify-structure  because it wouldn't make sense without clojure
    +     */
    +
    +
    +    public static String localHostname () throws UnknownHostException {
    +        return _instance.localHostnameImpl();
    +    }
    +
    +    protected String localHostnameImpl () throws UnknownHostException {
    +        return InetAddress.getLocalHost().getCanonicalHostName();
    +    }
    +
    +    private static String memoizedLocalHostnameString = null;
    +
    +    public static String memoizedLocalHostname () throws 
UnknownHostException {
    +        if (memoizedLocalHostnameString == null) {
    +            memoizedLocalHostnameString = localHostname();
    +        }
    +        return memoizedLocalHostnameString;
    +    }
    +
    +    /*
    +        checks conf for STORM_LOCAL_HOSTNAME.
    +        when unconfigured, falls back to (memoized) guess by 
`local-hostname`.
    +    */
    +    public static String hostname (Map<String, Object> conf) throws 
UnknownHostException  {
    +        if (conf == null) {
    +            return memoizedLocalHostname();
    +        }
    +        Object hostnameString = conf.get(Config.STORM_LOCAL_HOSTNAME);
    +        if (hostnameString == null ) {
    +            return memoizedLocalHostname();
    +        }
    +        if (hostnameString.equals("")) {
    +            return memoizedLocalHostname();
    +        }
    +        return hostnameString.toString();
    +    }
    +
    +    public static String uuid() {
    +        return UUID.randomUUID().toString();
    +    }
    +
    +    public static int currentTimeSecs() {
    +        return Time.currentTimeSecs();
    +    }
    +
    +    public static long currentTimeMillis() {
    +        return Time.currentTimeMillis();
    +    }
    +
    +    public static long secsToMillisLong(double secs) {
    +        return (long) (1000 * secs);
    +    }
    +
    +    public static Vector<String> tokenizePath (String path) {
    +        String[] tokens = path.split("/");
    +        Vector<String> outputs = new Vector<String>();
    +        if (tokens == null || tokens.length == 0) {
    +            return null;
    +        }
    +        for (String tok: tokens) {
    +            if (!tok.isEmpty()) {
    +                outputs.add(tok);
    +            }
    +        }
    +        return outputs;
    +    }
    +
    +    public static String parentPath(String path) {
    +        if (path == null) {
    +            return "/";
    +        }
    +        Vector<String> tokens = tokenizePath(path);
    +        int length = tokens.size();
    +        if (length == 0) {
    +            return "/";
    +        }
    +        String output = "";
    +        for (int i = 0; i < length - 1; i++) {  //length - 1 to mimic 
"butlast" from the old clojure code
    +            output = output + "/" + tokens.get(i);
    +        }
    +        return output;
    +    }
    +
    +    public static String toksToPath (Vector<String> toks) {
    +        if (toks == null) {
    +            return "/";
    +        }
    +        int length = toks.size();
    +        if (length == 0) {
    +            return "/";
    +        }
    +        String output = "";
    +        for (int i = 0; i < length; i++) {
    +            output = output + "/" + toks.get(i);
    +        }
    +        return output;
    +    }
    +    public static String normalizePath (String path) {
    +        return toksToPath(tokenizePath(path));
    +    }
    +
    +    /* TODO: This function was originally written to replace map-val in 
util.clj. But we decided to change the coding
    +             style in the caller functions to a more Java style for loop. 
This is mentioned in TODOs across the clojure
    +             files.
    +     */
    +    public static Map mapVal (IFn aFn, Map amap) {
    +        Map newMap = new HashMap();
    +        if (amap == null) {
    +            return newMap;
    +        }
    +        if (amap.keySet()==null) {
    +            return newMap;
    +        }
    +        for (Object key: amap.keySet()) {
    +            Object value = amap.get(key);
    +            if (value == null) {
    +                newMap.put(key, null);
    +            } else {
    +                Object newValue = aFn.eval(value);
    +                newMap.put(key, newValue);
    +            }
    +        }
    +        return newMap;
    +    }
    +
    +    /* TODO: This function was originally written to replace map-val in 
util.clj. But we decided to change the coding
    +         style in the caller functions to a more Java style for loop. This 
is mentioned in TODOs across the clojure
    +         files.
    +    */
    +//    public static Map filterVal(IPredicate aFn, Map amap) {
    +//        Map newMap = new HashMap();
    +//        if (amap == null) {
    +//            return newMap;
    +//        }
    +//        for (Object key: amap.keySet()) {
    +//            Object value = amap.get(key);
    +//            if(aFn.test(value)) {
    +//                newMap.put(key, value);
    +//            }
    +//        }
    +//        return newMap;
    +//    }
    +
    +    /* TODO: This function was originally written to replace filter-key in 
util.clj. But we decided to change the coding
    +         style in the caller functions to a more Java style for loop + if 
conditionals. This is mentioned in TODOs
    +         across the clojure files.
    +    */
    +//    public static Map filterKey(IPredicate aFn, Map amap) {
    +//        Map newMap = new HashMap();
    +//        if (amap == null) {
    +//            return newMap;
    +//        }
    +//        for (Object key: amap.keySet()) {
    +//            Object value = amap.get(key);
    +//            if(aFn.test(key)) {
    +//                newMap.put(key, value);
    +//            }
    +//        }
    +//        return newMap;
    +//    }
    +
    +    /* TODO: This function was originally written to replace map-key in 
util.clj. But we decided to change the coding
    +         style in the caller functions to a more Java style for loop. This 
is mentioned in TODOs across the clojure
    +         files.
    +    */
    +//    public static Map mapKey (IFn aFn, Map amap) {
    +//        Map newMap = new HashMap();
    +//        if (amap == null) {
    +//            return newMap;
    +//        }
    +//        for (Object key: amap.keySet()) {
    +//            Object value = amap.get(key);
    +//            Object newKey = aFn.eval(key);
    +//            newMap.put(newKey, value);
    +//        }
    +//        return newMap;
    +//    }
    +
    +    /* TODO: This function was originally written to replace separate in 
util.clj. But since it was only used in
    +    transactional_test.clj, the separate function was moved there for now.
    +    */
    +    public static Vector<Collection> separate (IPredicate pred, Collection 
aseq) {
    +        Vector<Collection> outputVector = new Vector<Collection>();
    +        Collection pass = new HashSet();
    +        Collection notPass = new HashSet();
    +        for (Object obj: aseq) {
    +            if (pred.test(obj)) {
    +                pass.add(obj);
    +            } else {
    +                notPass.add(obj);
    +            }
    +        }
    +        outputVector.add(pass);
    +        outputVector.add(notPass);
    +        return outputVector;
    +    }
    +
    +    public static void exitProcess (int val, Object... msg) {
    +        String combinedErrorMessage = "";
    --- End diff --
    
    Can we please us a StringBuilder here.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to