Source Code Cross Referenced for PropertyUtil.java in  » Database-DBMS » db-derby-10.2 » org » apache » derbyTesting » functionTests » harness » 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 » Database DBMS » db derby 10.2 » org.apache.derbyTesting.functionTests.harness 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* 
002:
003:           Derby - Class org.apache.derbyTesting.functionTests.harness.PropertyUtil
004:
005:           Licensed to the Apache Software Foundation (ASF) under one or more
006:           contributor license agreements.  See the NOTICE file distributed with
007:           this work for additional information regarding copyright ownership.
008:           The ASF licenses this file to You under the Apache License, Version 2.0
009:           (the "License"); you may not use this file except in compliance with
010:           the License.  You may obtain a copy of the License at
011:
012:              http://www.apache.org/licenses/LICENSE-2.0
013:
014:           Unless required by applicable law or agreed to in writing, software
015:           distributed under the License is distributed on an "AS IS" BASIS,
016:           WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017:           See the License for the specific language governing permissions and
018:           limitations under the License.
019:
020:         */
021:
022:        package org.apache.derbyTesting.functionTests.harness;
023:
024:        import java.util.Properties;
025:        import java.util.Enumeration;
026:
027:        public class PropertyUtil {
028:
029:            //////////////////////////////////////////////////////////////////////////////
030:            //
031:            //	SORTS A PROPERTY LIST AND STRINGIFIES THE SORTED PROPERTIES
032:            //
033:            /////////////////////////////////////////////////////////////////////////////
034:
035:            /**
036:             *	Sorts a property list and turns the sorted list into a string.
037:             *
038:             *	@param	list	property list to sort
039:             *
040:             *	@return	a string version of the sorted list
041:             */
042:            public static String sortProperties(Properties list) {
043:                // stringify them with no indentation
044:                return sortProperties(list, null);
045:            }
046:
047:            /**
048:             * Sorts property list and print out each key=value pair prepended with 
049:             * specific indentation.  If indent is null, do not prepend with
050:             * indentation. 
051:             *
052:             * The output string shows up in two styles, style 1 looks like
053:             * { key1=value1, key2=value2, key3=value3 }
054:             *
055:             * style 2 looks like
056:             *		key1=value1
057:             *		key2=value2
058:             *		key3=value3
059:             * where indent goes between the new line and the keys
060:             *
061:             * To get style 1, pass in a null indent
062:             * To get sytle 2, pass in non-null indent (whatever you want to go before
063:             * the key value)
064:             */
065:            public static String sortProperties(Properties list, char[] indent) {
066:                int size = list == null ? 0 : list.size();
067:                int count = 0;
068:                String[] array = new String[size];
069:                String key;
070:                String value;
071:                StringBuffer buffer;
072:
073:                // Calculate the number of properties in the property list and
074:                // build an array of all the property names.
075:                // We need to go thru the enumeration because Properties has a
076:                // recursive list of defaults.
077:                if (list != null) {
078:                    for (Enumeration propertyNames = list.propertyNames(); propertyNames
079:                            .hasMoreElements();) {
080:                        if (count == size) {
081:                            // need to expand the array
082:                            size = size * 2;
083:                            String[] expandedArray = new String[size];
084:                            System.arraycopy(array, 0, expandedArray, 0, count);
085:                            array = expandedArray;
086:                        }
087:                        key = (String) propertyNames.nextElement();
088:                        array[count++] = key;
089:                    }
090:                    // now sort the array
091:                    java.util.Arrays.sort(array, 0, count);
092:                }
093:
094:                // now stringify the array
095:                buffer = new StringBuffer();
096:                if (indent == null)
097:                    buffer.append("{ ");
098:
099:                for (int ictr = 0; ictr < count; ictr++) {
100:                    if (ictr > 0 && indent == null)
101:                        buffer.append(", ");
102:
103:                    key = array[ictr];
104:
105:                    if (indent != null)
106:                        buffer.append(indent);
107:
108:                    buffer.append(key);
109:                    buffer.append("=");
110:
111:                    value = list.getProperty(key, "MISSING_VALUE");
112:                    buffer.append(value);
113:
114:                    if (indent != null)
115:                        buffer.append("\n");
116:
117:                }
118:                if (indent == null)
119:                    buffer.append(" }");
120:
121:                return buffer.toString();
122:            }
123:
124:            /**
125:             * Copy a set of properties from one Property to another.
126:             * <p>
127:             *
128:             * @return The identifier to be used to open the conglomerate later.
129:             *
130:             * @param src_prop  Source set of properties to copy from.
131:             * @param dest_prop Dest Properties to copy into.
132:             *
133:             **/
134:            public static void copyProperties(Properties src_prop,
135:                    Properties dest_prop) {
136:                for (Enumeration propertyNames = src_prop.propertyNames(); propertyNames
137:                        .hasMoreElements();) {
138:                    String key = (String) propertyNames.nextElement();
139:                    dest_prop.put(key, src_prop.getProperty(key));
140:                }
141:            }
142:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.