View Javadoc

1   package org.sourceforge.jemm.client.shared;
2   
3   import java.util.Arrays;
4   
5   public abstract class ValueEncoder {
6   	public abstract <K> K encode(K value);
7   
8   	/**
9   	 * Creates an encoded copy of the given array, does not alter the original array. 
10  	 * @param <K> The array type
11  	 * @param values The original array
12  	 * @return A copy of the array with all values encoded.
13  	 */
14  	@SuppressWarnings("unchecked")
15  	public <K> K[] encodeArray(K[] values) {
16  		if(values == null)
17  			return null;
18  		
19          K[] newValues = (K[]) Arrays.copyOf(values,values.length,values.getClass());
20  		for(int i=0; i<newValues.length; i++)
21  				newValues[i] = this.encode(newValues[i]);		
22  		return newValues;
23  	}
24  }