Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/*******************************************************************************
 * Manchester Centre for Integrative Systems Biology
 * University of Manchester
 * Manchester M1 7ND
 * United Kingdom
 * 
 * Copyright (C) 2007 University of Manchester
 * 
 * This program is released under the Academic Free License ("AFL") v3.0.
 * (http://www.opensource.org/licenses/academic.php)
 *******************************************************************************/

import java.util.*;

public class Main {
    /**
     * 
     */
    public static final String ELEMENT_SEPARATOR = ",(\\s)*";
    /**
     * 
     */
    private static final String EMPTY_STRING = "";
    /**
     * 
     */
    private static final String ARRAY_OPEN_TAG = "[";
    /**
     * 
     */
    private static final String ARRAY_CLOSE_TAG = "]";

    /**
     * 
     * @param value
     * @return boolean[]
     */
    public static boolean[] toBooleanArray(final String value) {
        if (value == null) {
            return new boolean[] {};
        }

        final String strippedValue = value.replace(ARRAY_OPEN_TAG, EMPTY_STRING).replace(ARRAY_CLOSE_TAG,
                EMPTY_STRING);
        final StringTokenizer tokenizer = new StringTokenizer(strippedValue, ELEMENT_SEPARATOR);
        final Collection<Boolean> intCollection = new ArrayList<>();

        while (tokenizer.hasMoreTokens()) {
            intCollection.add(Boolean.valueOf(tokenizer.nextToken().trim()));
        }

        return toBooleanArray(intCollection);
    }

    /**
     * 
     * @param collection
     * @return int[]
     */
    public static boolean[] toBooleanArray(final Collection<Boolean> collection) {
        final boolean[] array = new boolean[collection == null ? 0 : collection.size()];

        if (collection != null) {
            int i = 0;

            for (Iterator<Boolean> iterator = collection.iterator(); iterator.hasNext();) {
                array[i++] = iterator.next().booleanValue();
            }
        }

        return array;
    }
}