Skip to content

Commit

Permalink
moditect#27 Added several graph algorithms
Browse files Browse the repository at this point in the history
  • Loading branch information
wuetherich committed Jan 17, 2019
1 parent 0745011 commit 3889dbb
Show file tree
Hide file tree
Showing 22 changed files with 1,873 additions and 59 deletions.
122 changes: 63 additions & 59 deletions javac-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,69 +17,73 @@
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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>
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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>

<parent>
<groupId>org.moditect.deptective</groupId>
<artifactId>deptective-aggregator</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<parent>
<groupId>org.moditect.deptective</groupId>
<artifactId>deptective-aggregator</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>deptective-javac-plugin</artifactId>
<artifactId>deptective-javac-plugin</artifactId>

<name>Deptective Javac Plug-in</name>
<name>Deptective Javac Plug-in</name>

<dependencies>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependencies>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.testing.compile</groupId>
<artifactId>compile-testing</artifactId>
<version>0.15</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.11.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.skyscreamer</groupId>
<artifactId>jsonassert</artifactId>
<version>1.5.0</version>
<scope>test</scope>
</dependency>
</dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.testing.compile</groupId>
<artifactId>compile-testing</artifactId>
<version>0.15</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.11.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.skyscreamer</groupId>
<artifactId>jsonassert</artifactId>
<version>1.5.0</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<!-- <fork>true</fork> -->
<!-- <compilerArgs> -->
<!-- <arg>-#-add-exports="jdk.compiler/com.sun.source.util=ALL-UNNAMED"</arg> -->
<!-- <arg>-#-add-exports="jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED"</arg> -->
<!-- <arg>-#-add-exports="jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED"</arg> -->
<!-- </compilerArgs> -->
</configuration>
</plugin>
</plugins>
</build>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<!-- <fork>true</fork> -->
<!-- <compilerArgs> -->
<!-- <arg>-#-add-exports="jdk.compiler/com.sun.source.util=ALL-UNNAMED"</arg> -->
<!-- <arg>-#-add-exports="jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED"</arg> -->
<!-- <arg>-#-add-exports="jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED"</arg> -->
<!-- </compilerArgs> -->
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/**
* Copyright 2019 The ModiTect authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.moditect.deptective.internal.graph;

import org.moditect.deptective.internal.graph.IDependency;

public class DefaultDependency implements IDependency {

private DefaultNode _from;

private DefaultNode _to;

private int aggregatdWeight;

/**
*
* @param from
* @param to
* @param aggregatdWeight
*/
public DefaultDependency(DefaultNode from, DefaultNode to, int aggregatdWeight) {
this._from = from;
this._to = to;
this.aggregatdWeight = aggregatdWeight;

from.addOutgoingDependency(this);
}

@Override
public DefaultNode getFrom() {
return _from;
}

@Override
public DefaultNode getTo() {
return _to;
}

@Override
public int getAggregatedWeight() {
return aggregatdWeight;
}

@Override
public String toString() {
return "SimpleDependency [from=" + _from + ", to=" + _to + ", aggregatdWeight=" + aggregatdWeight + "]";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
/**
* Copyright 2019 The ModiTect authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.moditect.deptective.internal.graph;

import static com.google.common.base.Preconditions.checkNotNull;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

import org.moditect.deptective.internal.graph.IDependency;
import org.moditect.deptective.internal.graph.INode;

/**
*
* @author Gerd W&uuml;therich ([email protected])
*/
public class DefaultNode implements INode {

//
private Map<INode, IDependency> _outgoingDependencies;

//
private String _id;

/**
*
* @param id
*/
public DefaultNode(String id) {
super();
this._id = id;
}

/**
*
* @return
*/
public String getId() {
return _id;
}

@Override
public IDependency getOutgoingDependencyTo(INode node) {

//
if (!hasOutgoingDependencies() || !_outgoingDependencies.containsKey(checkNotNull(node))) {
return null;
}

//
return _outgoingDependencies.get(node);
}

/**
*
*/
@Override
public Set<IDependency> getOutgoingDependenciesTo(Collection<INode> nodes) {
return checkNotNull(nodes).stream().map(node -> getOutgoingDependencyTo(node)).filter(dep -> dep != null)
.collect(Collectors.toSet());
}

/**
*
*/
@Override
public boolean hasOutgoingDependencies() {
return _outgoingDependencies != null && !_outgoingDependencies.isEmpty();
}

/**
*
* @param target
*/
public void addOutgoingDependency(DefaultDependency dependency) {
checkNotNull(dependency);
outgoingDependencies().put(dependency.getTo(), dependency);
}

@Override
public String toString() {
return "DummyNode [_id=" + _id + "]";
}

/**
*
* @return
*/
private Map<INode, IDependency> outgoingDependencies() {

//
if (_outgoingDependencies == null) {
_outgoingDependencies = new HashMap<>();
}

//
return _outgoingDependencies;
}

@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((_id == null) ? 0 : _id.hashCode());
return result;
}

@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
DefaultNode other = (DefaultNode) obj;
if (_id == null) {
if (other._id != null)
return false;
} else if (!_id.equals(other._id))
return false;
return true;
}
}
Loading

0 comments on commit 3889dbb

Please sign in to comment.