forked from moditect/deptective
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
moditect#27 Added several graph algorithms
- Loading branch information
1 parent
0745011
commit 3889dbb
Showing
22 changed files
with
1,873 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
javac-plugin/src/main/java/org/moditect/deptective/internal/graph/DefaultDependency.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 + "]"; | ||
} | ||
} |
140 changes: 140 additions & 0 deletions
140
javac-plugin/src/main/java/org/moditect/deptective/internal/graph/DefaultNode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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ü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; | ||
} | ||
} |
Oops, something went wrong.