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.util;
025    
026    import java.math.MathContext;
027    import java.util.Locale;
028    
029    public abstract class UJMPSettings {
030    
031            private static double tolerance = 1.0e-12;
032    
033            private static int numberOfThreads = 1;
034    
035            private static boolean useJBlas = true;
036    
037            private static boolean useOjalgo = true;
038    
039            private static boolean useEJML = true;
040    
041            private static boolean useParallelColt = true;
042    
043            private static boolean useMTJ = true;
044    
045            private static boolean useCommonsMath = true;
046    
047            private static boolean useBlockMatrixMultiply = true;
048    
049            private static int defaultBlockSize = 100;
050    
051            private static MathContext mathContext = MathContext.DECIMAL128;
052    
053            public static MathContext getDefaultMathContext() {
054                    return mathContext;
055            }
056    
057            public static void setDefaultMathContext(MathContext mc) {
058                    mathContext = mc;
059            }
060    
061            /**
062             * How many rows should be returned maximally for <code>toString()</code> If
063             * the <code>Matrix</code> is bigger, three dots (<code>...</code>) will be
064             * returned for the remaining rows.
065             * 
066             * 
067             * @default 1000
068             */
069            private static long maxRowsToPrint = 100;
070    
071            /**
072             * How many columns should be returned maximally for <code>toString()</code>
073             * . If the <code>Matrix</code> is bigger, three dots (<code>...</code>)
074             * will be returned for the remaining columns.
075             * 
076             * 
077             * @default 1000
078             */
079            private static long maxColumnsToPrint = 100;
080    
081            /**
082             * How many rows should be returned maximally for
083             * <code>getToolTipText()</code>. If the <code>Matrix</code> is bigger,
084             * three dots (<code>...</code>) will be returned for the remaining rows.
085             * 
086             * 
087             * @default 10
088             */
089            private static long maxToolTipRows = 10;
090    
091            /**
092             * How many columns should be returned maximally for
093             * <code>getToolTipText()</code>. If the <code>Matrix</code> is bigger,
094             * three dots (<code>...</code>) will be returned for the remaining columns.
095             * 
096             * @default 10
097             */
098            private static long maxToolTipCols = 10;
099    
100            static {
101                    // Set the number of threads to use for expensive calculations. If the
102                    // machine has only one cpu, only one thread is used. For more than one
103                    // core, the number of threads is higher.
104                    try {
105                            numberOfThreads = Runtime.getRuntime().availableProcessors();
106                    } catch (Throwable e) {
107                    }
108    
109                    try {
110                            setLocale(Locale.US);
111                    } catch (Throwable e) {
112                    }
113            }
114    
115            public static void initialize() {
116                    try {
117                            System.setProperty("file.encoding", "UTF-8");
118                            System.setProperty("sun.jnu.encoding", "UTF-8");
119                    } catch (Throwable e) {
120                    }
121            }
122    
123            public static int getNumberOfThreads() {
124                    return numberOfThreads;
125            }
126    
127            public static void setNumberOfThreads(int numberOfThreads) {
128                    UJMPSettings.numberOfThreads = numberOfThreads;
129            }
130    
131            public static double getTolerance() {
132                    return tolerance;
133            }
134    
135            public static void setTolerance(double tolerance) {
136                    UJMPSettings.tolerance = tolerance;
137            }
138    
139            public static long getMaxColumnsToPrint() {
140                    return maxColumnsToPrint;
141            }
142    
143            public static void setMaxColumnsToPrint(long maxColumnsToPrint) {
144                    UJMPSettings.maxColumnsToPrint = maxColumnsToPrint;
145            }
146    
147            public static long getMaxRowsToPrint() {
148                    return maxRowsToPrint;
149            }
150    
151            public static void setMaxRowsToPrint(long maxRowsToPrint) {
152                    UJMPSettings.maxRowsToPrint = maxRowsToPrint;
153            }
154    
155            public static long getMaxToolTipCols() {
156                    return maxToolTipCols;
157            }
158    
159            public static void setMaxToolTipCols(long maxToolTipCols) {
160                    UJMPSettings.maxToolTipCols = maxToolTipCols;
161            }
162    
163            public static long getMaxToolTipRows() {
164                    return maxToolTipRows;
165            }
166    
167            public static void setMaxToolTipRows(long maxToolTipRows) {
168                    UJMPSettings.maxToolTipRows = maxToolTipRows;
169            }
170    
171            public static Locale getLocale() {
172                    return Locale.getDefault();
173            }
174    
175            public static void setLocale(Locale locale) {
176                    Locale.setDefault(locale);
177            }
178    
179            public static void setUseCommonsMath(boolean useCommonsMath) {
180                    UJMPSettings.useCommonsMath = useCommonsMath;
181            }
182    
183            public static boolean isUseCommonsMath() {
184                    return useCommonsMath;
185            }
186    
187            /**
188             * @param useJBlas
189             *            the useJBlas to set
190             */
191            public static void setUseJBlas(boolean useJBlas) {
192                    UJMPSettings.useJBlas = useJBlas;
193            }
194    
195            /**
196             * @return useJBlas
197             */
198            public static boolean isUseJBlas() {
199                    return useJBlas;
200            }
201    
202            /**
203             * @param useOjalgo
204             *            the useOjalgo to set
205             */
206            public static void setUseOjalgo(boolean useOjalgo) {
207                    UJMPSettings.useOjalgo = useOjalgo;
208            }
209    
210            /**
211             * @return useOjalgo
212             */
213            public static boolean isUseOjalgo() {
214                    return useOjalgo;
215            }
216    
217            /**
218             * @param useEJML
219             *            the useEJML to set
220             */
221            public static void setUseEJML(boolean useEJML) {
222                    UJMPSettings.useEJML = useEJML;
223            }
224    
225            /**
226             * @return useEJML
227             */
228            public static boolean isUseEJML() {
229                    return useEJML;
230            }
231    
232            /**
233             * @param useParallelColt
234             *            the useParallelColt to set
235             */
236            public static void setUseParallelColt(boolean useParallelColt) {
237                    UJMPSettings.useParallelColt = useParallelColt;
238            }
239    
240            /**
241             * @return useParallelColt
242             */
243            public static boolean isUseParallelColt() {
244                    return useParallelColt;
245            }
246    
247            /**
248             * @param useMTJ
249             *            the useMTJ to set
250             */
251            public static void setUseMTJ(boolean useMTJ) {
252                    UJMPSettings.useMTJ = useMTJ;
253            }
254    
255            /**
256             * @return useMTJ
257             */
258            public static boolean isUseMTJ() {
259                    return useMTJ;
260            }
261    
262            public static boolean isUseBlockMatrixMultiply() {
263                    return useBlockMatrixMultiply;
264            }
265    
266            public static void setUseBlockMatrixMultiply(boolean useBlockMatrix) {
267                    UJMPSettings.useBlockMatrixMultiply = useBlockMatrix;
268            }
269    
270            public static int getDefaultBlockSize() {
271                    return defaultBlockSize;
272            }
273    
274            public static void setDefaultBlockSize(int defaultBlockSize) {
275                    UJMPSettings.defaultBlockSize = defaultBlockSize;
276            }
277    
278    }