Skip to content

Commit 947d1fb

Browse files
committed
Task 2: Complete the implementation of the filter package
1 parent d9ad8da commit 947d1fb

File tree

13 files changed

+136
-4
lines changed

13 files changed

+136
-4
lines changed

SoftwareConstruction_ObjectOrientedDesign/finalProject/final-project-starter/TwitterMapperStarter/.idea/inspectionProfiles/Project_Default.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
1.59 KB
Binary file not shown.
1.58 KB
Binary file not shown.
0 Bytes
Binary file not shown.
684 Bytes
Binary file not shown.
118 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
176 Bytes
Binary file not shown.
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package filters;
2+
3+
import twitter4j.Status;
4+
5+
import java.util.ArrayList;
6+
import java.util.List;
7+
8+
/**
9+
* A filter that represents the logical not of its child0 filter
10+
*/
11+
public class AndFilter implements Filter {
12+
13+
private final Filter child0;
14+
private final Filter child1;
15+
16+
17+
public AndFilter(Filter child, Filter child1) {
18+
this.child0 = child;
19+
this.child1 = child1;
20+
}
21+
22+
/**
23+
* @param s0 the tweet to check
24+
* @param s1 the next tweet to check
25+
* @return 2 status are matches
26+
*/
27+
public boolean matches(Status s0, Status s1) {
28+
return child0.matches(s0) && child1.matches(s1) || child0.matches(s1) && child1.matches(s0);
29+
}
30+
31+
@Override
32+
public boolean matches(Status s) {
33+
return false;
34+
}
35+
36+
@Override
37+
public List<String> terms() {
38+
return child0.terms();
39+
}
40+
41+
public List<String> andTerms() {
42+
ArrayList<String> terms = new ArrayList<>();
43+
terms.add(String.valueOf(child0.terms()));
44+
terms.add(String.valueOf(child1.terms()));
45+
return terms;
46+
}
47+
48+
public String toString() {
49+
return child1.toString() + " and " + child0.toString();
50+
}
51+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package filters;
2+
3+
import twitter4j.Status;
4+
5+
import java.util.ArrayList;
6+
import java.util.List;
7+
8+
/**
9+
* A filter that represents the logical not of its child0 filter
10+
*/
11+
public class OrFilter implements Filter {
12+
13+
private final Filter child0;
14+
private final Filter child1;
15+
16+
17+
public OrFilter(Filter child, Filter child1) {
18+
this.child0 = child;
19+
this.child1 = child1;
20+
}
21+
22+
/**
23+
* A and filter matches when its child0 doesn't, and vice versa
24+
* @param s0 the tweet to check
25+
* @param s1 the next tweet to check
26+
* @return whether or not it matches
27+
*/
28+
public boolean matches(Status s0, Status s1) {
29+
return (child0.matches(s0) || child1.matches(s1)) || (child0.matches(s1) || child1.matches(s0));
30+
}
31+
32+
@Override
33+
public boolean matches(Status s) {
34+
return false;
35+
}
36+
37+
@Override
38+
public List<String> terms() {
39+
return child0.terms();
40+
}
41+
42+
public List<String> orTerms() {
43+
ArrayList<String> terms = new ArrayList<>();
44+
terms.add(String.valueOf(child0.terms()));
45+
terms.add(String.valueOf(child1.terms()));
46+
return terms;
47+
}
48+
49+
public String toString() {
50+
return child1.toString() + " or " + child0.toString();
51+
}
52+
}

0 commit comments

Comments
 (0)