Thread: [Nice-commit] Nice/stdlib/nice/lang rawBooleanArray.java,NONE,1.1 rawByteArray.java,NONE,1.1 rawChar
Brought to you by:
bonniot
From: <ar...@us...> - 2004-01-17 16:32:48
|
Update of /cvsroot/nice/Nice/stdlib/nice/lang In directory sc8-pr-cvs1:/tmp/cvs-serv3521/F:/nice/stdlib/nice/lang Modified Files: rawArray.java Added Files: rawBooleanArray.java rawByteArray.java rawCharArray.java rawDoubleArray.java rawFloatArray.java rawIntArray.java rawLongArray.java rawObjectArray.java rawShortArray.java Log Message: Added specialized versions of rawArray to improve performance. --- NEW FILE: rawBooleanArray.java --- /**************************************************************************** * N I C E * * A high-level object-oriented research language * * (c) Daniel Bonniot 2004 * * * * This package is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * Free Software Foundation; either version 2 of the License, or (at your * * option) any later version. * * * * As a special exception, the copyright holders of this library give you * * permission to link this library with independent modules to produce an * * executable, regardless of the license terms of these independent * * modules, and to copy and distribute the resulting executable under * * terms of your choice. * ****************************************************************************/ package nice.lang; /** Class used to wrap native boolean arrays when considered as part of the collection hierarchy. */ public final class rawBooleanArray extends rawArray { rawBooleanArray(boolean[] arr) { super(arr); this.arr = arr; } private final boolean[] arr; /**************************************************************** * Implementation of java.util.List ****************************************************************/ public final int size () { return arr.length; } public final Object get (int index) { return new Boolean(arr[index]); } public final Object set (int index, Object element) { boolean old = arr[index]; arr[index] = ((Boolean)element).booleanValue(); return new Boolean(old); } } --- NEW FILE: rawByteArray.java --- /**************************************************************************** * N I C E * * A high-level object-oriented research language * * (c) Daniel Bonniot 2003 * * * * This package is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * Free Software Foundation; either version 2 of the License, or (at your * * option) any later version. * * * * As a special exception, the copyright holders of this library give you * * permission to link this library with independent modules to produce an * * executable, regardless of the license terms of these independent * * modules, and to copy and distribute the resulting executable under * * terms of your choice. * ****************************************************************************/ package nice.lang; /** Class used to wrap native byte arrays when considered as part of the collection hierarchy. */ public final class rawByteArray extends rawArray { rawByteArray(byte[] arr) { super(arr); this.arr = arr; } private final byte[] arr; /**************************************************************** * Implementation of java.util.List ****************************************************************/ public final int size () { return arr.length; } public final Object get (int index) { return new Byte(arr[index]); } public final Object set (int index, Object element) { byte old = arr[index]; arr[index] = ((Number)element).byteValue(); return new Byte(old); } } --- NEW FILE: rawCharArray.java --- /**************************************************************************** * N I C E * * A high-level object-oriented research language * * (c) Daniel Bonniot 2003 * * * * This package is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * Free Software Foundation; either version 2 of the License, or (at your * * option) any later version. * * * * As a special exception, the copyright holders of this library give you * * permission to link this library with independent modules to produce an * * executable, regardless of the license terms of these independent * * modules, and to copy and distribute the resulting executable under * * terms of your choice. * ****************************************************************************/ package nice.lang; /** Class used to wrap native char arrays when considered as part of the collection hierarchy. */ public final class rawCharArray extends rawArray { rawCharArray(char[] arr) { super(arr); this.arr = arr; } private final char[] arr; /**************************************************************** * Implementation of java.util.List ****************************************************************/ public final int size () { return arr.length; } public final Object get (int index) { return new Character(arr[index]); } public final Object set (int index, Object element) { char old = arr[index]; arr[index] = ((Character)element).charValue(); return new Character(old); } } --- NEW FILE: rawDoubleArray.java --- /**************************************************************************** * N I C E * * A high-level object-oriented research language * * (c) Daniel Bonniot 2004 * * * * This package is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * Free Software Foundation; either version 2 of the License, or (at your * * option) any later version. * * * * As a special exception, the copyright holders of this library give you * * permission to link this library with independent modules to produce an * * executable, regardless of the license terms of these independent * * modules, and to copy and distribute the resulting executable under * * terms of your choice. * ****************************************************************************/ package nice.lang; /** Class used to wrap native double arrays when considered as part of the collection hierarchy. */ public final class rawDoubleArray extends rawArray { rawDoubleArray(double[] arr) { super(arr); this.arr = arr; } private final double[] arr; /**************************************************************** * Implementation of java.util.List ****************************************************************/ public final int size () { return arr.length; } public final Object get (int index) { return new Double(arr[index]); } public final Object set (int index, Object element) { double old = arr[index]; arr[index] = ((Number)element).doubleValue(); return new Double(old); } } --- NEW FILE: rawFloatArray.java --- /**************************************************************************** * N I C E * * A high-level object-oriented research language * * (c) Daniel Bonniot 2004 * * * * This package is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * Free Software Foundation; either version 2 of the License, or (at your * * option) any later version. * * * * As a special exception, the copyright holders of this library give you * * permission to link this library with independent modules to produce an * * executable, regardless of the license terms of these independent * * modules, and to copy and distribute the resulting executable under * * terms of your choice. * ****************************************************************************/ package nice.lang; /** Class used to wrap native float arrays when considered as part of the collection hierarchy. */ public final class rawFloatArray extends rawArray { rawFloatArray(float[] arr) { super(arr); this.arr = arr; } private final float[] arr; /**************************************************************** * Implementation of java.util.List ****************************************************************/ public final int size () { return arr.length; } public final Object get (int index) { return new Float(arr[index]); } public final Object set (int index, Object element) { float old = arr[index]; arr[index] = ((Number)element).floatValue(); return new Float(old); } } --- NEW FILE: rawIntArray.java --- /**************************************************************************** * N I C E * * A high-level object-oriented research language * * (c) Daniel Bonniot 2004 * * * * This package is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * Free Software Foundation; either version 2 of the License, or (at your * * option) any later version. * * * * As a special exception, the copyright holders of this library give you * * permission to link this library with independent modules to produce an * * executable, regardless of the license terms of these independent * * modules, and to copy and distribute the resulting executable under * * terms of your choice. * ****************************************************************************/ package nice.lang; /** Class used to wrap native int arrays when considered as part of the collection hierarchy. */ public final class rawIntArray extends rawArray { rawIntArray(int[] arr) { super(arr); this.arr = arr; } private final int[] arr; /**************************************************************** * Implementation of java.util.List ****************************************************************/ public final int size () { return arr.length; } public final Object get (int index) { return new Integer(arr[index]); } public final Object set (int index, Object element) { int old = arr[index]; arr[index] = ((Number)element).intValue(); return new Integer(old); } } --- NEW FILE: rawLongArray.java --- /**************************************************************************** * N I C E * * A high-level object-oriented research language * * (c) Daniel Bonniot 2004 * * * * This package is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * Free Software Foundation; either version 2 of the License, or (at your * * option) any later version. * * * * As a special exception, the copyright holders of this library give you * * permission to link this library with independent modules to produce an * * executable, regardless of the license terms of these independent * * modules, and to copy and distribute the resulting executable under * * terms of your choice. * ****************************************************************************/ package nice.lang; /** Class used to wrap native long arrays when considered as part of the collection hierarchy. */ public final class rawLongArray extends rawArray { rawLongArray(long[] arr) { super(arr); this.arr = arr; } private final long[] arr; /**************************************************************** * Implementation of java.util.List ****************************************************************/ public final int size () { return arr.length; } public final Object get (int index) { return new Long(arr[index]); } public final Object set (int index, Object element) { long old = arr[index]; arr[index] = ((Number)element).longValue(); return new Long(old); } } --- NEW FILE: rawObjectArray.java --- /**************************************************************************** * N I C E * * A high-level object-oriented research language * * (c) Daniel Bonniot 2004 * * * * This package is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * Free Software Foundation; either version 2 of the License, or (at your * * option) any later version. * * * * As a special exception, the copyright holders of this library give you * * permission to link this library with independent modules to produce an * * executable, regardless of the license terms of these independent * * modules, and to copy and distribute the resulting executable under * * terms of your choice. * ****************************************************************************/ package nice.lang; /** Class used to wrap native Object arrays when considered as part of the collection hierarchy. */ public final class rawObjectArray extends rawArray { rawObjectArray(Object[] arr) { super(arr); this.arr = arr; } private final Object[] arr; /**************************************************************** * Implementation of java.util.List ****************************************************************/ public final int size () { return arr.length; } public final Object get (int index) { return arr[index]; } public final Object set (int index, Object element) { Object old = arr[index]; arr[index] = element; return old; } } --- NEW FILE: rawShortArray.java --- /**************************************************************************** * N I C E * * A high-level object-oriented research language * * (c) Daniel Bonniot 2004 * * * * This package is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * Free Software Foundation; either version 2 of the License, or (at your * * option) any later version. * * * * As a special exception, the copyright holders of this library give you * * permission to link this library with independent modules to produce an * * executable, regardless of the license terms of these independent * * modules, and to copy and distribute the resulting executable under * * terms of your choice. * ****************************************************************************/ package nice.lang; /** Class used to wrap native short arrays when considered as part of the collection hierarchy. */ public final class rawShortArray extends rawArray { rawShortArray(short[] arr) { super(arr); this.arr = arr; } private final short[] arr; /**************************************************************** * Implementation of java.util.List ****************************************************************/ public final int size () { return arr.length; } public final Object get (int index) { return new Short(arr[index]); } public final Object set (int index, Object element) { short old = arr[index]; arr[index] = ((Number)element).shortValue(); return new Short(old); } } Index: rawArray.java =================================================================== RCS file: /cvsroot/nice/Nice/stdlib/nice/lang/rawArray.java,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** rawArray.java 19 Nov 2003 16:04:45 -0000 1.11 --- rawArray.java 17 Jan 2004 16:32:45 -0000 1.12 *************** *** 2,6 **** * N I C E * * A high-level object-oriented research language * ! * (c) Daniel Bonniot 2003 * * * * This package is free software; you can redistribute it and/or modify * --- 2,6 ---- * N I C E * * A high-level object-oriented research language * ! * (c) Daniel Bonniot 2004 * * * * This package is free software; you can redistribute it and/or modify * *************** *** 28,39 **** @author Daniel Bonniot (d.b...@ma...) */ ! public final class rawArray extends java.util.AbstractList { ! private rawArray(Object value) { this.value = value; } ! public Object value; public Object value() { --- 28,39 ---- @author Daniel Bonniot (d.b...@ma...) */ ! public class rawArray extends java.util.AbstractList { ! protected rawArray(Object value) { this.value = value; } ! public final Object value; public Object value() { *************** *** 45,48 **** --- 45,76 ---- if (value == null) return null; + + if (value instanceof Object[]) + return new rawObjectArray((Object[])value); + + if (value instanceof int[]) + return new rawIntArray((int[])value); + + if (value instanceof byte[]) + return new rawByteArray((byte[])value); + + if (value instanceof long[]) + return new rawLongArray((long[])value); + + if (value instanceof char[]) + return new rawCharArray((char[])value); + + if (value instanceof boolean[]) + return new rawBooleanArray((boolean[])value); + + if (value instanceof double[]) + return new rawDoubleArray((double[])value); + + if (value instanceof float[]) + return new rawFloatArray((float[])value); + + if (value instanceof short[]) + return new rawShortArray((short[])value); + return new rawArray(value); } |