001/*
002 * Copyright 2010-2015 Institut Pasteur.
003 * 
004 * This file is part of Icy.
005 * 
006 * Icy is free software: you can redistribute it and/or modify
007 * it under the terms of the GNU General Public License as published by
008 * the Free Software Foundation, either version 3 of the License, or
009 * (at your option) any later version.
010 * 
011 * Icy is distributed in the hope that it will be useful,
012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014 * GNU General Public License for more details.
015 * 
016 * You should have received a copy of the GNU General Public License
017 * along with Icy. If not, see <http://www.gnu.org/licenses/>.
018 */
019package icy.type.collection.array;
020
021import icy.type.DataType;
022
023/**
024 * Class which define the following array informations :<br>
025 * <code>native data type</code><br>
026 * <code>dimension number</code>
027 * 
028 * @see DataType
029 * @author Stephane
030 */
031public class ArrayType
032{
033    /**
034     * Return the ArrayDataType for the specified array (passed as Object)
035     */
036    public static ArrayType getArrayInfo(Object array)
037    {
038        return ArrayUtil.getArrayType(array);
039    }
040
041    private DataType dataType;
042    private int dim;
043
044    /**
045     * @param dataType
046     *        data type
047     * @param dim
048     *        dimension number
049     */
050    public ArrayType(DataType dataType, int dim)
051    {
052        super();
053
054        this.dataType = dataType;
055        this.dim = dim;
056    }
057
058    /**
059     * Return the data type for this array
060     */
061    public DataType getDataType()
062    {
063        return dataType;
064    }
065
066    /**
067     * Return number of dimension
068     */
069    public int getDim()
070    {
071        return dim;
072    }
073
074    /**
075     * @param dataType
076     *        the dataType to set
077     */
078    public void setDataType(DataType dataType)
079    {
080        this.dataType = dataType;
081    }
082
083    /**
084     * @param dim
085     *        the dim to set
086     */
087    public void setDim(int dim)
088    {
089        this.dim = dim;
090    }
091
092    /**
093     * Return true if specified array data type is equals to current array data type
094     */
095    public boolean isSame(ArrayType arrayType)
096    {
097        return (arrayType.dataType == dataType) && (arrayType.dim == dim);
098    }
099
100    @Override
101    public boolean equals(Object obj)
102    {
103        if (obj instanceof ArrayType)
104            return isSame((ArrayType) obj);
105
106        return super.equals(obj);
107    }
108}