001    /*
002     * Copyright (C) 2008-2010 by Holger Arndt
003     *
004     * This file is part of the Universal Java Matrix Package (UJMP).
005     * See the NOTICE file distributed with this work for additional
006     * information regarding copyright ownership and licensing.
007     *
008     * UJMP is free software; you can redistribute it and/or modify
009     * it under the terms of the GNU Lesser General Public License as
010     * published by the Free Software Foundation; either version 2
011     * of the License, or (at your option) any later version.
012     *
013     * UJMP is distributed in the hope that it will be useful,
014     * but WITHOUT ANY WARRANTY; without even the implied warranty of
015     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
016     * GNU Lesser General Public License for more details.
017     *
018     * You should have received a copy of the GNU Lesser General Public
019     * License along with UJMP; if not, write to the
020     * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
021     * Boston, MA  02110-1301  USA
022     */
023    
024    package org.ujmp.core.genericmatrix.stub;
025    
026    import org.ujmp.core.genericmatrix.GenericMatrix;
027    import org.ujmp.core.matrix.AbstractMatrix;
028    import org.ujmp.core.matrix.factory.MatrixFactoryRoot;
029    import org.ujmp.core.objectmatrix.factory.DefaultDenseObjectMatrix2DFactory;
030    import org.ujmp.core.objectmatrix.factory.ObjectMatrix2DFactory;
031    import org.ujmp.core.util.MathUtil;
032    import org.ujmp.core.util.StringUtil;
033    
034    public abstract class AbstractGenericMatrix<A> extends AbstractMatrix implements GenericMatrix<A> {
035            private static final long serialVersionUID = -7498575238134186845L;
036    
037            public static ObjectMatrix2DFactory factory = new DefaultDenseObjectMatrix2DFactory();
038    
039            public final Object getAsObject(long... coordinates) {
040                    return getObject(coordinates);
041            }
042    
043            @SuppressWarnings("unchecked")
044            public final void setAsObject(Object o, long... coordinates) {
045                    switch (getValueType()) {
046                    case BOOLEAN:
047                            setAsBoolean(MathUtil.getBoolean(o), coordinates);
048                            break;
049                    case BIGINTEGER:
050                            setAsBigInteger(MathUtil.getBigInteger(o), coordinates);
051                            break;
052                    case BIGDECIMAL:
053                            setAsBigDecimal(MathUtil.getBigDecimal(o), coordinates);
054                            break;
055                    case BYTE:
056                            setAsByte(MathUtil.getByte(o), coordinates);
057                            break;
058                    case CHAR:
059                            setAsChar(MathUtil.getChar(o), coordinates);
060                            break;
061                    case DATE:
062                            setAsDate(MathUtil.getDate(o), coordinates);
063                            break;
064                    case DOUBLE:
065                            setAsDouble(MathUtil.getDouble(o), coordinates);
066                            break;
067                    case FLOAT:
068                            setAsFloat(MathUtil.getFloat(o), coordinates);
069                            break;
070                    case INT:
071                            setAsInt(MathUtil.getInt(o), coordinates);
072                            break;
073                    case LONG:
074                            setAsLong(MathUtil.getLong(o), coordinates);
075                            break;
076                    case OBJECT:
077                            setObject((A) o, coordinates);
078                            break;
079                    case SHORT:
080                            setAsShort(MathUtil.getShort(o), coordinates);
081                            break;
082                    case STRING:
083                            setAsString(StringUtil.convert(o), coordinates);
084                            break;
085                    }
086            }
087    
088            public MatrixFactoryRoot getFactory() {
089                    return factory;
090            }
091    }