Skip to content
This repository has been archived by the owner on Nov 13, 2017. It is now read-only.

Commit

Permalink
Make code style like rest of optaplanner-examples: field and getters …
Browse files Browse the repository at this point in the history
…in same order
  • Loading branch information
ge0ffrey committed Mar 24, 2013
1 parent 2633a4a commit 9ac2aa4
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 91 deletions.
Expand Up @@ -23,16 +23,16 @@ private static Set<Job> countSuccessorsRecursively(final Job j) {
}

private final int id;
private Project parentProject;

private final boolean isSource;
private final boolean isSink;
private final List<Job> successors;
private final List<Job> recursiveSuccessors;
private final List<JobMode> jobModes;
private Project parentProject;
private final boolean isSource;

private final int maxDuration;
private final int maxResourceId;

private final boolean isSink;

private List<Job> predecessors = new ArrayList<Job>();

public Job(final int id, final Collection<JobMode> modes, final Collection<Job> successors, final JobType type) {
Expand Down Expand Up @@ -76,17 +76,45 @@ public int getId() {
return this.id;
}

public JobMode getJobMode(final int id) {
if (id < 1 || id > this.jobModes.size()) {
throw new IllegalArgumentException("Job " + this + " has not mode #" + id);
public Project getParentProject() {
return this.parentProject;
}

protected void setParentProject(final Project p) {
if (this.parentProject == null) {
this.parentProject = p;
} else {
throw new IllegalStateException("Cannot override parent project!");
}
return this.jobModes.get(id - 1);
}

public boolean isSink() {
return this.isSink;
}

public boolean isSource() {
return this.isSource;
}

public List<Job> getSuccessors() {
return this.successors;
}

public List<Job> getRecursiveSuccessors() {
return this.recursiveSuccessors;
}

public Collection<JobMode> getJobModes() {
return this.jobModes;
}

public JobMode getJobMode(final int id) {
if (id < 1 || id > this.jobModes.size()) {
throw new IllegalArgumentException("Job " + this + " has not mode #" + id);
}
return this.jobModes.get(id - 1);
}

public int getMaxDuration() {
return this.maxDuration;
}
Expand All @@ -95,44 +123,16 @@ public int getMaxResourceId() {
return this.maxResourceId;
}

public Project getParentProject() {
return this.parentProject;
}

public List<Job> getPredecessors() {
return this.predecessors;
}

public List<Job> getRecursiveSuccessors() {
return this.recursiveSuccessors;
}

public List<Job> getSuccessors() {
return this.successors;
}

private void isPreceededBy(final Job j) {
final Set<Job> predecessors = new HashSet<Job>(this.predecessors);
predecessors.add(j);
this.predecessors = Collections.unmodifiableList(new ArrayList<Job>(predecessors));
}

public boolean isSink() {
return this.isSink;
}

public boolean isSource() {
return this.isSource;
}

protected void setParentProject(final Project p) {
if (this.parentProject == null) {
this.parentProject = p;
} else {
throw new IllegalStateException("Cannot override parent project!");
}
}

@Override
public String toString() {
final StringBuilder builder = new StringBuilder();
Expand Down
Expand Up @@ -6,10 +6,9 @@
public class JobMode {

private final int id;
private Job parentJob;

private final int duration;

private Job parentJob;
private final Collection<ResourceRequirement> resourceRequirements;

public JobMode(final int id, final int duration, final Collection<ResourceRequirement> resourceRequirements) {
Expand All @@ -21,10 +20,6 @@ public JobMode(final int id, final int duration, final Collection<ResourceRequir
this.resourceRequirements = Collections.unmodifiableCollection(resourceRequirements);
}

public int getDuration() {
return this.duration;
}

public int getId() {
return this.id;
}
Expand All @@ -33,10 +28,6 @@ public Job getParentJob() {
return this.parentJob;
}

public Collection<ResourceRequirement> getResourceRequirements() {
return this.resourceRequirements;
}

protected void setParentJob(final Job parentJob) {
if (this.parentJob == null) {
this.parentJob = parentJob;
Expand All @@ -45,6 +36,14 @@ protected void setParentJob(final Job parentJob) {
}
}

public int getDuration() {
return this.duration;
}

public Collection<ResourceRequirement> getResourceRequirements() {
return this.resourceRequirements;
}

@Override
public String toString() {
final StringBuilder builder = new StringBuilder();
Expand Down
Expand Up @@ -18,17 +18,18 @@ public int compare(final Integer arg0, final Integer arg1) {
}

private final List<Project> projects;
private final int maxDuration;
private final int maxStartDate;
private final int maxResourceId;

private final int minReleaseDate;
private final int maxStartDate;
private final int maxDuration;
private final int totalJobCount;
private final int maxResourceId;

public ProblemInstance(final Collection<Project> projects) {
// and now find the max due date for any of the projects
int maxDuration = Integer.MIN_VALUE;
int maxStartDate = Integer.MIN_VALUE;
int minReleaseDate = Integer.MAX_VALUE;
int maxStartDate = Integer.MIN_VALUE;
int maxDuration = Integer.MIN_VALUE;
int tmpJobCount = 0;
final List<Project> tmp = new ArrayList<Project>(projects.size());
for (final Project p : projects) {
Expand All @@ -44,10 +45,10 @@ public ProblemInstance(final Collection<Project> projects) {
Collections.max(p.getAvailableJobStartDates(), new IntegerComparator()));
tmpJobCount += p.getJobs().size();
}
this.totalJobCount = tmpJobCount;
this.minReleaseDate = minReleaseDate;
this.maxStartDate = maxStartDate;
this.maxDuration = maxDuration;
this.minReleaseDate = minReleaseDate;
this.totalJobCount = tmpJobCount;
this.projects = Collections.unmodifiableList(tmp);
int maxResourceId = Integer.MIN_VALUE;
for (final Project p : this.getProjects()) {
Expand All @@ -58,24 +59,24 @@ public ProblemInstance(final Collection<Project> projects) {
this.maxResourceId = maxResourceId;
}

public int getMaxAllowedDueDate() {
return this.maxStartDate + this.maxDuration;
}

public int getMaxResourceId() {
return this.maxResourceId;
public List<Project> getProjects() {
return this.projects;
}

public int getMinReleaseDate() {
return this.minReleaseDate;
}

public List<Project> getProjects() {
return this.projects;
public int getMaxAllowedDueDate() {
return this.maxStartDate + this.maxDuration;
}

public int getTotalNumberOfJobs() {
return this.totalJobCount;
}

public int getMaxResourceId() {
return this.maxResourceId;
}

}
Expand Up @@ -18,17 +18,15 @@ private static Collection<Integer> getStartDates(final int start, final double l
return Collections.unmodifiableCollection(startDates);
}

private ProblemInstance parentInstance;
private final int id;

private final int releaseDate;

private final List<Resource> resources;

private final List<Job> jobs;

private final int criticalPathDuration;

private ProblemInstance parentInstance;
private final Collection<Integer> startDates;

public Project(final int id, final int criticalPathDuration, final int releaseDate, final List<Resource> resources,
Expand All @@ -45,32 +43,40 @@ public Project(final int id, final int criticalPathDuration, final int releaseDa
* Project.TMD_MULTIPLIER);
}

public Collection<Integer> getAvailableJobStartDates() {
return this.startDates;
public ProblemInstance getParentInstance() {
return this.parentInstance;
}

public int getCriticalPathDuration() {
return this.criticalPathDuration;
protected void setParentInstance(final ProblemInstance parent) {
if (this.parentInstance == null) {
this.parentInstance = parent;
} else {
throw new IllegalStateException("Cannot override job's parent instance.");
}
}

public int getId() {
return this.id;
}

public int getReleaseDate() {
return this.releaseDate;
}

public List<Job> getJobs() {
return this.jobs;
}

public ProblemInstance getParentInstance() {
return this.parentInstance;
public List<Resource> getResources() {
return this.resources;
}

public int getReleaseDate() {
return this.releaseDate;
public int getCriticalPathDuration() {
return this.criticalPathDuration;
}

public List<Resource> getResources() {
return this.resources;
public Collection<Integer> getAvailableJobStartDates() {
return this.startDates;
}

private int getTheoreticalMaxDuration() {
Expand All @@ -88,14 +94,6 @@ private int getTheoreticalMaxDuration(final Job startWith) {
return max + startWith.getMaxDuration();
}

protected void setParentInstance(final ProblemInstance parent) {
if (this.parentInstance == null) {
this.parentInstance = parent;
} else {
throw new IllegalStateException("Cannot override job's parent instance.");
}
}

@Override
public String toString() {
final StringBuilder builder = new StringBuilder();
Expand Down
Expand Up @@ -7,17 +7,17 @@ public class Resource {
private static final AtomicInteger idGenerator = new AtomicInteger(0);

public static enum ResourceType {

RENEWABLE, NONRENEWABLE, DOUBLE_CONSTRAINED;

RENEWABLE,
NONRENEWABLE,
DOUBLE_CONSTRAINED;
}

private final int id;
private final int uniqueId;

private int capacity = -1;
private final boolean isGlobal;
private final boolean isRenewable;
private int capacity = -1;

public Resource(final int id) {
this.isGlobal = true;
Expand All @@ -36,10 +36,6 @@ public Resource(final int id, final ResourceType type) {
this.isRenewable = (type == ResourceType.RENEWABLE);
}

public int getCapacity() {
return this.capacity;
}

public int getId() {
return this.id;
}
Expand All @@ -63,6 +59,10 @@ public boolean isRenewable() {
return this.isRenewable;
}

public int getCapacity() {
return this.capacity;
}

public void setCapacity(final int capacity) {
if (this.capacity == -1) {
this.capacity = capacity;
Expand Down

0 comments on commit 9ac2aa4

Please sign in to comment.