@matfah/

Filter FR 2008

Java

No description

fork
loading
Files
  • Main.java
  • Filter.java
  • OrFilter.java
  • PartB.java

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.23518567926040967","path":"Main.java","file":{"path":"Main.java","content":{"asEncoding":{"base64":"aW1wb3J0IGphdmEubGFuZy5yZWZsZWN0Lio7CmltcG9ydCBqYXZhLnV0aWwuQXJyYXlMaXN0OwoKcHVibGljIGNsYXNzIE1haW4gewogIHB1YmxpYyBzdGF0aWMgdm9pZCBtYWluKFN0cmluZ1tdIGFyZ3MpIHsKICAgIGZvcihpbnQgaSA9IDA7IGkgPCAxMDsgaSsrKQogICAgICB0ZXN0T3JGaWx0ZXIoKTsKICAgICAgCiAgICBmb3IoaW50IGkgPSAwOyBpIDwgMTA7IGkrKykKICAgICAgdGVzdEJ1aWxkRmlsdGVyKCk7CiAgICAgIAogICAgU3lzdGVtLm91dC5wcmludGxuKCJBbGwgdGVzdHMgcGFzc2VkISIpOwogIH0KICAKICBwdWJsaWMgc3RhdGljIHZvaWQgY2hlY2tBbGxJbnN0YW5jZVZhcmlhYmxlc0FyZVByaXZhdGUoQ2xhc3MgYykgewogICAgRmllbGRbXSBmaWVsZHMgPSBjLmdldERlY2xhcmVkRmllbGRzKCk7CiAgICBmb3IoRmllbGQgZjogZmllbGRzKSB7CiAgICAgIGlmKChmLmdldE1vZGlmaWVycygpICYgTW9kaWZpZXIuUFJJVkFURSkgIT0gTW9kaWZpZXIuUFJJVkFURSkKICAgICAgewogICAgICAgIFN5c3RlbS5vdXQucHJpbnRsbigiTm90IGFsbCBmaWVsZHMgb2YgIiArIGMuZ2V0TmFtZSgpICsgIiBhcmUgcHJpdmF0ZSEiKTsKICAgICAgICBTeXN0ZW0uZXhpdCgwKTsKICAgICAgfQogICAgfQogIH0KICAKICBwdWJsaWMgc3RhdGljIHZvaWQgdGVzdE9yRmlsdGVyKCkgewogICAgY2hlY2tBbGxJbnN0YW5jZVZhcmlhYmxlc0Fy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b3NdLmluZGV4T2YodG9NYXRjaFttYXRjaFBvc09uZV0pIDwgMCB8fCBwaHJhc2VzW3BocmFzZVBvc10uaW5kZXhPZih0b01hdGNoW21hdGNoUG9zVHdvXSkgPCAwKSkgewogICAgICBTeXN0ZW0ub3V0LnByaW50bG4oIldyb25nIHJlc3VsdCByZXR1cm5lZCBieSBhY2NlcHQoKSBtZXRob2Qgb2YgT3JGaWx0ZXIgY2xhc3MiKTsKICAgICAgU3lzdGVtLmV4aXQoMCk7CiAgICB9CiAgICAKICB9CiAgCiAgcHVibGljIHN0YXRpYyB2b2lkIHRlc3RCdWlsZEZpbHRlcigpIHsKICAgIEZpbHRlciBmID0gbnVsbDsKICAgIAogICAgU3RyaW5nW10gcmFuZG9tID0geyJoYXBweSIsICJiaXJ0aGRheSIsICJhbWVyaWNhIn07CiAgICBTdHJpbmdbXSBnb29kID0geyJ0aGUiLCAiYW5kIiwgIm9yIiwgImJ1dCIsICJ3aHkifTsKICAgIFN0cmluZ1tdIGJhZCA9IHsieW9sbyIsICJidXJuIn07CiAgICAKICAgIEFycmF5TGlzdDxTdHJpbmc+IGdvb2RTZWxlY3QgPSBuZXcgQXJyYXlMaXN0PFN0cmluZz4oKTsKICAgIHdoaWxlKGdvb2RTZWxlY3Quc2l6ZSgpIDwgMikgewogICAgICBnb29kU2VsZWN0ID0gbmV3IEFycmF5TGlzdDxTdHJpbmc+KCk7CiAgICAgIGJvb2xlYW5bXSBnb29kQ2hvaWNlcyA9IHtNYXRoLnJhbmRvbSgpIDwgMC41LCAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIE1hdGgucmFuZG9tKCkgPCAwLjUsIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgTWF0aC5yYW5kb20oKSA8IDAuNSwgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBNYXRoLnJhbmRvbSgpIDwgMC41LCAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIE1hdGgucmFuZG9tKCkgPCAwLjV9OwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgCiAgICAgIGZvcihpbnQgaSA9IDA7IGkgPCBnb29kLmxlbmd0aDsgaSsrKSB7CiAgICAgICAgaWYoZ29vZENob2ljZXNbaV0pCiAgICAgICAgICBnb29kU2VsZWN0LmFkZChnb29kW2ldKTsKICAgICAgfQogICAgfQogICAgCiAgICBTdHJpbmdbXSBnb29kQ2hvaWNlID0gbmV3IFN0cmluZ1tnb29kU2VsZWN0LnNpemUoKV07CiAgICBmb3IoaW50IGkgPSAwOyBpIDwgZ29vZENob2ljZS5sZW5ndGg7IGkrKykgewogICAgICBnb29kQ2hvaWNlW2ldID0gZ29vZFNlbGVjdC5nZXQoaSk7CiAgICB9CiAgICAKICAgIGludCBiYWRDaG9pY2UgPSAoaW50KShNYXRoLnJhbmRvbSgpKjIpOwogICAgCiAgICB0cnkgewogICAgICBmID0gUGFydEIuYnVpbGRGaWx0ZXIoZ29vZENob2ljZSwgYmFkW2JhZENob2ljZV0pOwogICAgfQogICAgY2F0Y2goRXhjZXB0aW9uIGUpIHsKICAgICAgU3lzdGVtLm91dC5wcmludGxuKCJFcnJvciBjYWxsaW5nIGJ1aWxkRmlsdGVyKCkgbWV0aG9kIik7CiAgICAgIGUucHJpbnRTdGFja1RyYWNlKCk7CiAgICAgIFN5c3RlbS5leGl0KDApOwogICAgfQogICAgCiAgICBmb3IoaW50IGkgPSAwOyBpIDwgNTA7IGkrKykgewogICAgICBTdHJpbmcgbWVzc2FnZSA9ICIiOwogICAgICAKICAgICAgZm9yKGludCBqID0gMDsgaiA8IDc7IGorKykgewogICAgICAgIAogICAgICAgIGludCBjaG9pY2UgPSAoaW50KShNYXRoLnJhbmRvbSgpKjEwKTsKICAgICAgICBpZihjaG9pY2UgPCAzKQogICAgICAgICAgbWVzc2FnZSArPSByYW5kb21bY2hvaWNlXSArICIgIjsKICAgICAgICBlbHNlIGlmKGNob2ljZSA8IDgpCiAgICAgICAgICBtZXNzYWdlICs9IGdvb2RbY2hvaWNlIC0gM10gKyAiICI7CiAgICAgICAgZWxzZQogICAgICAgICAgbWVzc2FnZSArPSBiYWRbY2hvaWNlLThdICsgIiAiOwogICAgICB9CiAgICAKICAgIAogICAgICBib29sZWFuIHJlc3VsdCA9IGZhbHNlOwogICAgICAKICAgICAgdHJ5IHsKICAgICAgICByZXN1bHQgPSBmLmFjY2VwdChtZXNzYWdlKTsKICAgICAgfQogICAgICBjYXRjaChFeGNlcHRpb24gZSkgewogICAgICAgIFN5c3RlbS5vdXQucHJpbnRsbigiRXJyb3IgY2FsbGluZyBhY2NlcHQoKSBvbiBmaWx0ZXIgYnVpbHQgYnkgYnVpbGRGaWx0ZXIoKSBtZXRob2QhIik7CiAgICAgICAgU3lzdGVtLmV4aXQoMCk7CiAgICAgIH0KICAgICAgCiAgICAgIGJvb2xlYW4gbm9CYWQgPSBtZXNzYWdlLmluZGV4T2YoYmFkW2JhZENob2ljZV0pIDwgMDsKICAgICAgYm9vbGVhbiBoYXNHb29kID0gZmFsc2U7CiAgICAgIGZvcihTdHJpbmcgZyA6IGdvb2RDaG9pY2UpIHsKICAgICAgICBpZihtZXNzYWdlLmluZGV4T2YoZykgPj0gMCkgewogICAgICAgICAgaGFzR29vZCA9IHRydWU7CiAgICAgICAgICBicmVhazsKICAgICAgICB9CiAgICAgIH0KICAgICAgCiAgICAgIGlmKHJlc3VsdCAhPSAobm9CYWQgJiYgaGFzR29vZCkpIHsKICAgICAgICBTeXN0ZW0ub3V0LnByaW50bG4oIlJlc3VsdCBvZiBjYWxsaW5nIGFjY2VwdCgpIG9uIGZpbHRlciBidWlsdCBieSBidWlsZEZpbHRlcigpIG1ldGhvZCBpcyBpbmNvcnJlY3QiKTsKICAgICAgICBTeXN0ZW0uZXhpdCgwKTsKICAgICAgfQogICAgfQogICAgCiAgfQp9CgpjbGFzcyBTaW1wbGVGaWx0ZXIgaW1wbGVtZW50cyBGaWx0ZXIgewogIAogIHByaXZhdGUgU3RyaW5nIHN1YjsKICAKICBwdWJsaWMgU2ltcGxlRmlsdGVyKFN0cmluZyBzKSB7CiAgICBzdWIgPSBzOwogIH0KICAKICBwdWJsaWMgYm9vbGVhbiBhY2NlcHQoU3RyaW5nIHRleHQpIHsKICAgIHJldHVybiB0ZXh0LmluZGV4T2Yoc3ViKSAhPSAtMTsKICB9Cn0KCmNsYXNzIEFuZEZpbHRlciBpbXBsZW1lbnRzIEZpbHRlciB7CiAgCiAgcHJpdmF0ZSBGaWx0ZXIgYSwgYjsKICAKICBwdWJsaWMgQW5kRmlsdGVyKEZpbHRlciBhLCBGaWx0ZXIgYikgewogICAgdGhpcy5hID0gYTsKICAgIHRoaXMuYiA9IGI7CiAgfQogIAogIHB1YmxpYyBib29sZWFuIGFjY2VwdChTdHJpbmcgdGV4dCkgewogICAgcmV0dXJuIGEuYWNjZXB0KHRleHQpICYmIGIuYWNjZXB0KHRleHQpOwogIH0KfQoKY2xhc3MgTm90RmlsdGVyIGltcGxlbWVudHMgRmlsdGVyIHsKICBwcml2YXRlIEZpbHRlciBhOwogIGJvb2xlYW4gY2FsbGVkOwoKICBwdWJsaWMgTm90RmlsdGVyKEZpbHRlciBhKSB7CiAgICB0aGlzLmEgPSBhOwogIH0KICAKICBwdWJsaWMgYm9vbGVhbiBhY2NlcHQoU3RyaW5nIHRleHQpIHsKICAgIGNhbGxlZCA9IHRydWU7CiAgICByZXR1cm4gIWEuYWNjZXB0KHRleHQpOwogIH0KfQ=="},"asBuffer":null},"loaded":true}}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
import java.lang.reflect.*;
import java.util.ArrayList;

public class Main {
  public static void main(String[] args) {
    for(int i = 0; i < 10; i++)
      testOrFilter();
      
    for(int i = 0; i < 10; i++)
      testBuildFilter();
      
    System.out.println("All tests passed!");
  }
  
  public static void checkAllInstanceVariablesArePrivate(Class c) {
    Field[] fields = c.getDeclaredFields();
    for(Field f: fields) {
      if((f.getModifiers() & Modifier.PRIVATE) != Modifier.PRIVATE)
      {
        System.out.println("Not all fields of " + c.getName() + " are private!");
        System.exit(0);
      }
    }
  }
  
  public static void testOrFilter() {
    checkAllInstanceVariablesArePrivate(OrFilter.class);
    
    Constructor<OrFilter> cons = null;
    
    try {
      cons = OrFilter.class.getConstructor(Filter.class, Filter.class);
    }
    catch(Exception e) {
      System.out.println("OrFilter does not have a two parameter Filter constructor");
      System.exit(0);
    }
    
    OrFilter check = null;
    String[] toMatch = {"the", "pizza", "apple", "city"};
    String[] phrases = {"it's the end of the world as we know it", 
                        "did someone say pizza?",
                        "an apple a day keeps the doctor away",
                        "we built this city on rock and roll!"};
    
    int matchPosOne = (int)(Math.random()*toMatch.length);
    int matchPosTwo = (int)(Math.random()*toMatch.length);
    int phrasePos = (int)(Math.random()*phrases.length);

    NotFilter a = null;
    NotFilter b = null;

    try {
      a = new NotFilter(new SimpleFilter(toMatch[matchPosOne]));
      b = new NotFilter(new SimpleFilter(toMatch[matchPosTwo]));
      check = cons.newInstance(a, b);
    }
    catch(Exception e) {
      System.out.println("Error creating an instance of an OrFilter");
      System.exit(0);
    }
    
    
    //now, there isn't a way to see if they've initializes their fields correctly,
    //but let's make sure they initialize at least one of them!
    Field[] fields = OrFilter.class.getDeclaredFields();
    boolean didOne = false;
    for(Field f: fields) {
      f.setAccessible(true);
      Object value = null;

      //I'm not sure how this would generate an error...
      try {
        value = f.get(check);
      }
      catch(Exception e) {}
      
      if(value != null)
        didOne = true;
    }
    
    //this doesn't check if they initialized it correctly... 
    //that's almost impossible to tell...
    if(!didOne) {
      System.out.println("OrFilter constructor does not initialize an instance variable!");
      System.exit(0);
    }
    
    boolean result = false;
    
    try {
      result = check.accept(phrases[phrasePos]);
    }
    catch(Exception e) {
      System.out.println("Error calling accept() method of OrFilter class");
      System.exit(0);
    }
    
    //I do an and because you actually don't need to call both if the result should be false
    if(!a.called && !b.called) {
      System.out.println("OrFilter class does not call accept() method for each of the Filter objects it contains");
      System.exit(0);
    }
    
    if(result != (phrases[phrasePos].indexOf(toMatch[matchPosOne]) < 0 || phrases[phrasePos].indexOf(toMatch[matchPosTwo]) < 0)) {
      System.out.println("Wrong result returned by accept() method of OrFilter class");
      System.exit(0);
    }
    
  }
  
  public static void testBuildFilter() {
    Filter f = null;
    
    String[] random = {"happy", "birthday", "america"};
    String[] good = {"the", "and", "or", "but", "why"};
    String[] bad = {"yolo", "burn"};
    
    ArrayList<String> goodSelect = new ArrayList<String>();
    while(goodSelect.size() < 2) {
      goodSelect = new ArrayList<String>();
      boolean[] goodChoices = {Math.random() < 0.5, 
                               Math.random() < 0.5, 
                               Math.random() < 0.5, 
                               Math.random() < 0.5, 
                               Math.random() < 0.5};
                              
      
      for(int i = 0; i < good.length; i++) {
        if(goodChoices[i])
          goodSelect.add(good[i]);
      }
    }
    
    String[] goodChoice = new String[goodSelect.size()];
    for(int i = 0; i < goodChoice.length; i++) {
      goodChoice[i] = goodSelect.get(i);
    }
    
    int badChoice = (int)(Math.random()*2);
    
    try {
      f = PartB.buildFilter(goodChoice, bad[badChoice]);
    }
    catch(Exception e) {
      System.out.println("Error calling buildFilter() method");
      e.printStackTrace();
      System.exit(0);
    }
    
    for(int i = 0; i < 50; i++) {
      String message = "";
      
      for(int j = 0; j < 7; j++) {
        
        int choice = (int)(Math.random()*10);
        if(choice < 3)
          message += random[choice] + " ";
        else if(choice < 8)
          message += good[choice - 3] + " ";
        else
          message += bad[choice-8] + " ";
      }
    
    
      boolean result = false;
      
      try {
        result = f.accept(message);
      }
      catch(Exception e) {
        System.out.println("Error calling accept() on filter built by buildFilter() method!");
        System.exit(0);
      }
      
      boolean noBad = message.indexOf(bad[badChoice]) < 0;
      boolean hasGood = false;
      for(String g : goodChoice) {
        if(message.indexOf(g) >= 0) {
          hasGood = true;
          break;
        }
      }
      
      if(result != (noBad && hasGood)) {
        System.out.println("Result of calling accept() on filter built by buildFilter() method is incorrect");
        System.exit(0);
      }
    }
    
  }
}

class SimpleFilter implements Filter {
  
  private String sub;
  
  public SimpleFilter(String s) {
    sub = s;
  }
  
  public boolean accept(String text) {
    return text.indexOf(sub) != -1;
  }
}

class AndFilter implements Filter {
  
  private Filter a, b;
  
  public AndFilter(Filter a, Filter b) {
    this.a = a;
    this.b = b;
  }
  
  public boolean accept(String text) {
    return a.accept(text) && b.accept(text);
  }
}

class NotFilter implements Filter {
  private Filter a;
  boolean called;

  public NotFilter(Filter a) {
    this.a = a;
  }
  
  public boolean accept(String text) {
    called = true;
    return !a.accept(text);
  }
}