package pracaDomowa3;
import java.util.Objects;
public class Book implements Comparable
<Book
> {
private int pages;
this.title = title;
this.author = author;
this.pages = pages;
}
@Override
public int hashCode() {
int hash = 7;
hash = 31 * hash + Objects.hashCode(this.title);
hash = 31 * hash + Objects.hashCode(this.author);
hash = 31 * hash + this.pages;
return hash;
}
@Override
public boolean equals
(Object obj
) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
if (this.pages != other.pages) {
return false;
}
if (!Objects.equals(this.title, other.title)) {
return false;
}
if (!Objects.equals(this.author, other.author)) {
return false;
}
return true;
}
@Override
return "Book{" + "title=" + title + ", author=" + author + ", pages=" + pages + '}';
}
@Override
public int compareTo
(Book o
){
int compareTitle = title.compareTo(o.title);
if (compareTitle == 0){
return author.compareTo(o.author);
}
else{
return compareTitle;
}
}
}
------------------------------------------------------------------------------------
package pracaDomowa3;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class Start {
public static void main
(String[] args
) {
List<Book> books = new ArrayList<>();
books.
add(new Book("Podstawy języka Java",
"A",
100));
books.
add(new Book("Java dla opornych",
"B",
100));
books.
add(new Book("Podstawy języka Java",
"C",
150));
books.
add(new Book("C# dla początkujących",
"B",
200));
books.
add(new Book("W pustyni i w puszczy",
"Henryk Sienkiewicz",
350));
}
System.
out.
println("\nPosortowane: ");
}
CompareBook.compare(books);
}
}
}
---------------------------------------------------------------------------------------
package pracaDomowa3;
import java.util.Comparator;
import java.util.List;
public class CompareBook implements Comparator<Book> {
@Override
int a = pages(o2) - pages(o1);
if (a == 0){
author(o1) - author(o2);
}
else{
return a;
}
}
}
{"html5":"htmlmixed","css":"css","javascript":"javascript","php":"php","python":"python","ruby":"ruby","lua":"text\/x-lua","bash":"text\/x-sh","go":"go","c":"text\/x-csrc","cpp":"text\/x-c++src","diff":"diff","latex":"stex","sql":"sql","xml":"xml","apl":"apl","asterisk":"asterisk","c_loadrunner":"text\/x-csrc","c_mac":"text\/x-csrc","coffeescript":"text\/x-coffeescript","csharp":"text\/x-csharp","d":"d","ecmascript":"javascript","erlang":"erlang","groovy":"text\/x-groovy","haskell":"text\/x-haskell","haxe":"text\/x-haxe","html4strict":"htmlmixed","java":"text\/x-java","java5":"text\/x-java","jquery":"javascript","mirc":"mirc","mysql":"sql","ocaml":"text\/x-ocaml","pascal":"text\/x-pascal","perl":"perl","perl6":"perl","plsql":"sql","properties":"text\/x-properties","q":"text\/x-q","scala":"scala","scheme":"text\/x-scheme","tcl":"text\/x-tcl","vb":"text\/x-vb","verilog":"text\/x-verilog","yaml":"text\/x-yaml","z80":"text\/x-z80"}