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.bigintegermatrix.impl; 025 026 import java.math.BigInteger; 027 import java.util.Arrays; 028 029 import org.ujmp.core.Matrix; 030 import org.ujmp.core.bigintegermatrix.stub.AbstractDenseBigIntegerMatrix2D; 031 import org.ujmp.core.exceptions.MatrixException; 032 033 public class ArrayDenseBigIntegerMatrix2D extends AbstractDenseBigIntegerMatrix2D { 034 private static final long serialVersionUID = 3110279640095711135L; 035 036 private BigInteger[][] values = null; 037 038 public ArrayDenseBigIntegerMatrix2D(Matrix m) throws MatrixException { 039 if (m instanceof ArrayDenseBigIntegerMatrix2D) { 040 BigInteger[][] v = ((ArrayDenseBigIntegerMatrix2D) m).values; 041 this.values = new BigInteger[v.length][v[0].length]; 042 for (int r = v.length; --r >= 0;) { 043 for (int c = v[0].length; --c >= 0;) { 044 values[r][c] = v[r][c]; 045 } 046 } 047 } else { 048 values = new BigInteger[(int) m.getRowCount()][(int) m.getColumnCount()]; 049 for (long[] c : m.allCoordinates()) { 050 setAsBigInteger(m.getAsBigInteger(c), c); 051 } 052 } 053 } 054 055 public ArrayDenseBigIntegerMatrix2D(BigInteger[]... v) { 056 this.values = v; 057 } 058 059 public ArrayDenseBigIntegerMatrix2D(long... size) { 060 values = new BigInteger[(int) size[ROW]][(int) size[COLUMN]]; 061 for (int r = values.length; --r != -1;) { 062 Arrays.fill(values[r], BigInteger.ZERO); 063 } 064 } 065 066 public ArrayDenseBigIntegerMatrix2D(BigInteger... v) { 067 this.values = new BigInteger[v.length][1]; 068 for (int r = v.length; --r >= 0;) { 069 values[r][0] = v[r]; 070 } 071 } 072 073 public long[] getSize() { 074 return new long[] { values.length, values.length == 0 ? 0 : values[0].length }; 075 } 076 077 public long getRowCount() { 078 return values.length; 079 } 080 081 public long getColumnCount() { 082 return values.length == 0 ? 0 : values[0].length; 083 } 084 085 public BigInteger getBigInteger(long row, long column) { 086 return values[(int) row][(int) column]; 087 } 088 089 public void setBigInteger(BigInteger value, long row, long column) { 090 values[(int) row][(int) column] = value; 091 } 092 093 public BigInteger getBigInteger(int row, int column) { 094 return values[row][column]; 095 } 096 097 public void setBigInteger(BigInteger value, int row, int column) { 098 values[row][column] = value; 099 } 100 101 }