hw1: Ex5 tested

This commit is contained in:
Claudio Maggioni (maggicl) 2019-10-21 10:45:09 +02:00
parent ae127b3240
commit 67dbbe3f64
3 changed files with 18 additions and 1 deletions

2
hw1/.gitignore vendored
View file

@ -1,3 +1,5 @@
**/target/**/*
*.pdf *.pdf
## Core latex/pdflatex auxiliary files: ## Core latex/pdflatex auxiliary files:

View file

@ -4,13 +4,15 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<!-- run with: mvn clean install exec:java -->
<groupId>ch.usi.inf.pf3.hw1</groupId> <groupId>ch.usi.inf.pf3.hw1</groupId>
<artifactId>ex5</artifactId> <artifactId>ex5</artifactId>
<version>1.0-SNAPSHOT</version> <version>1.0-SNAPSHOT</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<build> <build>
<finalName>${artifactId}</finalName> <finalName>${project.artifactId}</finalName>
<plugins> <plugins>
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
@ -31,6 +33,14 @@
</archive> </archive>
</configuration> </configuration>
</plugin> </plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<configuration>
<mainClass>reentrantrwlock.Main</mainClass>
</configuration>
</plugin>
</plugins> </plugins>
</build> </build>
</project> </project>

View file

@ -31,6 +31,7 @@ public class MovieCatalog {
int length; int length;
rLock.lock(); rLock.lock();
length = movies.size(); length = movies.size();
System.out.println("The movies catalog size is: " + length);
rLock.unlock(); rLock.unlock();
return length; return length;
} }
@ -45,6 +46,7 @@ public class MovieCatalog {
Movie m; Movie m;
rLock.lock(); rLock.lock();
m = movies.get(title); m = movies.get(title);
System.out.println("Getting movie: " + m.getTitle());
rLock.unlock(); rLock.unlock();
return m; return m;
} }
@ -57,6 +59,7 @@ public class MovieCatalog {
List<String> titles; List<String> titles;
rLock.lock(); rLock.lock();
titles = new ArrayList<>(movies.keySet()); titles = new ArrayList<>(movies.keySet());
System.out.println("Getting title list of length " + titles.size());
rLock.unlock(); rLock.unlock();
return titles; return titles;
} }
@ -74,6 +77,7 @@ public class MovieCatalog {
it.next(); it.next();
} }
m = it.next(); m = it.next();
System.out.println("Getting random movie: " + m.getTitle());
rLock.unlock(); rLock.unlock();
return m; return m;
} }
@ -85,6 +89,7 @@ public class MovieCatalog {
public void addMovie(Movie movie) { public void addMovie(Movie movie) {
wLock.lock(); wLock.lock();
movies.put(movie.getTitle(), movie); movies.put(movie.getTitle(), movie);
System.out.println("Putting movie: " + movie.getTitle());
wLock.unlock(); wLock.unlock();
} }
} }