Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/alicebot/server/core/util/WildCardFilter.java


1   // Decompiled by Jad v1.5.8c. Copyright 2001 Pavel Kouznetsov.
2   // Jad home page: http://www.geocities.com/kpdus/jad.html
3   // Decompiler options: packimports(3) 
4   
5   package org.alicebot.server.core.util;
6   
7   import java.io.File;
8   import java.io.FilenameFilter;
9   
10  public final class WildCardFilter
11      implements FilenameFilter
12  {
13  
14      public WildCardFilter(String s, char c)
15      {
16          pattern = s;
17          wildCard = c;
18          int i = 0;
19          for(int j = 0; j < s.length(); j++)
20              if(c == s.charAt(j))
21                  i++;
22  
23          wildIndex = new int[i];
24          int k = 0;
25          for(int l = 0; k < i; l++)
26              if(c == s.charAt(l))
27                  wildIndex[k++] = l;
28  
29          if(i == 0)
30          {
31              prefix = null;
32              suffix = null;
33          } else
34          {
35              prefix = s.substring(0, wildIndex[0]);
36              suffix = s.substring(wildIndex[i - 1] + 1);
37          }
38      }
39  
40      public boolean accept(File file, String s)
41      {
42          if(wildIndex.length == 0)
43              return pattern.equals(s);
44          if(!s.startsWith(prefix) || !s.endsWith(suffix))
45              return false;
46          if(wildIndex.length == 1)
47              return true;
48          int i = s.length() - suffix.length();
49          int j = wildIndex[0];
50          int k = j;
51          for(int l = 1; l < wildIndex.length; l++)
52          {
53              int i1 = j + 1;
54              j = wildIndex[l];
55              int j1 = j - i1;
56              do
57              {
58                  if(j1 + k > i)
59                      return false;
60                  if(s.regionMatches(k, pattern, i1, j1))
61                      break;
62                  k++;
63              } while(true);
64              k += j1;
65          }
66  
67          return true;
68      }
69  
70      private String pattern;
71      private char wildCard;
72      private int wildIndex[];
73      private String prefix;
74      private String suffix;
75  }