📄 idutil.java
字号:
In the syntax braces ([]) show grouping. '*' means repeat 0 or more times. The syntax for id is defined in IdUtil. </PRE> <BR> Classpath returned is a two part name. <BR> If the class path is empty then this returns an array of zero length. @exception StandardException Oops */ public static String[][] parseDbClassPath(String input, boolean normalizeToUpper) throws StandardException { //As a special case we accept a zero length dbclasspath. if (input.length() == 0) return new String[0][]; Vector v = new Vector(); java.io.StringReader r = new java.io.StringReader(input); // while (true) { try { String[] thisQName = IdUtil.parseQualifiedName(r, normalizeToUpper); if (thisQName.length != 2) throw StandardException.newException(SQLState.DB_CLASS_PATH_PARSE_ERROR,input); v.addElement(thisQName); int delim = r.read(); if (delim != ':') { if (delim!=-1) throw StandardException.newException(SQLState.DB_CLASS_PATH_PARSE_ERROR,input); break; } } catch (StandardException se){ if (se.getMessageId().equals(SQLState.ID_PARSE_ERROR)) throw StandardException.newException(SQLState.DB_CLASS_PATH_PARSE_ERROR, se,input); else throw se; } catch (IOException ioe){ throw StandardException.newException(SQLState.DB_CLASS_PATH_PARSE_ERROR,ioe,input); } } String[][] result = new String[v.size()][]; v.copyInto(result); return result; } /* ** Methods that operate on lists of identifiers. */ /** Scan a list of ids from the string provided. This returns an array with id per entry. This raises an an exception if the string does not contain a valid list of names. @exception StandardException Oops */ public static String[] parseIdList(String p) throws StandardException { if (p==null) return null; StringReader r = new StringReader(p); String[] result = parseIdList(r, true); verifyListEmpty(r); return result; } /** Parse an idList. @parm nomralize true means return ids in nomral form, false means return them as they were entered. @exception StandardException Oops */ private static String[] parseIdList(StringReader r, boolean normalize) throws StandardException { Vector v = new Vector(); while (true) { int delim; try { String thisId = IdUtil.parseId(r,normalize, true); v.addElement(thisId); r.mark(0); delim = r.read(); if (delim != ',') { if (delim!=-1) r.reset(); break; } } catch (StandardException se){ if (se.getMessageId().equals(SQLState.ID_LIST_PARSE_ERROR)) throw StandardException.newException(SQLState.ID_LIST_PARSE_ERROR,se); else throw se; } catch (IOException ioe){ throw StandardException.newException(SQLState.ID_LIST_PARSE_ERROR,ioe); } } if (v.size() == 0) return null; String[] result = new String[v.size()]; v.copyInto(result); return result; } /** Return an IdList with all the ids that in l1 and l2 or null if not ids are on both lists. @param l1 An array of ids in normal form @param l2 An array of ids in nomral form */ public static String intersect(String[] l1, String[] l2) { if (l1 == null || l2 == null) return null; HashSet h = new HashSet(); for(int ix=0;ix<l2.length;ix++) h.add(l2[ix]); Vector v = new Vector(); for(int ix=0;ix<l1.length;ix++) if (h.contains(l1[ix])) v.addElement(l1[ix]); return vectorToIdList(v,true); } /** Return an idList in external form with one id for every element of v. If v has no elements, return null. @param normal True means the ids in v are in normal form and false means they are in external form. */ private static String vectorToIdList(Vector v,boolean normal) { if (v.size() == 0) return null; String[] a = new String[v.size()]; v.copyInto(a); if (normal) return mkIdList(a); else return mkIdListAsEntered(a); } /** Return an IdList with all the ids that are repeated in l. @param l a list of ids in normal form. */ public static String dups(String[] l) { if (l == null) return null; HashSet h = new HashSet(); Vector v = new Vector(); for(int ix=0;ix<l.length;ix++) { if (!h.contains(l[ix])) h.add(l[ix]); else v.addElement(l[ix]); } return vectorToIdList(v,true); } /** Return an IdList with all the duplicate ids removed @param l a list of ids in external form. @exception StandardException Oops. */ public static String pruneDups(String l) throws StandardException { if (l == null) return null; String[] normal_a = parseIdList(l); StringReader r = new StringReader(l); String[] external_a = parseIdList(r,false); HashSet h = new HashSet(); Vector v = new Vector(); for(int ix=0;ix<normal_a.length;ix++) { if (!h.contains(normal_a[ix])) { h.add(normal_a[ix]); v.addElement(external_a[ix]); } } return vectorToIdList(v,false); } /** Produce a string form of an idList from an array of normalized ids. */ public static String mkIdList(String[] ids) { StringBuffer sb = new StringBuffer(); for (int ix=0;ix<ids.length; ix++) { if (ix != 0) sb.append(","); sb.append(IdUtil.delimitId(ids[ix])); } return sb.toString(); } /** Produce an id list from an array of ids in external form */ private static String mkIdListAsEntered(String[] externalIds ) { StringBuffer sb = new StringBuffer(); for (int ix=0;ix<externalIds.length; ix++) { if (ix != 0) sb.append(","); sb.append(externalIds[ix]); } return sb.toString(); } private static void verifyListEmpty(StringReader r) throws StandardException { try { if (r.read() != -1) throw StandardException.newException(SQLState.ID_LIST_PARSE_ERROR); } catch (IOException ioe){ throw StandardException.newException(SQLState.ID_LIST_PARSE_ERROR,ioe); } } /** Return true if the id provided is on the list provided. @param id an id in normal form @list a list of ids in external form. @exception StandardException oops. */ public static boolean idOnList(String id, String list) throws StandardException { if (list==null) return false; String[] list_a = parseIdList(list); for (int ix=0; ix < list_a.length; ix++) if (id.equals(list_a[ix])) return true; return false; } /** Delete an id from a list of ids. @param id an id in normal form (quotes removed, upshifted) @param list a comma separated list of ids in external form (possibly delmited or not upshifted). @return the list with the id deleted or null if the resulting list has no ids. If 'id' is not on 'list' this returns list unchanged. @exception StandardException oops. */ public static String deleteId(String id, String list) throws StandardException { if (list==null) return null; Vector v = new Vector(); StringReader r = new StringReader(list); String[] enteredList_a = parseIdList(r,false); // //Loop through enteredList element by element //removing elements that match id. Before we //compare we parse each id in list to convert //to normal form. for (int ix=0; ix < enteredList_a.length; ix++) if (!id.equals(IdUtil.parseId(enteredList_a[ix]))) v.addElement(enteredList_a[ix]); if (v.size() == 0) return null; else return vectorToIdList(v,false); } /** Append an id in external form. @return the list with the id appended. @exception StandardException oops */ public static String appendId(String id, String list) throws StandardException { if (list==null) return id; else return list+","+id; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -