Example usage for java.util Arrays deepToString

List of usage examples for java.util Arrays deepToString

Introduction

In this page you can find the example usage for java.util Arrays deepToString.

Prototype

public static String deepToString(Object[] a) 

Source Link

Document

Returns a string representation of the "deep contents" of the specified array.

Usage

From source file:ArraysTester.java

public static void main(String[] args) {
    ArraysTester tester = new ArraysTester(50);
    int[] myArray = tester.get();

    // Compare two arrays
    int[] myOtherArray = tester.get().clone();
    if (Arrays.equals(myArray, myOtherArray)) {
        System.out.println("The two arrays are equal!");
    } else {//w w w  . j av a2s.  c om
        System.out.println("The two arrays are not equal!");
    }

    // Fill up some values
    Arrays.fill(myOtherArray, 2, 10, new Double(Math.PI).intValue());
    myArray[30] = 98;

    // Print array, as is
    System.out.println("Here's the unsorted array...");
    System.out.println(Arrays.toString(myArray));
    System.out.println();

    // Sort the array
    Arrays.sort(myArray);

    // print array, sorted
    System.out.println("Here's the sorted array...");
    System.out.println(Arrays.toString(myArray));
    System.out.println();

    // Get the index of a particular value
    int index = Arrays.binarySearch(myArray, 98);
    System.out.println("98 is located in the array at index " + index);

    String[][] ticTacToe = { { "X", "O", "O" }, { "O", "X", "X" }, { "X", "O", "X" } };
    System.out.println(Arrays.deepToString(ticTacToe));

    String[][] ticTacToe2 = { { "O", "O", "X" }, { "O", "X", "X" }, { "X", "O", "X" } };

    String[][] ticTacToe3 = { { "X", "O", "O" }, { "O", "X", "X" }, { "X", "O", "X" } };

    if (Arrays.deepEquals(ticTacToe, ticTacToe2)) {
        System.out.println("Boards 1 and 2 are equal.");
    } else {
        System.out.println("Boards 1 and 2 are not equal.");
    }

    if (Arrays.deepEquals(ticTacToe, ticTacToe3)) {
        System.out.println("Boards 1 and 3 are equal.");
    } else {
        System.out.println("Boards 1 and 3 are not equal.");
    }
}

From source file:com.jivesoftware.os.routing.bird.deployable.config.extractor.ConfigExtractor.java

public static void main(String[] args) {
    String configHost = args[0];//from w w w  .  j a v a 2  s. c o  m
    String configPort = args[1];
    String instanceKey = args[2];
    String instanceVersion = args[3];
    String setPath = args[4];
    String getPath = args[5];

    HttpRequestHelper buildRequestHelper = buildRequestHelper(null, configHost, Integer.parseInt(configPort));

    try {
        Set<URL> packages = new HashSet<>();
        for (int i = 5; i < args.length; i++) {
            packages.addAll(ClasspathHelper.forPackage(args[i]));
        }

        Reflections reflections = new Reflections(new ConfigurationBuilder().setUrls(packages)
                .setScanners(new SubTypesScanner(), new TypesScanner()));

        Set<Class<? extends Config>> subTypesOf = reflections.getSubTypesOf(Config.class);

        File configDir = new File("./config");
        configDir.mkdirs();

        Set<Class<? extends Config>> serviceConfig = new HashSet<>();
        Set<Class<? extends Config>> healthConfig = new HashSet<>();
        for (Class<? extends Config> type : subTypesOf) {
            if (HealthCheckConfig.class.isAssignableFrom(type)) {
                healthConfig.add(type);
            } else {
                serviceConfig.add(type);
            }
        }

        Map<String, String> defaultServiceConfig = extractAndPublish(serviceConfig,
                new File(configDir, "default-service-config.properties"), "default", instanceKey,
                instanceVersion, buildRequestHelper, setPath);

        DeployableConfig getServiceOverrides = new DeployableConfig("override", instanceKey, instanceVersion,
                defaultServiceConfig);
        DeployableConfig gotSerivceConfig = buildRequestHelper.executeRequest(getServiceOverrides, getPath,
                DeployableConfig.class, null);
        if (gotSerivceConfig == null) {
            System.out.println("Failed to publish default service config for " + Arrays.deepToString(args));
        } else {
            Properties override = createKeySortedProperties();
            override.putAll(gotSerivceConfig.properties);
            override.store(new FileOutputStream("config/override-service-config.properties"), "");
        }

        Map<String, String> defaultHealthConfig = extractAndPublish(healthConfig,
                new File(configDir, "default-health-config.properties"), "default-health", instanceKey,
                instanceVersion, buildRequestHelper, setPath);

        DeployableConfig getHealthOverrides = new DeployableConfig("override-health", instanceKey,
                instanceVersion, defaultHealthConfig);
        DeployableConfig gotHealthConfig = buildRequestHelper.executeRequest(getHealthOverrides, getPath,
                DeployableConfig.class, null);
        if (gotHealthConfig == null) {
            System.out.println("Failed to publish default health config for " + Arrays.deepToString(args));
        } else {
            Properties override = createKeySortedProperties();
            override.putAll(gotHealthConfig.properties);
            override.store(new FileOutputStream("config/override-health-config.properties"), "");
        }

        Properties instanceProperties = createKeySortedProperties();
        File configFile = new File("config/instance.properties");
        if (configFile.exists()) {
            instanceProperties.load(new FileInputStream(configFile));
        }

        Properties serviceOverrideProperties = createKeySortedProperties();
        configFile = new File("config/override-service-config.properties");
        if (configFile.exists()) {
            serviceOverrideProperties.load(new FileInputStream(configFile));
        }

        Properties healthOverrideProperties = createKeySortedProperties();
        configFile = new File("config/override-health-config.properties");
        if (configFile.exists()) {
            healthOverrideProperties.load(new FileInputStream(configFile));
        }

        Properties properties = createKeySortedProperties();
        properties.putAll(defaultServiceConfig);
        properties.putAll(defaultHealthConfig);
        properties.putAll(serviceOverrideProperties);
        properties.putAll(healthOverrideProperties);
        properties.putAll(instanceProperties);
        properties.store(new FileOutputStream("config/config.properties"), "");

        System.exit(0);
    } catch (Exception x) {
        x.printStackTrace();
        System.exit(1);
    }

}

From source file:Main.java

static void printObject(Object obj) {
    System.out.println("find threadlocal var:" + obj);
    if (obj instanceof Object[]) {
        System.out.println("array:" + Arrays.deepToString((Object[]) obj));
    } else if (obj instanceof Reference) {
        Reference ref = (Reference) obj;
        System.out.println("ref: " + ref.getClass().getName() + ",ref to " + ref.get());
    } else {//from  ww  w  .j av a  2s .co m
        System.out.println("others: " + obj);
    }
}

From source file:Main.java

/**
 * creates a table showing target value (arbitrary) and bitArray it should
 * be assigned to *.//from www  .  j a v  a  2  s .c o  m
 * 
 * @param array
 *            the array
 * @param verbose
 *            the verbose
 * @return the double[][][]
 */
public static double[][][] createConversionTable(double[] array, boolean verbose) {
    int length = array.length;
    double[][][] bArray = new double[length][2][length];
    int i = 0;
    for (double val : array) { // don't actually need value
        bArray[i][0] = new double[] { val }; // original value
        for (int j = 0; j < length; ++j) { // Think it is a bit confusing if
            // I for each this...
            bArray[i][1][j] = 0; // every value 0 except...
        }
        bArray[i][1][length - i - 1] = 1; // this guy
        i++;
    }
    if (verbose) {
        System.out.println("Conversion table:\n" + Arrays.deepToString(bArray));
    }
    return bArray;
}

From source file:org.sipfoundry.sipxconfig.common.SipxCollectionUtils.java

/**
 * Displays as much information about the array as we can without overwhelming log file with
 * useless data//from  w  w  w  .j a v  a2 s .  co m
 */
public static String arrayToShortString(Object[] items, int len) {
    String[] strItems = new String[items.length];
    for (int i = 0; i < items.length; i++) {
        Object item = items[i];
        String itemRepr;
        if (item instanceof Object[]) {
            itemRepr = Arrays.deepToString((Object[]) item);
        } else {
            itemRepr = item.toString();
        }
        strItems[i] = StringUtils.abbreviate(itemRepr, len);
    }
    return "[" + StringUtils.join(strItems, ", ") + "]";
}

From source file:com.target.tgcase.json.ProductCompositeResponse.java

@Override
public String toString() {
    return "ProductCompositeResponse{" + "items=" + Arrays.deepToString(items) + '}';
}

From source file:Main.java

/**
 * return a 2d array with the value and its count. Can deal with multiples.
 * Values will be in the same order as array (with subsequent duplicate
 * values removed). *//from   ww w. ja  v a2s .  c o m
 * 
 * @param array
 *            the array
 * @param verbose
 *            the verbose
 * @return the count
 */
public static Double[][] getCount(double[] array, boolean verbose) {
    ArrayList<Double[]> countArray = new ArrayList<Double[]>();
    double count = 0;
    for (int i = 0; i < array.length; ++i) {
        // check if list contains current value
        boolean unique = true;
        for (Double[] ia : countArray) {
            if (ia[0].doubleValue() == array[i]) {
                unique = false;
            }
        }
        // Count values
        if (unique) {
            count = 1;
            for (int j = i + 1; j < array.length; ++j) {
                if (array[i] == array[j]) {
                    count++;
                }
            }
            countArray.add(new Double[] { array[i], count });
        }
    }
    Double[][] doubleArray = new Double[countArray.size()][];

    doubleArray = countArray.toArray(doubleArray);
    if (verbose) {
        System.out.println("Value and count of value:\n" + Arrays.deepToString(doubleArray));
    }
    return doubleArray;
}

From source file:org.opendds.jms.common.util.Logger.java

public void debug(String message, String[] args) {
    if (isDebugEnabled()) {
        debug(message, Arrays.deepToString(args));
    }
}

From source file:bachelorthesis.captchabuilder.builder.ColorsParser.java

/**
 * Returns a ColorRangRGBA based on string arguments
 * <p/>/*from   w w w .  j a  va2  s . co m*/
 * @param colorArgs the string arguments
 * <p/>
 * @return a ColorRangRGBA object
 * <p/>
 * @throws ParseException
 * @see ColorRangeContainer
 */
public static ColorRangeContainer parse(String[] colorArgs) throws ParseException {

    System.out.println("parsing colors option: " + Arrays.deepToString(colorArgs));
    ColorOptions colorOptionType = ColorOptions.valueOf(colorArgs[0]);

    switch (colorOptionType) {
    case RANGE:
        if (colorArgs.length != 3) {
            throw new ParseException("Colors range Option only takes 2 argumenst");
        }
        String startHex = "#" + colorArgs[1].toUpperCase();
        String endHex = "#" + colorArgs[2].toUpperCase();
        return new ColorRangeContainer(ImageUtil.hexadecimalToRGBa(startHex),
                ImageUtil.hexadecimalToRGBa(endHex));
    case LIST:
        if (colorArgs.length < 2) {
            throw new ParseException("Colors list Option takes at least 2 argumenst");
        }
        ArrayList<String> hexList = new ArrayList<>();
        for (int i = 1; i < colorArgs.length; i++) {
            String colorHex = "#" + colorArgs[i].toUpperCase();
            hexList.add(colorHex);
        }

        return new ColorRangeContainer(hexList);
    default:
        throw new ParseException("Colors option not found: " + colorOptionType.name());
    }
}

From source file:Main.java

/**
 * creates a table showing target value (arbitrary) and bitArray it should
 * be assigned to *./*  ww w.  ja  v  a  2  s .com*/
 * 
 * @param array
 *            the array
 * @param verbose
 *            the verbose
 * @return the string[][][]
 */
public static String[][][] createConversionTable(String[] array, boolean verbose) {
    int length = array.length;
    String[][][] bArray = new String[length][2][length];
    int i = 0;
    for (String val : array) { // don't actually need value
        bArray[i][0] = new String[] { array[i] }; // original value
        for (int j = 0; j < length; ++j) { // Think it is a bit confusing if
            // I for each this...
            bArray[i][1][j] = "0"; // every value 0 except...
        }
        bArray[i][1][length - i - 1] = "1"; // this guy
        i++;
    }
    if (verbose) {
        System.out.println("Conversion table:\n" + Arrays.deepToString(bArray));
    }
    return bArray;
}