Java List Permutate permutation(List list1, List list2, String token)

Here you can find the source of permutation(List list1, List list2, String token)

Description

permutation

License

Open Source License

Declaration

public static List<String> permutation(List<String> list1, List<String> list2, String token) 

Method Source Code

//package com.java2s;
/*/*  ww  w.  j av  a  2 s.c  om*/
 * $RCSfile: StringUtil,v $$
 * $Revision: 1.0  $
 * $Date: 2011  $
 *
 * Copyright (C) 2011 GyTech, Inc. All rights reserved.
 *
 * This software is the proprietary information of GyTech, Inc.
 * Use is subject to license terms.
 */

import java.util.ArrayList;
import java.util.List;

public class Main {
    public static final String Empty = "";

    public static List<String> permutation(List<String> list1, List<String> list2, String token) {
        List<String> result = new ArrayList<String>();

        for (String s1 : list1) {
            for (String s2 : list2) {
                StringBuilder sb = new StringBuilder();

                sb.append(s1);

                if (!isEmpty(token)) {
                    sb.append(token);
                }

                sb.append(s2);

                result.add(sb.toString());
            }
        }

        return result;
    }

    /**
    * @param args
    * @return boolean
    */
    public static boolean isEmpty(String... args) {
        if (args != null && args.length > 0) {
            for (String s : args) {
                if (s == null || s.trim().length() == 0) {
                    return true;
                }
            }

            return false;
        }

        return true;
    }

    /**
    * @param b
    * @return String
    * @author: lizj
    */
    public static String toString(boolean b) {
        return Boolean.toString(b);
    }

    /**
    * @param b
    * @return String
    * @author: lizj
    */
    public static String toString(byte b) {
        return Byte.toString(b);
    }

    /**
    * @param b
    * @return String
    * @author: lizj
    */
    public static String toString(char c) {
        return Character.toString(c);
    }

    /**
    * @param s
    * @return String
    * @author: lizj
    */
    public static String toString(short s) {
        return Short.toString(s);
    }

    /**
    * @param i
    * @return String
    * @author: lizj
    */
    public static String toString(int i) {
        return Integer.toString(i);
    }

    /**
    * @param f
    * @return String
    * @author: lizj
    */
    public static String toString(float f) {
        return Float.toString(f);
    }

    /**
    * @param d
    * @return String
    * @author: lizj
    */
    public static String toString(double d) {
        return Double.toString(d);
    }

    /**
    * @param l
    * @return String
    * @author: lizj
    */
    public static String toString(long l) {
        return Long.toString(l);
    }

    /**
    * @param b
    * @return
    * @author: lizj
    */
    public static String toString(Boolean b) {
        return b != null ? b.toString() : Empty;
    }

    /**
    * @param b
    * @return String
    * @author: lizj
    */
    public static String toString(Byte b) {
        return b != null ? b.toString() : Empty;
    }

    /**
    * @param s
    * @return String
    * @author: lizj
    */
    public static String toString(Short s) {
        return s != null ? s.toString() : Empty;
    }

    /**
    * @param c
    * @return String
    * @author: lizj
    */
    public static String toString(Character c) {
        return c != null ? c.toString() : Empty;
    }

    /**
    * @param i
    * @return String
    * @author: lizj
    */
    public static String toString(Integer i) {
        return i != null ? i.toString() : Empty;
    }

    /**
    * @param f
    * @return String
    * @author: lizj
    */
    public static String toString(Float f) {
        return f != null ? f.toString() : Empty;
    }

    /**
    * @param d
    * @return String
    * @author: lizj
    */
    public static String toString(Double d) {
        return d != null ? d.toString() : Empty;
    }

    /**
    * @param l
    * @return String
    * @author: lizj
    */
    public static String toString(Long l) {
        return l != null ? l.toString() : Empty;
    }

    /**
    * @param s
    * @return String
    * @author: lizj
    */
    public static String toString(String s) {
        return s != null ? s : Empty;
    }

    /**
    * @param buf
    * @return String
    * @author: lizj
    */
    public static String toString(StringBuffer buf) {
        return buf != null ? buf.toString() : Empty;
    }

    /**
    * @param b
    * @param defaultValue
    * @return String
    */
    public static String toString(boolean b, String defaultValue) {
        return Boolean.toString(b);
    }

    /**
    * @param b
    * @param defaultValue
    * @return String
    * @author: lizj 
    */
    public static String toString(byte b, String defaultValue) {
        return Byte.toString(b);
    }

    /**
    * @param b
    * @param defaultValue
    * @return String
    * @author: lizj
    */
    public static String toString(char c, String defaultValue) {
        return Character.toString(c);
    }

    /**
    * @param s
    * @param defaultValue
    * @return String
    * @author: lizj
    */
    public static String toString(short s, String defaultValue) {
        return Short.toString(s);
    }

    /**
    * @param i
    * @param defaultValue
    * @return String
    * @author: lizj
    */
    public static String toString(int i, String defaultValue) {
        return Integer.toString(i);
    }

    /**
    * @param f
    * @param defaultValue
    * @return String
    * @author: lizj
    */
    public static String toString(float f, String defaultValue) {
        return Float.toString(f);
    }

    /**
    * @param d
    * @param defaultValue
    * @return String
    * @author: lizj
    */
    public static String toString(double d, String defaultValue) {
        return Double.toString(d);
    }

    /**
    * @param l
    * @param defaultValue
    * @return String
    * @author: lizj
    */
    public static String toString(long l, String defaultValue) {
        return Long.toString(l);
    }

    /**
    * @param b
    * @param defaultValue
    * @return String
    * @author: lizj
    */
    public static String toString(Boolean b, String defaultValue) {
        return (b != null ? b.toString() : defaultValue);
    }

    /**
    * @param b
    * @param defaultValue
    * @return String
    * @author: lizj
    */
    public static String toString(Byte b, String defaultValue) {
        return (b != null ? b.toString() : defaultValue);
    }

    /**
    * @param s
    * @param defaultValue
    * @return String
    * @author: lizj
    */
    public static String toString(Short s, String defaultValue) {
        return (s != null ? s.toString() : defaultValue);
    }

    /**
    * @param c
    * @param defaultValue
    * @return String
    * @author: lizj
    */
    public static String toString(Character c, String defaultValue) {
        return (c != null ? c.toString() : defaultValue);
    }

    /**
    * @param i
    * @param defaultValue
    * @return String
    * @author: lizj
    */
    public static String toString(Integer i, String defaultValue) {
        return (i != null ? i.toString() : defaultValue);
    }

    /**
    * @param f
    * @param defaultValue
    * @return String
    * @author: lizj
    */
    public static String toString(Float f, String defaultValue) {
        return (f != null ? f.toString() : defaultValue);
    }

    /**
    * @param d
    * @param defaultValue
    * @return String
    * @author: lizj
    */
    public static String toString(Double d, String defaultValue) {
        return (d != null ? d.toString() : defaultValue);
    }

    /**
    * @param l
    * @param defaultValue
    * @return String
    * @author: lizj
    */
    public static String toString(Long l, String defaultValue) {
        return (l != null ? l.toString() : defaultValue);
    }

    /**
    * @param s
    * @param defaultValue
    * @return String
    * @author: lizj
    */
    public static String toString(String s, String defaultValue) {
        return (s != null ? s : defaultValue);
    }

    /**
    * @param buf
    * @param defaultValue
    * @return String
    * @author: lizj
    */
    public static String toString(StringBuffer buf, String defaultValue) {
        return (buf != null ? buf.toString() : defaultValue);
    }

    /**
    * @param s
    * @return String
    * @author lizj
    */
    public static String trim(String s) {
        return (s != null ? s.trim() : Empty);
    }
}

Related

  1. perm(List l)
  2. permsList(List topList)
  3. permutate(List src)
  4. permutation(String prefix, String s, List list)
  5. permutations(List list)
  6. permutations(List listings)
  7. permutations(Map> parameterValues)