Commit fc62c362 authored by Sebastian Vollbrecht's avatar Sebastian Vollbrecht
Browse files

Cleaned up code.

This includes:
- removal of optionals as fields
- removal of unnecessary 'public abstract' modifiers in interfaces
- more lambdas and method reference usage
- simplified dataflow
- removal of faulty integer divisions
- renaming of expected exceptions in JUnit tests
- typo fixes
parent e876a5c2
Loading
Loading
Loading
Loading
+4 −5
Original line number Diff line number Diff line
@@ -17,7 +17,6 @@

package graphgen.datastructures;

import java.util.Optional;
import java.util.Random;

/**
@@ -28,7 +27,7 @@ import java.util.Random;
 */
public class SeededRandom {

	private Optional<Long> seed;
	private Long seed;

	private final Random rng;

@@ -38,7 +37,7 @@ public class SeededRandom {
	 */
	public SeededRandom() {
		this.rng = new Random();
		this.seed = Optional.empty();
		this.seed = null;
	}

	/**
@@ -58,7 +57,7 @@ public class SeededRandom {
	 * @param seed the seed to pass to the wrapped random instance
	 */
	public void setSeed(long seed) {
		this.seed = Optional.of(seed);
		this.seed = seed;
		rng.setSeed(seed);
	}

@@ -97,7 +96,7 @@ public class SeededRandom {
	}

	private void checkSeededStatus() {
		if (!seed.isPresent()) {
		if (seed == null) {
			throw new UnsupportedOperationException("Must set the seed first.");
		}
	}
+2 −2
Original line number Diff line number Diff line
@@ -34,11 +34,11 @@ public interface Initializable {
	 *
	 * @param rng the graph generator's random number generator
	 */
	public abstract void init(SeededRandom rng);
	void init(SeededRandom rng);

	/**
	 * Resets the implementing class, preparing it for the generation of a new graph. This method is called every time
	 * before the generator begins generating a new graph.
	 */
	public abstract void reset();
	void reset();
}
+2 −2
Original line number Diff line number Diff line
@@ -37,7 +37,7 @@ public interface EdgeCreationComponent extends Initializable {
	 *
	 * @param layers the layer structure to use
	 */
	public abstract void setLayerStructure(LayerStructure layers);
	void setLayerStructure(LayerStructure layers);

	/**
	 * Sets the ASAP times map of the implementing class, which can be used optionally for different purposes, such as
@@ -45,6 +45,6 @@ public interface EdgeCreationComponent extends Initializable {
	 *
	 * @param asapTimes the ASAP times map to use
	 */
	public abstract void setASAPTimesMap(Map<ResourceNode, Integer> asapTimes);
	void setASAPTimesMap(Map<ResourceNode, Integer> asapTimes);

}
+10 −7
Original line number Diff line number Diff line
@@ -27,7 +27,6 @@ import modsched.Edge;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;

/**
@@ -38,7 +37,7 @@ import java.util.Set;
public class IdenticalValueComputer extends ValueComputer {

	private final Map<ResourceNode, Map<ResourceNode, Integer>> edgeValues;
	private final Optional<Distribution<Integer>> defaultDistribution;
	private final Distribution<Integer> defaultDistribution;

	/**
	 * Constructs a new identical value computer for the specified {@link EdgeValue}, using the provided set of edges.
@@ -81,7 +80,7 @@ public class IdenticalValueComputer extends ValueComputer {

		}

		this.defaultDistribution = Optional.ofNullable(defaultDistribution);
		this.defaultDistribution = defaultDistribution;

	}

@@ -92,8 +91,8 @@ public class IdenticalValueComputer extends ValueComputer {
			return edgeValues.get(src).get(dst);
		}

		if (defaultDistribution.isPresent()) {
			return defaultDistribution.get().pick();
		if (defaultDistribution != null) {
			return defaultDistribution.pick();
		} else {
			throw new IllegalArgumentException("No edge value for nodes " + src + " and " + dst + " was given.");
		}
@@ -111,12 +110,16 @@ public class IdenticalValueComputer extends ValueComputer {

	@Override
	public void init(SeededRandom rng) {
		defaultDistribution.ifPresent(dist -> dist.init(rng));
		if (defaultDistribution != null) {
			defaultDistribution.init(rng);
		}
	}

	@Override
	protected void implementedReset() {
		defaultDistribution.ifPresent(Distribution::reset);
		if (defaultDistribution != null) {
			defaultDistribution.reset();
		}
	}

}
+1 −1
Original line number Diff line number Diff line
@@ -34,6 +34,6 @@ public interface FoldingStrategy<T> extends Initializable {
	 * @param values the list of values
	 * @return the folded value
	 */
	public abstract T fold(List<T> values);
	T fold(List<T> values);

}
Loading