Source Code Cross Referenced for ApolloUtil.java in  » Graphic-Library » apollo » org » apollo » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Graphic Library » apollo » org.apollo 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Apollo - Motion capture and animation system
003:         * Copyright (c) 2005 Apollo
004:         * 
005:         * This program is free software; you can redistribute it and/or
006:         * modify it under the terms of the GNU General Public License
007:         * as published by the Free Software Foundation; either version 2
008:         * of the License, or (at your option) any later version.
009:         * 
010:         * This program is distributed in the hope that it will be useful,
011:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
012:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
013:         * GNU General Public License for more details.
014:         * 
015:         * You should have received a copy of the GNU General Public License
016:         * along with this program; if not, write to the Free Software
017:         * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
018:         *
019:         * http://www.gnu.org/copyleft/gpl.html
020:         *
021:         * @author Giovane.Kuhn - brain@netuno.com.br
022:         *
023:         */
024:        package org.apollo;
025:
026:        import java.io.File;
027:        import java.lang.reflect.InvocationTargetException;
028:        import java.lang.reflect.Method;
029:
030:        public final class ApolloUtil {
031:
032:            private ApolloUtil() {
033:                // nop
034:            }
035:
036:            /**
037:             * Runs garbage collector many times
038:             */
039:            public static void gc() {
040:                System.gc();
041:                System.gc();
042:            }
043:
044:            /**
045:             * Indicate if there's at least one <code>null</code> object
046:             * @param objects List of objects
047:             * @return <code>true</code> if has <code>null</code> object, otherwise <code>false</code>
048:             */
049:            public static boolean hasNull(Object... objects) {
050:                for (Object o : objects) {
051:                    if (o == null) {
052:                        return true;
053:                    }
054:                }
055:                return false;
056:            }
057:
058:            /**
059:             * Indicate if there's at least one <code>NaN</code> number
060:             * @param numbers List of numbers
061:             * @return <code>true</code> if has <code>NaN</code> number, otherwise <code>false</code>
062:             */
063:            public static boolean hasNaN(double... numbers) {
064:                for (double n : numbers) {
065:                    if (Double.isNaN(n)) {
066:                        return true;
067:                    }
068:                }
069:                return false;
070:            }
071:
072:            /**
073:             * Return file name from a complete file name
074:             * @param fileName Complete file name
075:             * @param withExtension <code>true</code> file name with extension, otherwise <code>false</code>
076:             * @return File name
077:             */
078:            public static String getFileName(String fileName,
079:                    boolean withExtension) {
080:                if (fileName == null) {
081:                    return null;
082:                }
083:                fileName = fileName.replace('\\', File.separatorChar).replace(
084:                        '/', File.separatorChar);
085:                int dot = fileName.length();
086:                if (!withExtension) {
087:                    dot = fileName.lastIndexOf('.');
088:                    if (dot < 0) {
089:                        dot = fileName.length();
090:                    }
091:                }
092:                int path = fileName.lastIndexOf(File.separatorChar);
093:                if (path < 0) {
094:                    path = 0;
095:                }
096:                return fileName.substring(path + 1, dot);
097:            }
098:
099:            /**
100:             * Return path name missing last separator char
101:             * @param fileName Full file name
102:             * @return Return path name
103:             */
104:            public static String getPathName(String fileName) {
105:                if (fileName == null) {
106:                    return null;
107:                }
108:                fileName = fileName.replace('\\', File.separatorChar).replace(
109:                        '/', File.separatorChar);
110:                int path = fileName.lastIndexOf(File.separatorChar);
111:                if (path < 0) {
112:                    path = fileName.length();
113:                }
114:                return fileName.substring(0, path);
115:            }
116:
117:            public static String getRelativeFileName(String pathName,
118:                    String fileName) {
119:                if (fileName == null || pathName == null) {
120:                    return fileName;
121:                }
122:                if (!fileName.startsWith(pathName)) {
123:                    return fileName;
124:                }
125:                return "./" + fileName.substring(pathName.length() + 1);
126:
127:            }
128:
129:            /**
130:             * Create a new instance of the class informed
131:             * @param className Class to have a new instance
132:             * @return New instance
133:             * @throws ClassNotFoundException 
134:             * @throws IllegalAccessException 
135:             * @throws InstantiationException 
136:             */
137:            public static Object newInstance(String className)
138:                    throws ClassNotFoundException, InstantiationException,
139:                    IllegalAccessException {
140:                Class clazz = Class.forName(className);
141:                return clazz.newInstance();
142:            }
143:
144:            /**
145:             * Util method to invoke other methods 
146:             * @param methodName Methos to invoke
147:             * @param obj Object that will be invoked
148:             * @param args Method arguments
149:             * @return Return method invokes result
150:             * @throws SecurityException
151:             * @throws NoSuchMethodException
152:             * @throws InvocationTargetException 
153:             * @throws IllegalAccessException 
154:             * @throws IllegalArgumentException 
155:             */
156:            public static Object invokeMethod(String methodName, Object obj,
157:                    Object[] args) throws SecurityException,
158:                    NoSuchMethodException, IllegalArgumentException,
159:                    IllegalAccessException, InvocationTargetException {
160:                Method method = null;
161:                if (args == null) {
162:                    args = new Object[0];
163:                }
164:                for (Method m : obj.getClass().getMethods()) {
165:                    if (m.getName().equals(methodName)
166:                            && m.getParameterTypes().length == args.length) {
167:                        // same name and parameters length
168:                        method = m;
169:                        break;
170:                    }
171:                }
172:                if (method == null) {
173:                    throw new NoSuchMethodException("Method " + methodName
174:                            + " with " + args.length
175:                            + " parameters, not exists at " + obj.getClass());
176:                }
177:                return method.invoke(obj, convertValue(method
178:                        .getParameterTypes(), args));
179:            }
180:
181:            /**
182:             * Convert the values to correct data type
183:             * @param types Correct types
184:             * @param values Values to be converted
185:             * @return An array with the values converted
186:             */
187:            public static Object[] convertValue(Class[] types, Object[] values) {
188:                assert types.length == values.length;
189:                Object ret[] = new Object[types.length];
190:                for (int i = 0; i < ret.length; i++) {
191:
192:                    // TODO do it better
193:                    if (types[i] == Byte.class) {
194:                        ret[i] = Byte.valueOf(values[i].toString());
195:                    } else if (types[i] == Short.class) {
196:                        ret[i] = Short.valueOf(values[i].toString());
197:                    } else if (types[i] == Integer.class) {
198:                        ret[i] = Integer.valueOf(values[i].toString());
199:                    } else if (types[i] == Long.class) {
200:                        ret[i] = Long.valueOf(values[i].toString());
201:                    } else if (types[i] == Float.class) {
202:                        ret[i] = Float.valueOf(values[i].toString());
203:                    } else if (types[i] == Double.class) {
204:                        ret[i] = Double.valueOf(values[i].toString());
205:                    } else if (types[i] == String.class) {
206:                        ret[i] = String.valueOf(values[i].toString());
207:                    } else if (types[i] == Boolean.class) {
208:                        ret[i] = Boolean.valueOf(values[i].toString());
209:                    } else {
210:                        ret[i] = values[i];
211:                    }
212:                }
213:                return ret;
214:            }
215:
216:            /**
217:             * Return a repeated <code>quantity</code> string
218:             * @param s String to be repeated
219:             * @param quantity Quantity to repeat
220:             * @return String builded
221:             */
222:            public static String repeatString(String s, int quantity) {
223:                StringBuilder b = new StringBuilder("");
224:                for (int i = 0; i < quantity; i++) {
225:                    b.append(s);
226:                }
227:                return b.toString();
228:            }
229:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.