Util.java revision 1790
381N/A * Copyright 2005-2008 Sun Microsystems, Inc. All Rights Reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 0N/A * published by the Free Software Foundation. Sun designates this 0N/A * particular file as subject to the "Classpath" exception as provided 0N/A * by Sun in the LICENSE file that accompanied this code. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 0N/A * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 0N/A * CA 95054 USA or visit www.sun.com if you need additional information or 0N/A * have any questions. 0N/A /* This method can be used by code that is deliberately violating the 0N/A * allowed checked casts. Rather than marking the whole method containing 0N/A * the code with @SuppressWarnings, you can use a call to this method for 0N/A * the exact place where you need to escape the constraints. Typically 0N/A * you will "import static" this method and then write either 0N/A * or, if that doesn't work (e.g. X is a type variable) 443N/A * Computes a descriptor hashcode from its names and values. 443N/A * @param names the sorted array of descriptor names. 443N/A * @param values the array of descriptor values. 443N/A * @return a hash code value, as described in {@link #hashCode(Descriptor)} 443N/A // hashcode of a list containing just v is 443N/A // v.hashCode() + 31, see List.hashCode() 528N/A /** Match a part of a string against a shell-style pattern. 528N/A The only pattern characters recognized are <code>?</code>, 528N/A standing for any one character, 528N/A and <code>*</code>, standing for any string of 528N/A characters, including the empty string. For instance, 528N/A {@code wildmatch("sandwich","sa?d*ch",1,4,1,4)} will match 528N/A {@code "and"} against {@code "a?d"}. 528N/A @param str the string containing the sequence to match. 528N/A @param pat a string containing a pattern to match the sub string 528N/A @param stri the index in the string at which matching should begin. 528N/A @param strend the index in the string at which the matching should 528N/A @param pati the index in the pattern at which matching should begin. 528N/A @param patend the index in the pattern at which the matching should 528N/A @return true if and only if the string matches the pattern. 528N/A /* The algorithm is a classical one. We advance pointers in 528N/A parallel through str and pat. If we encounter a star in pat, 528N/A we remember its position and continue advancing. If at any 528N/A stage we get a mismatch between str and pat, we look to see if 528N/A there is a remembered star. If not, we fail. If so, we 528N/A retreat pat to just past that star and str to the position 528N/A after the last one we tried, and we let the match advance 528N/A Even though there is only one remembered star position, the 528N/A algorithm works when there are several stars in the pattern. 528N/A When we encounter the second star, we forget the first one. 528N/A This is OK, because if we get to the second star in A*B*C 528N/A (where A etc are arbitrary strings), we have already seen AXB. 528N/A We're therefore setting up a match of *C against the remainder 528N/A of the string, which will match if that remainder looks like 528N/A YC, so the whole string looks like AXBYC. 528N/A // System.out.println("matching "+pat.substring(pati,patend)+ 528N/A // " against "+str.substring(stri, strend)); 528N/A /* On each pass through this loop, we either advance pati, 528N/A or we backtrack pati and advance starstri. Since starstri 528N/A is only ever assigned from pati, the loop must terminate. */ 528N/A // Mismatched, can we backtrack to a "*"? 528N/A // Retry the match one position later in str 528N/A /** Match a string against a shell-style pattern. The only pattern 528N/A characters recognized are <code>?</code>, standing for any one 528N/A character, and <code>*</code>, standing for any string of 528N/A characters, including the empty string. 528N/A @param str the string to match. 528N/A @param pat the pattern to match the string against. 528N/A @return true if and only if the string matches the pattern.