KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > xquark > mapper > util > Functions


1 /*
2  * This file belongs to the XQuark distribution.
3  * Copyright (C) 2003 Universite de Versailles Saint-Quentin.
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307.
18  * You can also get it at http://www.gnu.org/licenses/lgpl.html
19  *
20  * For more information on this software, see http://www.xquark.org.
21  */

22
23 package org.xquark.mapper.util;
24
25 import java.util.StringTokenizer JavaDoc;
26
27 /**
28  * Easy to use functions and methods
29  */

30 public class Functions
31 {
32     private static final String JavaDoc RCSRevision = "$Revision: 1.1 $";
33     private static final String JavaDoc RCSName = "$Name: $";
34     public static final long LOCAL_BITMASK = 0x00000000FFFFFFFF;
35
36     public static LongList StringToLongList(String JavaDoc s)
37     {
38         StringTokenizer JavaDoc tokens = new StringTokenizer JavaDoc(s, ".");
39         LongList list = new LongList();
40
41         while (tokens.hasMoreTokens())
42         {
43             list.add(new Long JavaDoc(tokens.nextToken()));
44         }
45
46         return list;
47     }
48
49     public static LongList StringToIntegerList(String JavaDoc s)
50     {
51         StringTokenizer JavaDoc tokens = new StringTokenizer JavaDoc(s, ".");
52         LongList list = new LongList();
53
54         while (tokens.hasMoreTokens())
55         {
56             list.add(new Long JavaDoc(tokens.nextToken()));
57         }
58
59         return list;
60     }
61
62     public static String JavaDoc replacePlaceholder(String JavaDoc s, String JavaDoc ph, String JavaDoc value)
63     {
64         int phIndex;
65         if (s == null)
66             return null;
67         while ((phIndex = s.indexOf(ph)) >= 0)
68         {
69             s =
70                 s.substring(0, phIndex)
71                     + value
72                     + s.substring(phIndex + ph.length());
73         }
74         return s;
75     }
76
77     /* Replaces character '?' at position n with the value */
78     public static String JavaDoc setString(String JavaDoc statement, String JavaDoc value, int pos)
79     {
80         StringBuffer JavaDoc buf = new StringBuffer JavaDoc(statement);
81
82         // find the corresponding '?'
83
int markPos = 0, markCount = 0, bufLen = buf.length();
84
85         for (; markPos < bufLen; markPos++)
86         {
87             if (buf.charAt(markPos) == '?')
88                 markCount++;
89             if (markCount == pos)
90                 break;
91         }
92
93         // replacing '?' by value
94
buf.insert(markCount, value);
95         buf.deleteCharAt(markCount + value.length());
96
97         return buf.toString();
98     }
99
100     public static long makeLong(int highBits, int lowBits)
101     {
102         long result = (long) highBits;
103         return ((result << 32) + lowBits);
104     }
105
106     public static int getHigh32(long tagCode)
107     {
108         return (int) (tagCode >>> 32);
109     }
110
111     public static int getLow32(long tagCode)
112     {
113         return (int) (tagCode & LOCAL_BITMASK);
114     }
115
116     /**
117      * Test if the character is whitespace according to XML 1.0 specifications.
118      *
119      * @param c The character to be tested.
120      * @return the result of the test.
121      */

122     public static boolean isWhitespace(char c)
123     {
124         switch (c)
125         {
126             case 0x20 :
127             case 0x9 :
128             case 0xD :
129             case 0xA :
130                 return true;
131             default :
132                 return false;
133         }
134     }
135 }
136
Popular Tags