Compare commits
No commits in common. "1583e33ab3fec7b3b25b9f17efa3858df0823bdd" and "eb2ffae473e2165cdf62733e0f2d070e7ce64717" have entirely different histories.
1583e33ab3
...
eb2ffae473
|
@ -1,11 +1,9 @@
|
||||||
package lab4;
|
package lab4;
|
||||||
|
|
||||||
|
/**
|
||||||
///**
|
* My class Furniture.
|
||||||
// * My class Furniture.
|
*/
|
||||||
// */
|
public class Furniture<T> {
|
||||||
//todo uncomment /*<Furniture>*/
|
|
||||||
public /*abstract*/ class Furniture/*<T>*/ implements Comparable<Furniture> {
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
@ -15,13 +13,14 @@ public /*abstract*/ class Furniture/*<T>*/ implements Comparable<Furniture> {
|
||||||
private int width;
|
private int width;
|
||||||
private int price;
|
private int price;
|
||||||
|
|
||||||
// private T additional;
|
private T additional;
|
||||||
|
|
||||||
// public void setAdditional(T additional) {
|
public void setAdditional(T additional) {
|
||||||
// this.additional = additional;
|
this.additional = additional;
|
||||||
// }
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
*
|
||||||
* @param material
|
* @param material
|
||||||
* @param length
|
* @param length
|
||||||
* @param height
|
* @param height
|
||||||
|
@ -75,19 +74,4 @@ public /*abstract*/ class Furniture/*<T>*/ implements Comparable<Furniture> {
|
||||||
", price=" + price +
|
", price=" + price +
|
||||||
'}';
|
'}';
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Override
|
|
||||||
// public int compareTo(Object o) {
|
|
||||||
// return /*this.*/price - ((Furniture) o).price;
|
|
||||||
//// return /*this.*/material.compareTo(((Furniture) o).material);
|
|
||||||
// }
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int compareTo(Furniture o) {
|
|
||||||
final int priceDifference = price - o.price;
|
|
||||||
return priceDifference != 0
|
|
||||||
? priceDifference
|
|
||||||
// : -material.compareTo(o.material);
|
|
||||||
: o.material.compareTo(material);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,19 +1,14 @@
|
||||||
package lab4;
|
package lab4;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Comparator;
|
|
||||||
|
|
||||||
public class Main {
|
public class Main {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
System.out.println(Integer.MIN_VALUE - 1);
|
// todo Comparable
|
||||||
//todo equals+hashcode
|
//todo equals+hashcode
|
||||||
// todo JavaDoc
|
// todo JavaDoc
|
||||||
final Furniture/*<Furniture>*/ furniture1 = new Furniture("A", 1, 1, 1, 1);
|
final Furniture<Furniture> furniture1 = new Furniture<>("A", 1, 1, 1, 1);
|
||||||
final Furniture/*<String>*/ furniture2 = new Furniture("F", 1, 1, 1, 4);
|
final Furniture<String> furniture2 = new Furniture<>("D", 1, 1, 1, 4);
|
||||||
|
|
||||||
System.out.println(furniture1.compareTo(furniture2));
|
|
||||||
// System.out.println(furniture1.compareTo("furniture2"));
|
|
||||||
|
|
||||||
Furniture[] furnitureArray = {
|
Furniture[] furnitureArray = {
|
||||||
furniture1,
|
furniture1,
|
||||||
furniture2,
|
furniture2,
|
||||||
|
@ -27,8 +22,8 @@ public class Main {
|
||||||
}
|
}
|
||||||
System.out.println("+++++++++++++");
|
System.out.println("+++++++++++++");
|
||||||
|
|
||||||
// furniture1.setAdditional(new Furniture("Y", 1, 1, 1, 0));
|
furniture1.setAdditional(new Furniture("Y", 1, 1, 1, 0));
|
||||||
// furniture2.setAdditional("new Furniture(\"Y\", 1, 1, 1, 0)");
|
furniture2.setAdditional("new Furniture(\"Y\", 1, 1, 1, 0)");
|
||||||
|
|
||||||
// furnitureArray[0].setMaterial("E");
|
// furnitureArray[0].setMaterial("E");
|
||||||
|
|
||||||
|
@ -46,39 +41,5 @@ public class Main {
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.println("+++++++++++++");
|
System.out.println("+++++++++++++");
|
||||||
|
|
||||||
/*Arrays.sort(furnitureArray);
|
|
||||||
for (Furniture furniture : furnitureArray) {
|
|
||||||
System.out.println(furniture);
|
|
||||||
}
|
|
||||||
|
|
||||||
System.out.println("+++++++++++++");*/
|
|
||||||
|
|
||||||
/*Arrays.sort(furnitureArray, new PriceFurnitureComparator());
|
|
||||||
for (Furniture furniture : furnitureArray) {
|
|
||||||
System.out.println(furniture);
|
|
||||||
}
|
|
||||||
|
|
||||||
System.out.println("+++++++++++++");*/
|
|
||||||
|
|
||||||
/*Arrays.sort(furnitureArray, new Comparator<Furniture>() {
|
|
||||||
@Override
|
|
||||||
public int compare(Furniture o1, Furniture o2) {
|
|
||||||
return o1.getMaterial().compareTo(o2.getMaterial());
|
|
||||||
}
|
|
||||||
});*/
|
|
||||||
// Arrays.sort(furnitureArray, (o1, o2) -> o1.getMaterial().compareTo(o2.getMaterial()));
|
|
||||||
// Arrays.sort(furnitureArray, Comparator.comparing(Furniture::getMaterial));
|
|
||||||
// Arrays.sort(furnitureArray, Comparator.comparing(Furniture::getMaterial).reversed());
|
|
||||||
// Arrays.sort(furnitureArray, Comparator.comparing(Furniture::getPrice)
|
|
||||||
// .thenComparing(Furniture::getMaterial).reversed());
|
|
||||||
Arrays.sort(furnitureArray, Comparator.comparing(Furniture::getPrice)
|
|
||||||
.thenComparing(Comparator.comparing(Furniture::getMaterial).reversed()));
|
|
||||||
|
|
||||||
for (Furniture furniture : furnitureArray) {
|
|
||||||
System.out.println(furniture);
|
|
||||||
}
|
|
||||||
|
|
||||||
System.out.println("+++++++++++++");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +0,0 @@
|
||||||
package lab4;
|
|
||||||
|
|
||||||
import java.util.Comparator;
|
|
||||||
|
|
||||||
public class MaterialFurnitureComparator implements Comparator<Furniture> {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int compare(Furniture o1, Furniture o2) {
|
|
||||||
return o1.getMaterial().compareTo(o2.getMaterial());
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,11 +0,0 @@
|
||||||
package lab4;
|
|
||||||
|
|
||||||
import java.util.Comparator;
|
|
||||||
|
|
||||||
public class PriceFurnitureComparator implements Comparator<Furniture> {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int compare(Furniture o1, Furniture o2) {
|
|
||||||
return o1.getPrice() - o2.getPrice();
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue