package com.akjava.gwt.lib.client;

import java.util.Collection;

import com.google.common.collect.Lists;


public class ArrayUtils {

	public static String[] iterableToArray(Iterable<String> vs){
		Collection<String> collection =  Lists.newArrayList(vs);
	    String[] array = new String[collection.size()];
	    return collection.toArray(array);
	}
	
	public static int[][] createIntYXArray(int x,int y,int defaultValue){
	int[][] ret=new int[y][x];
	if(defaultValue!=0){
		for(int i=0;i<y;i++){
			for(int j=0;j<x;j++){
				ret[i][j]=defaultValue;
			}
		}
	}
	return ret;
	}
	
	public static int[][] copy(int[][] data){
		int[][] newret=new int[data.length][];
		for(int y=0;y<data.length;y++){
			newret[y]=new int[data[y].length];
			for(int x=0;x<data[y].length;x++){
				newret[y][x]=data[y][x];
			}
		}
		return newret;
	}
	public static int[][] inverse(int[][] data){
		int[][] newret=new int[data.length][];
		for(int y=0;y<data.length;y++){
			newret[y]=new int[data[y].length];
			for(int x=0;x<data[y].length;x++){
				newret[y][x]=data[y][x]*-1;
			}
		}
		return newret;
	}
	
	public static void clear(int[][] array,int value){
			for(int i=0;i<array.length;i++){
				for(int j=0;j<array[i].length;j++){
					array[i][j]=value;
				}
			}
		}
	
	public static String toString(int[][] array){
		String ret="";
		for(int i=0;i<array.length;i++){
			for(int j=0;j<array[i].length;j++){
				ret+=""+array[i][j];
				if(j!=array[i].length-1){
					ret+=",";
				}
			}
			if(i!=array.length-1){
				ret+="\n";
			}
		}
		return ret;
	}
	
	public static class ArrayIntGrid{
		private int[][] data;
		private int rows;
		private int cols;
		public int[][] getData(){
			return data;
		}
		public int getRows() {
			return rows;
		}
		public int getCols() {
			return cols;
		}
		public ArrayIntGrid(int cols,int rows){
			data=createIntYXArray(cols, rows, 0);
			this.rows=rows;
			this.cols=cols;
		}
		public int get(int x,int y){
			return data[y][x];
		}
		public void set(int x,int y,int value){
			data[y][x]=value;
		}
		
	}

}

@@ -100,47 +100,522 @@
 ect.
-Lists;%0D%0A%0D%0A%0D%0Apublic class ArrayUtils %7B%0D%0A
+FluentIterable;%0D%0Aimport com.google.common.collect.Lists;%0D%0A%0D%0A%0D%0A/**%0D%0A * %0D%0A *  * http://docs.oracle.com/javase/6/docs/api/java/util/Arrays.html%0D%0A%09* https://github.com/google/guava/wiki/PrimitivesExplained%0D%0A * %0D%0A * should use com.google.common.collect.Table%0D%0A * but toArray not support on GWT,so still need these old style class%0D%0A * @author aki%0D%0A *%0D%0A */%0D%0Apublic class ArrayUtils %7B%0D%0A%0D%0A%09/**%0D%0A%09 * see%0D%0A%09 *%0D%0A%09%0D%0A%09 * %0D%0A%09 * sadly FluentIterable.from(vs).toArray(String.class) not work on GWT%0D%0A%09 * @param vs%0D%0A%09 * @return%0D%0A%09 */
 %0D%0A%09p
@@ -675,16 +675,20 @@
 %3E vs)%7B%0D%0A
+%09%09%0D%0A
 %09%09Collec
@@ -833,16 +833,22 @@
 rray);%0D%0A
+%09   %0D%0A
 %09%7D%0D%0A%09%0D%0A%09
@@ -2092,32 +2092,49 @@
 rn ret;%0D%0A%09%7D%0D%0A%09%0D%0A
+%09/*%0D%0A%09 * %0D%0A%09 */%0D%0A
 %09public static c

add comment