Subversion Repository Public Repository

litesoft

Diff Revisions 822 vs 823 for /trunk/Java/core/Anywhere/src/org/litesoft/core/util/UtilsCommon.java

Diff revisions: vs.
  @@ -1,199 +1,15 @@
1 1 // This Source Code is in the Public Domain per: http://litesoft.org/License.txt
2 2 package org.litesoft.core.util;
3 3
4 - import java.util.*;
5 -
6 4 import org.litesoft.charstreams.*;
7 - import org.litesoft.core.simpletypes.nonpublic.*;
8 - import org.litesoft.core.simpletypes.temporal.*;
9 - import org.litesoft.core.simpletypes.temporal.nonpublic.*;
10 5 import org.litesoft.core.typeutils.*;
11 6
12 - public class UtilsCommon extends EqualSupport
7 + public class UtilsCommon
13 8 {
14 9 protected UtilsCommon()
15 10 {
16 11 }
17 12
18 - public static String cvtTextForDisplay( String pText )
19 - {
20 - if ( pText == null )
21 - {
22 - return "[null]";
23 - }
24 - int length = pText.length();
25 - StringBuilder sb = new StringBuilder( length );
26 - for ( int i = 0; i < length; i++ )
27 - {
28 - char c = pText.charAt( i );
29 - switch ( c )
30 - {
31 - case '[':
32 - case ']':
33 - case '\\':
34 - case '"':
35 - sb.append( '\\' );
36 - sb.append( c );
37 - break;
38 - case '\n':
39 - sb.append( "\\n" );
40 - break;
41 - case '\r':
42 - sb.append( "\\r" );
43 - break;
44 - case '\t':
45 - sb.append( "\\t" );
46 - break;
47 - case '\f':
48 - sb.append( "\\f" );
49 - break;
50 - default:
51 - if ( (' ' <= c) && (c < 127) )
52 - {
53 - sb.append( c );
54 - break;
55 - }
56 - sb.append( '[' );
57 - sb.append( Characters.cvtCharForDisplay( c ) );
58 - sb.append( ']' );
59 - break;
60 - }
61 - }
62 - return sb.toString();
63 - }
64 -
65 - public static Object[] convert( int pEntries, Enumeration<Object> pEnumeration )
66 - {
67 - Object[] them = new Object[pEntries];
68 - for ( int i = 0; (i < pEntries) && pEnumeration.hasMoreElements(); i++ )
69 - {
70 - them[i] = pEnumeration.nextElement();
71 - }
72 - return them;
73 - }
74 -
75 - // Groups
76 -
77 - // Object Group:
78 -
79 - @SuppressWarnings({"unchecked", "ManualArrayToCollectionCopy", "MismatchedQueryAndUpdateOfCollection"})
80 - public static <T> Collection<T> convert( Collection<T> pCollectionToFill, Object[] pObjects )
81 - {
82 - Collection<Object> toFill = (Collection<Object>) pCollectionToFill;
83 - for ( Object object : pObjects )
84 - {
85 - toFill.add( object );
86 - }
87 - return pCollectionToFill;
88 - }
89 -
90 - public static void appendClassName( StringBuilder pBuffer, int pTabLevel, String pLabel, Object pValue )
91 - {
92 - append( pBuffer, pTabLevel, pLabel, (pValue == null) ? null : pValue.getClass().getName() );
93 - }
94 -
95 - public static void append( StringBuilder pBuffer, int pTabLevel, String pLabel, Object pValue )
96 - {
97 - append( pBuffer, pTabLevel, pLabel );
98 - pBuffer.append( ':' );
99 - pBuffer.append( (pValue == null) ? "null" : pValue.toString() );
100 - }
101 -
102 - public static void append( StringBuilder pBuffer, int pTabLevel, String pValue )
103 - {
104 - pBuffer.append( '\n' );
105 - while ( pTabLevel-- >= 1 )
106 - {
107 - pBuffer.append( '\t' );
108 - }
109 - pBuffer.append( (pValue == null) ? "null" : pValue );
110 - }
111 -
112 - public static String normalizeCtrlChars( String pText )
113 - {
114 - if ( pText != null )
115 - {
116 - for ( int i = pText.length(); i-- > 0; )
117 - {
118 - if ( pText.charAt( i ) < ' ' )
119 - {
120 - StringBuilder sb = new StringBuilder( pText );
121 - for (; i >= 0; i-- )
122 - {
123 - char c = sb.charAt( i );
124 - if ( c < ' ' )
125 - {
126 - switch ( c )
127 - {
128 - case '\n':
129 - case '\r':
130 - case '\f':
131 - break;
132 - case '\t':
133 - sb.setCharAt( i, ' ' );
134 - break;
135 - default:
136 - sb.setCharAt( i, '.' );
137 - break;
138 - }
139 - }
140 - pText = sb.toString();
141 - }
142 - break;
143 - }
144 - }
145 - }
146 - return pText;
147 - }
148 -
149 - /**
150 - * Given path(s) that may be system dependent, create a path
151 - * that is converted to a system independent form (forward Slashes).
152 - * Note: Ignore null entries (null, or all nulls returns null).
153 - */
154 - public static String forwardSlashPath( String... pPaths )
155 - {
156 - StringBuilder sb = null;
157 - if ( pPaths != null )
158 - {
159 - for ( String path : pPaths )
160 - {
161 - if ( path != null )
162 - {
163 - if ( sb == null )
164 - {
165 - sb = new StringBuilder();
166 - }
167 - if ( path.length() != 0 )
168 - {
169 - String fsp = Paths.forwardSlash( path );
170 - if ( sb.length() == 0 )
171 - {
172 - sb.append( fsp );
173 - }
174 - else
175 - {
176 - boolean pStartsWithSlash = (fsp.charAt( 0 ) == '/');
177 - if ( sb.charAt( sb.length() - 1 ) == '/' )
178 - {
179 - sb.append( pStartsWithSlash ? fsp.substring( 1 ) : fsp );
180 - }
181 - else
182 - {
183 - if ( !pStartsWithSlash )
184 - {
185 - sb.append( '/' );
186 - }
187 - sb.append( fsp );
188 - }
189 - }
190 - }
191 - }
192 - }
193 - }
194 - return (sb == null) ? null : sb.toString();
195 - }
196 -
197 13 /**
198 14 * @param pText !null
199 15 */
  @@ -334,23 +150,4 @@
334 150 }
335 151 return pSB;
336 152 }
337 -
338 - // Array / varArgs
339 -
340 - // Objects:
341 -
342 - // Object Group:
343 -
344 - public static SimpleDate forceEndOfMonth( SimpleDate pSimpleDate )
345 - {
346 - if ( pSimpleDate != null )
347 - {
348 - int zDaysInMonth = CalendarSupport.daysInMonth( pSimpleDate.getYear(), pSimpleDate.getMonth() );
349 - if ( pSimpleDate.getDay() != zDaysInMonth )
350 - {
351 - pSimpleDate.setDay( zDaysInMonth );
352 - }
353 - }
354 - return pSimpleDate;
355 - }
356 153 }