1 | // Utils.java |
---|
2 | // |
---|
3 | // (c) 1999-2001 PAL Development Core Team |
---|
4 | // |
---|
5 | // This package may be distributed under the |
---|
6 | // terms of the Lesser GNU General Public License (LGPL) |
---|
7 | |
---|
8 | package de.ugoe.cs.autoquest.tasktrees.alignment.pal.misc; |
---|
9 | |
---|
10 | |
---|
11 | |
---|
12 | /** |
---|
13 | * Provides some miscellaneous methods. |
---|
14 | * |
---|
15 | * @version $Id: Utils.java,v 1.9 2001/11/20 19:58:45 alexi Exp $ |
---|
16 | * |
---|
17 | * @author Matthew Goode |
---|
18 | */ |
---|
19 | public class Utils { |
---|
20 | |
---|
21 | /** Clones an array of doubles |
---|
22 | * @return null if input is null, otherwise return complete copy. |
---|
23 | */ |
---|
24 | public static final double[] getCopy(double[] array) { |
---|
25 | |
---|
26 | if(array == null) { |
---|
27 | return null; |
---|
28 | } |
---|
29 | double[] copy = new double[array.length]; |
---|
30 | System.arraycopy(array,0,copy,0,array.length); |
---|
31 | return copy; |
---|
32 | } |
---|
33 | |
---|
34 | /** |
---|
35 | * Clones an array of doubles |
---|
36 | * @return null if input is null, otherwise return complete copy. |
---|
37 | */ |
---|
38 | public static final double[][] getCopy(double[][] array) { |
---|
39 | |
---|
40 | if(array == null) { |
---|
41 | return null; |
---|
42 | } |
---|
43 | double[][] copy = new double[array.length][]; |
---|
44 | for(int i = 0 ; i < copy.length ; i++) { |
---|
45 | copy[i] = new double[array[i].length]; |
---|
46 | System.arraycopy(array[i],0,copy[i],0,array[i].length); |
---|
47 | } |
---|
48 | return copy; |
---|
49 | } |
---|
50 | |
---|
51 | /** |
---|
52 | * Clones an array of ints |
---|
53 | * @return null if input is null, otherwise return complete copy. |
---|
54 | */ |
---|
55 | public static final int[] getCopy(int[] array) { |
---|
56 | if(array == null) { |
---|
57 | return null; |
---|
58 | } |
---|
59 | int[] copy = new int[array.length]; |
---|
60 | System.arraycopy(array,0,copy,0,array.length); |
---|
61 | return copy; |
---|
62 | } |
---|
63 | |
---|
64 | /** Copies all of source into dest - assumes dest to be large enough */ |
---|
65 | public static final void copy(double[][] source, double[][] dest) { |
---|
66 | for(int i = 0 ; i < source.length ; i++) { |
---|
67 | System.arraycopy(source[i],0,dest[i],0,source[i].length); |
---|
68 | } |
---|
69 | } |
---|
70 | |
---|
71 | /** |
---|
72 | * A simple toString method for an array of doubles. |
---|
73 | * No fancy formating. |
---|
74 | * Puts spaces between each value |
---|
75 | */ |
---|
76 | public static final String toString(double[] array) { |
---|
77 | StringBuffer sb = new StringBuffer(array.length*7); |
---|
78 | for(int i = 0 ; i < array.length ; i++) { |
---|
79 | sb.append(array[i]); |
---|
80 | sb.append(' '); |
---|
81 | } |
---|
82 | return sb.toString(); |
---|
83 | } |
---|
84 | /** |
---|
85 | * A simple toString method for an array of ints. |
---|
86 | * No fancy formating. |
---|
87 | * Puts spaces between each value |
---|
88 | */ |
---|
89 | public static final String toString(int[] array) { |
---|
90 | StringBuffer sb = new StringBuffer(array.length*7); |
---|
91 | for(int i = 0 ; i < array.length ; i++) { |
---|
92 | sb.append(array[i]); |
---|
93 | sb.append(' '); |
---|
94 | } |
---|
95 | return sb.toString(); |
---|
96 | } |
---|
97 | |
---|
98 | /** |
---|
99 | * A simple toString method for an array of doubles. |
---|
100 | * No fancy formating. |
---|
101 | * Puts spaces between each value |
---|
102 | */ |
---|
103 | public static final String toString(double[][] array) { |
---|
104 | String ss = ""; |
---|
105 | for(int i = 0 ; i < array.length ; i++) { |
---|
106 | ss+= i+":"+toString(array[i])+'\n'; |
---|
107 | } |
---|
108 | return ss; |
---|
109 | } |
---|
110 | } |
---|
111 | |
---|
112 | |
---|
113 | |
---|