Skip to content

Commit f560756

Browse files
author
Stanislav Rakitov
authored
Merge pull request #3 from ProsperousRF/Week4
Week4
2 parents 92e3fab + d2b2efa commit f560756

21 files changed

+1265
-0
lines changed

.idea/modules.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Week4/Week4.iml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module type="JAVA_MODULE" version="4">
3+
<component name="NewModuleRootManager" inherit-compiler-output="true">
4+
<exclude-output />
5+
<content url="file://$MODULE_DIR$">
6+
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
7+
</content>
8+
<orderEntry type="inheritedJdk" />
9+
<orderEntry type="sourceFolder" forTests="false" />
10+
<orderEntry type="module-library" exported="">
11+
<library>
12+
<CLASSES>
13+
<root url="jar://$MODULE_DIR$/../../apache-csv.jar!/" />
14+
</CLASSES>
15+
<JAVADOC />
16+
<SOURCES>
17+
<root url="jar://$MODULE_DIR$/../../apache-csv.jar!/" />
18+
</SOURCES>
19+
</library>
20+
</orderEntry>
21+
<orderEntry type="module-library" exported="">
22+
<library>
23+
<CLASSES>
24+
<root url="jar://$MODULE_DIR$/../../courserajava.jar!/" />
25+
</CLASSES>
26+
<JAVADOC />
27+
<SOURCES>
28+
<root url="jar://$MODULE_DIR$/../../courserajava.jar!/" />
29+
</SOURCES>
30+
</library>
31+
</orderEntry>
32+
</component>
33+
</module>

Week4/src/AllFilters.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import java.util.ArrayList;
2+
3+
public class AllFilters implements Filter {
4+
ArrayList<Filter> filters;
5+
6+
public AllFilters() {
7+
filters = new ArrayList<>();
8+
}
9+
10+
public void addFilter(Filter f) {
11+
filters.add(f);
12+
}
13+
14+
@Override
15+
public boolean satisfies(String id) {
16+
for (Filter f : filters) {
17+
if (!f.satisfies(id)) {
18+
return false;
19+
}
20+
}
21+
22+
return true;
23+
}
24+
}

Week4/src/DirectorsFilter.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* A class for filter movies by directors
3+
*
4+
* @author Stanislav Rakitov
5+
* @version 1.0
6+
*/
7+
public class DirectorsFilter implements Filter {
8+
String directors;
9+
10+
public DirectorsFilter(String directors) {
11+
this.directors = directors;
12+
}
13+
14+
@Override
15+
public boolean satisfies(String id) {
16+
String movieDirectors = MovieDatabase.getDirector(id);
17+
String[] filterDirectors = directors.split(",");
18+
for (String direcor : filterDirectors) {
19+
if (movieDirectors.contains(direcor)) {
20+
return true;
21+
}
22+
}
23+
return false;
24+
}
25+
}

Week4/src/EfficientRater.java

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import java.util.ArrayList;
2+
import java.util.HashMap;
3+
4+
/**
5+
* The class EfficientRater keeps track of one rater and all their ratings.
6+
*
7+
* @author Stanislav Rakitov
8+
* @version 1.0
9+
*/
10+
public class EfficientRater implements Rater {
11+
private final String myID;
12+
private final HashMap<String, Rating> myRatings;
13+
14+
public EfficientRater(String id) {
15+
myID = id;
16+
myRatings = new HashMap<>();
17+
}
18+
19+
public void addRating(String movieID, double rating) {
20+
myRatings.put(movieID, new Rating(movieID, rating));
21+
}
22+
23+
public boolean hasRating(String movieID) {
24+
return myRatings.containsKey(movieID);
25+
}
26+
27+
public String getID() {
28+
return myID;
29+
}
30+
31+
public double getRating(String movieID) {
32+
Rating rating = myRatings.get(movieID);
33+
if (rating != null) {
34+
return rating.getValue();
35+
} else {
36+
return -1;
37+
}
38+
}
39+
40+
public int numRatings() {
41+
return myRatings.size();
42+
}
43+
44+
public ArrayList<String> getItemsRated() {
45+
return new ArrayList<>(myRatings.keySet());
46+
}
47+
48+
public HashMap<String, Rating> getMyRatings() {
49+
return myRatings;
50+
}
51+
}

Week4/src/Filter.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
public interface Filter {
2+
boolean satisfies(String id);
3+
}

0 commit comments

Comments
 (0)