Skip to content

Commit 2b4ae79

Browse files
Merge branch 'dev'
2 parents 07a1343 + 7c46631 commit 2b4ae79

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+3271
-76
lines changed

.travis.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
language: java
22
jdk:
33
- oraclejdk8
4-
- oraclejdk7
5-
- openjdk7
64
notifications:
75
webhooks:
86
- http://octopull.rmhartog.me/api/travis/webhook

pom.xml

Lines changed: 75 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<groupId>nl.tudelft</groupId>
55
<artifactId>lifetiles</artifactId>
66
<packaging>jar</packaging>
7-
<version>1.0-SNAPSHOT</version>
7+
<version>1.2-SNAPSHOT</version>
88
<name>lifetiles</name>
99
<url>http://maven.apache.org</url>
1010
<properties>
@@ -17,10 +17,19 @@
1717
<version>4.12</version>
1818
<scope>test</scope>
1919
</dependency>
20+
<dependency>
21+
<groupId>org.mockito</groupId>
22+
<artifactId>mockito-all</artifactId>
23+
<version>1.9.5</version>
24+
<scope>test</scope>
25+
</dependency>
26+
<dependency>
27+
<groupId>org.jgrapht</groupId>
28+
<artifactId>jgrapht-core</artifactId>
29+
<version>0.9.1</version>
30+
</dependency>
2031
</dependencies>
2132
<build>
22-
<sourceDirectory>../src/main/java</sourceDirectory>
23-
2433
<plugins>
2534
<plugin>
2635
<groupId>org.apache.maven.plugins</groupId>
@@ -60,71 +69,74 @@
6069
</execution>
6170
</executions>
6271
</plugin>
63-
64-
65-
6672
<plugin>
67-
<groupId>org.codehaus.mojo</groupId>
68-
<artifactId>findbugs-maven-plugin</artifactId>
69-
<version>3.0.1</version>
73+
<groupId>org.apache.maven.plugins</groupId>
74+
<artifactId>maven-compiler-plugin</artifactId>
75+
<version>3.3</version>
7076
<configuration>
71-
<!--
72-
Enables analysis which takes more memory but finds more bugs.
73-
If you run out of memory, changes the value of the effort element
74-
to 'Low'.
75-
-->
76-
<effort>Max</effort>
77-
<!-- Build doesn't fail if problems are found -->
78-
<failOnError>false</failOnError>
79-
<!-- Reports all bugs (other values are medium and max) -->
80-
<threshold>Low</threshold>
81-
<!-- Produces XML report -->
82-
<xmlOutput>true</xmlOutput>
83-
<!-- Configures the directory in which the XML report is created -->
84-
<findbugsXmlOutputDirectory>${project.build.directory}/findbugs</findbugsXmlOutputDirectory>
77+
<source>1.8</source>
78+
<target>1.8</target>
8579
</configuration>
86-
<executions>
87-
<!--
88-
Ensures that FindBugs inspects source code when project is compiled.
89-
-->
90-
<execution>
91-
<id>analyze-compile</id>
92-
<phase>compile</phase>
93-
<goals>
94-
<goal>check</goal>
95-
</goals>
96-
</execution>
97-
</executions>
9880
</plugin>
99-
</plugins>
100-
</build>
10181

10282

83+
<plugin>
84+
<groupId>org.codehaus.mojo</groupId>
85+
<artifactId>findbugs-maven-plugin</artifactId>
86+
<version>3.0.1</version>
87+
<configuration>
88+
<!-- Enables analysis which takes more memory but finds more bugs. If
89+
you run out of memory, changes the value of the effort element to 'Low'. -->
90+
<effort>Max</effort>
91+
<!-- Build doesn't fail if problems are found -->
92+
<failOnError>false</failOnError>
93+
<!-- Reports all bugs (other values are medium and max) -->
94+
<threshold>Low</threshold>
95+
<!-- Produces XML report -->
96+
<xmlOutput>true</xmlOutput>
97+
<!-- Configures the directory in which the XML report is created -->
98+
<findbugsXmlOutputDirectory>${project.build.directory}/findbugs</findbugsXmlOutputDirectory>
99+
</configuration>
100+
<executions>
101+
<!-- Ensures that FindBugs inspects source code when project is compiled. -->
102+
<execution>
103+
<id>analyze-compile</id>
104+
<phase>compile</phase>
105+
<goals>
106+
<goal>check</goal>
107+
</goals>
108+
</execution>
109+
</executions>
110+
</plugin>
111+
</plugins>
112+
</build>
103113

104-
<reporting>
105-
<plugins>
106-
<plugin>
107-
<groupId>org.apache.maven.plugins</groupId>
108-
<artifactId>maven-pmd-plugin</artifactId>
109-
<version>3.4</version>
110-
</plugin>
111-
<plugin>
112-
<groupId>org.apache.maven.plugins</groupId>
113-
<artifactId>maven-checkstyle-plugin</artifactId>
114-
<version>2.14</version>
115-
<configuration>
116-
<failOnViolation>false</failOnViolation>
117-
<!--<configLocation>checkstyle.xml</configLocation>-->
118-
</configuration>
119-
</plugin>
120-
<plugin>
121-
<groupId>org.codehaus.mojo</groupId>
122-
<artifactId>findbugs-maven-plugin</artifactId>
123-
<version>3.0.1</version>
124-
<configuration>
125-
<failOnError>false</failOnError>
126-
</configuration>
127-
</plugin>
128-
</plugins>
129-
</reporting>
114+
115+
116+
<reporting>
117+
<plugins>
118+
<plugin>
119+
<groupId>org.apache.maven.plugins</groupId>
120+
<artifactId>maven-pmd-plugin</artifactId>
121+
<version>3.4</version>
122+
</plugin>
123+
<plugin>
124+
<groupId>org.apache.maven.plugins</groupId>
125+
<artifactId>maven-checkstyle-plugin</artifactId>
126+
<version>2.14</version>
127+
<configuration>
128+
<failOnViolation>false</failOnViolation>
129+
<!--<configLocation>checkstyle.xml</configLocation> -->
130+
</configuration>
131+
</plugin>
132+
<plugin>
133+
<groupId>org.codehaus.mojo</groupId>
134+
<artifactId>findbugs-maven-plugin</artifactId>
135+
<version>3.0.1</version>
136+
<configuration>
137+
<failOnError>false</failOnError>
138+
</configuration>
139+
</plugin>
140+
</plugins>
141+
</reporting>
130142
</project>
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package nl.tudelft.lifetiles.controller;
2+
3+
import java.util.HashSet;
4+
import java.util.Map;
5+
import java.util.Observable;
6+
import java.util.Set;
7+
8+
import nl.tudelft.lifetiles.graph.Sequence;
9+
10+
/**
11+
* @author Rutger van den Berg
12+
* Controls what the view modules display.
13+
*/
14+
public class ViewController extends Observable {
15+
/**
16+
* Map of all sequences currently loaded.
17+
*/
18+
private Map<String, Sequence> sequenceMap;
19+
/**
20+
* Set containing all sequences currently loaded.
21+
*/
22+
private Set<Sequence> allSequences;
23+
/**
24+
* Set containing the currently visible sequences.
25+
*/
26+
private Set<Sequence> visibleSequences;
27+
28+
/**
29+
* Creates a new viewcontroller.
30+
*
31+
* @param sequences
32+
* The current sequences.
33+
*/
34+
public ViewController(final Map<String, Sequence> sequences) {
35+
sequenceMap = sequences;
36+
allSequences = new HashSet<>();
37+
38+
for (Map.Entry<String, Sequence> map : sequenceMap.entrySet()) {
39+
Sequence seq = map.getValue();
40+
allSequences.add(seq);
41+
}
42+
visibleSequences = new HashSet<>(allSequences);
43+
}
44+
45+
/**
46+
* Sets the visible sequences in all views to the provided sequences.
47+
*
48+
* @param sequences
49+
* The sequences to set to visible.
50+
*/
51+
public final void setVisible(final Set<Sequence> sequences) {
52+
visibleSequences = sequences;
53+
if (visibleSequences.retainAll(allSequences)) {
54+
throw new IllegalArgumentException(
55+
"Attempted to set a non-existant sequence to visible");
56+
}
57+
setChanged();
58+
notifyObservers();
59+
}
60+
61+
/**
62+
* @return A set containing all visible sequences.
63+
*/
64+
public final Set<Sequence> getVisible() {
65+
return visibleSequences;
66+
}
67+
68+
}
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
package nl.tudelft.lifetiles.graph;
2+
3+
import java.io.File;
4+
import java.io.IOException;
5+
import java.net.URISyntaxException;
6+
import java.nio.file.Files;
7+
import java.util.HashMap;
8+
import java.util.HashSet;
9+
import java.util.Iterator;
10+
import java.util.Map;
11+
import java.util.Set;
12+
13+
/**
14+
* @author Rutger van den Berg
15+
*
16+
*/
17+
public class DefaultGraphParser implements GraphParser {
18+
/**
19+
* Index of starting position in the vertex descriptor.
20+
*/
21+
private static final int START_POS = 2;
22+
/**
23+
* Index of end position in the vertex descriptor.
24+
*/
25+
private static final int END_POS = 3;
26+
27+
/**
28+
* @param filename
29+
* The basename of the file to parse.
30+
* @param gfact
31+
* The graph factory to use to produce the graph.
32+
* @return a new graph containing the parsed information.
33+
*/
34+
@Override
35+
public final Graph<SequenceSegment> parseFile(final String filename,
36+
final GraphFactory<SequenceSegment> gfact) {
37+
Graph<SequenceSegment> graph = gfact.getGraph();
38+
parseVertices(filename, graph);
39+
parseEdges(filename, graph);
40+
return graph;
41+
}
42+
43+
/**
44+
* @param filename
45+
* name of the file to parse.
46+
* @param graph
47+
* The graph to which the edges will be added.
48+
*/
49+
private void parseEdges(final String filename,
50+
final Graph<SequenceSegment> graph) {
51+
try {
52+
File file = new File(this.getClass()
53+
.getResource("/" + filename + ".edge.graph").toURI());
54+
Iterator<String> it = Files.lines(file.toPath()).iterator();
55+
String line;
56+
while (it.hasNext()) {
57+
line = it.next();
58+
String[] edge = line.split(" ");
59+
graph.addEdge(Integer.parseInt(edge[0]),
60+
Integer.parseInt(edge[1]));
61+
}
62+
} catch (IOException e) {
63+
e.printStackTrace();
64+
} catch (URISyntaxException e) {
65+
e.printStackTrace();
66+
}
67+
}
68+
69+
/**
70+
* @param filename
71+
* name of the file to parse.
72+
* @param graph
73+
* The graph to which the edges will be added.
74+
*/
75+
private void parseVertices(final String filename,
76+
final Graph<SequenceSegment> graph) {
77+
Map<String, Sequence> sequences = new HashMap<>();
78+
try {
79+
File file = new File(this.getClass()
80+
.getResource("/" + filename + ".node.graph").toURI());
81+
Iterator<String> it = Files.lines(file.toPath()).iterator();
82+
while (it.hasNext()) {
83+
graph.addVertex(createSegment(it.next(), it.next(), sequences));
84+
}
85+
} catch (IOException e) {
86+
e.printStackTrace();
87+
} catch (URISyntaxException e) {
88+
e.printStackTrace();
89+
}
90+
}
91+
92+
/**
93+
* @param descriptor
94+
* Description line in the vertex file.
95+
* @param content
96+
* Content line in the vertex file.
97+
* @param sequences
98+
* A map containing sequences that have already been seen.
99+
* @return a new SequenceSegment
100+
*/
101+
private SequenceSegment createSegment(final String descriptor,
102+
final String content, final Map<String, Sequence> sequences) {
103+
if (!descriptor.startsWith(">")) {
104+
throw new IllegalArgumentException();
105+
}
106+
String[] desc = descriptor.split("\\|");
107+
String[] sources = desc[2].split(",");
108+
Set<Sequence> currentSequences = new HashSet<>();
109+
for (String sequencename : sources) {
110+
if (!sequences.containsKey(sequencename.trim())) {
111+
sequences.put(sequencename, new SequenceImplementation(
112+
sequencename));
113+
}
114+
currentSequences.add(sequences.get(sequencename));
115+
}
116+
117+
return new SequenceSegment(currentSequences,
118+
Integer.parseInt(desc[START_POS].trim()),
119+
Integer.parseInt(desc[END_POS].trim()), content.trim());
120+
121+
}
122+
123+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package nl.tudelft.lifetiles.graph;
2+
3+
/**
4+
* @author Rutger van den Berg Interface for generic edge.
5+
* @param <V>
6+
* The type of vertex to use for this Edge.
7+
*/
8+
public interface Edge<V> {
9+
10+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package nl.tudelft.lifetiles.graph;
2+
3+
/**
4+
* @author Rutger van den Berg
5+
* @param <V> The type of vertex to use.
6+
*/
7+
public interface EdgeFactory<V> {
8+
/**
9+
* @return A new edge from <code>v1</code> to <code>v2</code>
10+
* @param v1 The source vertex.
11+
* @param v2 The destination vertex.
12+
*/
13+
Edge<V> getEdge(final V v1, final V v2);
14+
}

0 commit comments

Comments
 (0)