* Fix PersonView setter and contructor.
* Add some javadoc.
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
private Color color;
private List<String> colorList = Arrays.asList("black", "green", "blue", "brown");
+ /**
+ *
+ * @param color
+ */
Eye(String color) {
setColor(color);
}
+ /**
+ *
+ * @return
+ */
public Color getColor() {
return color;
}
+ /**
+ *
+ * @param color
+ */
public void setColor(String color) {
if (validateColor(color)) {
if (color.equals("brown"))
}
}
+ /**
+ *
+ * @param color
+ * @return
+ */
private boolean validateColor(String color) {
return colorList.contains(color);
}
+ /**
+ *
+ * @param eye
+ * @return
+ */
@Override
public int compareTo(Eye eye) {
double r_diff = this.getColor().getRed() - eye.getColor().getRed();
public class EyeView {
private Eye eyeObj;
+ /**
+ *
+ * @param eyeObj
+ */
EyeView(Eye eyeObj) {
setEyeObj(eyeObj);
}
+ /**
+ *
+ * @return
+ */
public Eye getEyeObj() {
return eyeObj;
}
+ /**
+ *
+ * @param eyeObj
+ */
public void setEyeObj(Eye eyeObj) {
this.eyeObj = eyeObj;
}
@Override
public int compareTo(Firstname firstname) {
- //return StringUtils.getLevenshteinDistance(this.getFirstname(), firstname.getFirstname());
- return 0;
+ return LevenshteinDistance.computeLevenshteinDistance(this.getFirstname(), firstname.getFirstname());
}
-}
+}
\ No newline at end of file
--- /dev/null
+
+public class LevenshteinDistance {
+ /**
+ *
+ * @param a
+ * @param b
+ * @param c
+ * @return
+ */
+ private static int minimum(int a, int b, int c) {
+ return Math.min(Math.min(a, b), c);
+ }
+
+ /**
+ *
+ * @param lhs
+ * @param rhs
+ * @return
+ */
+ public static int computeLevenshteinDistance(CharSequence lhs, CharSequence rhs) {
+ int[][] distance = new int[lhs.length() + 1][rhs.length() + 1];
+
+ for (int i = 0; i <= lhs.length(); i++)
+ distance[i][0] = i;
+ for (int j = 1; j <= rhs.length(); j++)
+ distance[0][j] = j;
+
+ for (int i = 1; i <= lhs.length(); i++)
+ for (int j = 1; j <= rhs.length(); j++)
+ distance[i][j] = minimum(
+ distance[i - 1][j] + 1,
+ distance[i][j - 1] + 1,
+ distance[i - 1][j - 1] + ((lhs.charAt(i - 1) == rhs.charAt(j - 1)) ? 0 : 1));
+
+ return distance[lhs.length()][rhs.length()];
+ }
+}
}
@Override
- public int compare(Person person, Person t1) {
- return 0;
+ public int compare(Person p1, Person p2) {
+ return p1.compareTo(p2);
}
}
private WeightView weightView;
private EyeView eyeView;
+ PersonView(FirstnameView firstnameView, OriginView originView, SizeView sizeView, WeightView weightView, EyeView eyeView) {
+ setFirstnameView(firstnameView);
+ setOriginView(originView);
+ setSizeView(sizeView);
+ setWeightView(weightView);
+ setEyeView(eyeView);
+ }
+
+ /**
+ *
+ * @return
+ */
public FirstnameView getFirstnameView() {
return firstnameView;
}
+ /**
+ *
+ * @param firstnameView
+ */
public void setFirstnameView(FirstnameView firstnameView) {
this.firstnameView = firstnameView;
}
+ /**
+ *
+ * @return
+ */
public OriginView getOriginView() {
return originView;
}
+ /**
+ *
+ * @param originView
+ */
public void setOriginView(OriginView originView) {
this.originView = originView;
}
+ /**
+ *
+ * @return
+ */
public SizeView getSizeView() {
return sizeView;
}
+ /**
+ *
+ * @param sizeView
+ */
public void setSizeView(SizeView sizeView) {
this.sizeView = sizeView;
}
+ /**
+ *
+ * @return
+ */
public WeightView getWeightView() {
return weightView;
}
- public void setWeightView(EyeView eyeView) {
- this.eyeView = eyeView;
+ /**
+ *
+ * @param weightView
+ */
+ public void setWeightView(WeightView weightView) {
+ this.weightView = weightView;
}
+ /**
+ *
+ * @param eyeView
+ */
public void setEyeView(EyeView eyeView) {
this.eyeView = eyeView;
}
+ /**
+ *
+ * @return
+ */
public EyeView getEyeView() {
return eyeView;
}