Skip to content

Commit

Permalink
ACN:Add compartors on Vector and Bin
Browse files Browse the repository at this point in the history
  • Loading branch information
Slashgear committed Apr 26, 2015
1 parent 71d61a4 commit 602564a
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

package com.polytech4A.cuttingstock.core.model;

import java.util.Comparator;

/**
* Created by Antoine CARON on 12/03/2015.
*
Expand All @@ -28,7 +30,7 @@
* <p>
* Representation of a classic mathematical 2D vector for Position of Size.
*/
public class Vector {
public class Vector implements Comparable<Vector> {

/**
* Horizontal value.
Expand Down Expand Up @@ -102,6 +104,7 @@ public Vector getInvertedVector() {

/**
* Check if one of dimensions equals 0.
*
* @return True if one of x or y equals 0.
*/
public boolean isDimensionNull() {
Expand All @@ -120,4 +123,48 @@ public boolean equals(Object obj) {
public Vector clone() {
return new Vector(getX(), getY());
}


@Override
public int compareTo(Vector o) {
return Comparators.AREA.compare(this, o);
}

public static class Comparators {
/**
* Compares the X sizes of the boxes.
*
* @see com.polytech4A.cuttingstock.core.model.Vector
*/
public static Comparator<Vector> X = new Comparator<Vector>() {
@Override
public int compare(Vector o1, Vector o2) {
return (int) (o1.getX() - o2.getX());
}
};

/**
* Compares the X sizes of the boxes.
*
* @see com.polytech4A.cuttingstock.core.model.Vector
*/
public static Comparator<Vector> Y = new Comparator<Vector>() {
@Override
public int compare(Vector o1, Vector o2) {
return (int) (o1.getY() - o2.getY());
}
};

/**
* Compares the X sizes of the boxes.
*
* @see com.polytech4A.cuttingstock.core.model.Vector
*/
public static Comparator<Vector> AREA = new Comparator<Vector>() {
@Override
public int compare(Vector o1, Vector o2) {
return (int) (o1.getArea() - o2.getArea());
}
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
* @author Antoine CARON
* @version 1.0
*/
public class Bin {
public class Bin implements Comparable<Bin> {
/**
* Size of the Bin.
*/
Expand Down Expand Up @@ -140,4 +140,10 @@ public void disableSubBinFromBin(ArrayList<Bin> bins) {
}
});
}


@Override
public int compareTo(Bin o) {
return this.size.compareTo(o.getSize());
}
}

0 comments on commit 602564a

Please sign in to comment.