Here you can find the source of wildcardCompare(String s, String z)
public static int wildcardCompare(String s, String z)
//package com.java2s; /*/*from w w w . j ava2 s.com*/ * Copyright (c) Davide Raccagni (2006, 2009). All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ public class Main { public static int wildcardCompare(String s, String z) { if (s.equals("*") || z.equals("*")) { return 0; } int l = s.length(); int m = z.length(); int i = 0; int j = 0; while (j < m && i < l) { char c = s.charAt(i); char k = z.charAt(j); if (c != '*' && k != '*') { if (k != c) { return ((int) k) - ((int) c) > 0 ? 1 : -1; } i++; j++; } else if (c == '*') { if (i == l - 1) { // s ends w/ a * return 0; } else if (i < l - 2 && s.charAt(i + 1) == k) { i += 2; } j++; } else { // if (k == '*') { if (j == m - 1) { // z ends w/ a * return 0; } else if (j < m - 2 && z.charAt(j + 1) == c) { j += 2; } i++; } } return i == l && j == m ? 0 : (i < l ? -1 : 1); } }