1 22 23 package org.xquark.mapper.util; 24 25 import java.util.StringTokenizer ; 26 27 30 public class Functions 31 { 32 private static final String RCSRevision = "$Revision: 1.1 $"; 33 private static final String RCSName = "$Name: $"; 34 public static final long LOCAL_BITMASK = 0x00000000FFFFFFFF; 35 36 public static LongList StringToLongList(String s) 37 { 38 StringTokenizer tokens = new StringTokenizer (s, "."); 39 LongList list = new LongList(); 40 41 while (tokens.hasMoreTokens()) 42 { 43 list.add(new Long (tokens.nextToken())); 44 } 45 46 return list; 47 } 48 49 public static LongList StringToIntegerList(String s) 50 { 51 StringTokenizer tokens = new StringTokenizer (s, "."); 52 LongList list = new LongList(); 53 54 while (tokens.hasMoreTokens()) 55 { 56 list.add(new Long (tokens.nextToken())); 57 } 58 59 return list; 60 } 61 62 public static String replacePlaceholder(String s, String ph, String 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 78 public static String setString(String statement, String value, int pos) 79 { 80 StringBuffer buf = new StringBuffer (statement); 81 82 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 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 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 |