Commit 94a68ae6 by Patryk Czarnik

Formatowanie kodu IDEA

parent fd341077
package ogloszenia;
/** W tej klasie trzeba wpisać swoje ustawienia ścieżek. */
/**
* W tej klasie trzeba wpisać swoje ustawienia ścieżek.
*/
public class Ustawienia {
public static final String SQLITE_PATH = "/home/patryk/ogloszenia/ogloszenia.db";
public static final String PHOTOS_PATH = "/home/patryk/ogloszenia/foto";
public static final String SQLITE_PATH = "/home/patryk/ogloszenia/ogloszenia.db";
public static final String PHOTOS_PATH = "/home/patryk/ogloszenia/foto";
}
......@@ -10,69 +10,69 @@ import ogloszenia.baza.sqlite.SprzedawcaDAO;
import ogloszenia.exn.BladBazyDanych;
public class DostepDoBazySqlite implements AutoCloseable {
private Connection c;
DostepDoBazySqlite(Connection con) {
c = con;
}
public static DostepDoBazySqlite newSQLite(String sqliteFile) throws BladBazyDanych {
try {
Class.forName("org.sqlite.JDBC");
Connection con = DriverManager.getConnection("jdbc:sqlite:" + sqliteFile);
return new DostepDoBazySqlite(con);
} catch (Exception e) {
throw new BladBazyDanych("Błąd podczas otwierania bazy danych ("+e.getMessage()+")", e);
}
}
public static DostepDoBazySqlite newSQLite() throws BladBazyDanych {
return newSQLite(Ustawienia.SQLITE_PATH);
}
@Override
public void close() {
try {
if(c != null)
c.close();
} catch (SQLException e) {
System.err.println("Błąd podczas close: " + e.getMessage());
}
}
Connection c() {
return c;
}
public void beginTransaction() throws BladBazyDanych {
try {
c.setAutoCommit(false);
//c.setTransactionIsolation(Connection.TRANSACTION_REPEATABLE_READ);
} catch (SQLException e) {
throw new BladBazyDanych("beginTransaction: " + e.getMessage(), e);
}
}
private Connection c;
public void endTransaction(boolean commit) throws BladBazyDanych {
try {
if(commit) {
c.commit();
} else {
c.rollback();
}
c.setAutoCommit(true);
} catch (SQLException e) {
throw new BladBazyDanych("endTransaction: " + e.getMessage(), e);
}
}
DostepDoBazySqlite(Connection con) {
c = con;
}
public static DostepDoBazySqlite newSQLite(String sqliteFile) throws BladBazyDanych {
try {
Class.forName("org.sqlite.JDBC");
Connection con = DriverManager.getConnection("jdbc:sqlite:" + sqliteFile);
return new DostepDoBazySqlite(con);
} catch (Exception e) {
throw new BladBazyDanych("Błąd podczas otwierania bazy danych (" + e.getMessage() + ")", e);
}
}
public static DostepDoBazySqlite newSQLite() throws BladBazyDanych {
return newSQLite(Ustawienia.SQLITE_PATH);
}
@Override
public void close() {
try {
if (c != null)
c.close();
} catch (SQLException e) {
System.err.println("Błąd podczas close: " + e.getMessage());
}
}
Connection c() {
return c;
}
public void beginTransaction() throws BladBazyDanych {
try {
c.setAutoCommit(false);
//c.setTransactionIsolation(Connection.TRANSACTION_REPEATABLE_READ);
} catch (SQLException e) {
throw new BladBazyDanych("beginTransaction: " + e.getMessage(), e);
}
}
public void endTransaction(boolean commit) throws BladBazyDanych {
try {
if (commit) {
c.commit();
} else {
c.rollback();
}
c.setAutoCommit(true);
} catch (SQLException e) {
throw new BladBazyDanych("endTransaction: " + e.getMessage(), e);
}
}
public OgloszenieDAO newOgloszenieDAO() {
return new OgloszenieDAO(this);
}
public SprzedawcaDAO newSprzedawcaDAO() {
return new SprzedawcaDAO(this);
}
public OgloszenieDAO newOgloszenieDAO() {
return new OgloszenieDAO(this);
}
public SprzedawcaDAO newSprzedawcaDAO() {
return new SprzedawcaDAO(this);
}
}
......@@ -6,19 +6,19 @@ import ogloszenia.model.Paliwo;
public class Konwersje {
public static LocalDateTime dateFromString(String s) {
return s == null ? null : LocalDateTime.parse(s.replace(' ', 'T'));
}
public static LocalDateTime dateFromString(String s) {
return s == null ? null : LocalDateTime.parse(s.replace(' ', 'T'));
}
public static String dateToString(LocalDateTime localDateTime) {
return localDateTime == null ? null : localDateTime.toString().replace('T', ' ');
}
public static Paliwo paliwoFromString(String s) {
return s == null ? null : Paliwo.valueOf(s.trim().toUpperCase());
}
public static String dateToString(LocalDateTime localDateTime) {
return localDateTime == null ? null : localDateTime.toString().replace('T', ' ');
}
public static String paliwoToString(Paliwo paliwo) {
return paliwo == null ? null : paliwo.toString();
}
public static Paliwo paliwoFromString(String s) {
return s == null ? null : Paliwo.valueOf(s.trim().toUpperCase());
}
public static String paliwoToString(Paliwo paliwo) {
return paliwo == null ? null : paliwo.toString();
}
}
......@@ -12,69 +12,69 @@ import ogloszenia.model.Adres;
import ogloszenia.model.Sprzedawca;
public class SprzedawcaDAO {
private DostepDoBazySqlite db;
SprzedawcaDAO(DostepDoBazySqlite db) {
this.db = db;
}
public DostepDoBazySqlite getDBHandler() {
return db;
}
public List<Integer> idList() throws BladBazyDanych {
final String sql = "SELECT id_sprzedawcy FROM sprzedawcy";
List<Integer> lista = new LinkedList<>();
try(PreparedStatement stmt = db.c().prepareStatement(sql)) {
try(ResultSet rs = stmt.executeQuery()) {
while(rs.next()) {
lista.add(rs.getInt(1));
}
}
} catch (SQLException e) {
throw new BladBazyDanych("listaIdSprzedawcow: "+e.getMessage(), e);
}
return lista;
}
private DostepDoBazySqlite db;
public Sprzedawca findById(int idSprzedawcy) throws BladBazyDanych, NieznanyRekord {
final String sql = "SELECT * FROM sprzedawcy WHERE id_sprzedawcy = ?";
try(PreparedStatement stmt = db.c().prepareStatement(sql)) {
stmt.setInt(1, idSprzedawcy);
try(ResultSet rs = stmt.executeQuery()) {
if(rs.next()) {
return sprzedawcaZResultSet(rs);
} else {
throw new NieznanyRekord("Nieznany sprzedawca " + idSprzedawcy);
}
}
} catch (SQLException e) {
throw new BladBazyDanych("Sprzedawca byId: "+e.getMessage(), e);
}
}
SprzedawcaDAO(DostepDoBazySqlite db) {
this.db = db;
}
public List<Sprzedawca> readAll() throws BladBazyDanych {
final String sql = "SELECT * FROM sprzedawcy";
List<Sprzedawca> lista = new LinkedList<>();
try(PreparedStatement stmt = db.c().prepareStatement(sql)) {
try(ResultSet rs = stmt.executeQuery()) {
while(rs.next()) {
lista.add(sprzedawcaZResultSet(rs));
}
}
} catch (SQLException e) {
throw new BladBazyDanych("Sprzedawca readAll: "+e.getMessage(), e);
}
return lista;
}
private Sprzedawca sprzedawcaZResultSet(ResultSet rs) throws SQLException {
Adres adres = new Adres(rs.getString("ulica"),
rs.getString("kod_pocztowy"), rs.getString("miasto"));
return new Sprzedawca(
rs.getInt("id_sprzedawcy"), rs.getString("nazwa"),
adres, rs.getString("telefon"), rs.getString("email")
);
}
public DostepDoBazySqlite getDBHandler() {
return db;
}
public List<Integer> idList() throws BladBazyDanych {
final String sql = "SELECT id_sprzedawcy FROM sprzedawcy";
List<Integer> lista = new LinkedList<>();
try (PreparedStatement stmt = db.c().prepareStatement(sql)) {
try (ResultSet rs = stmt.executeQuery()) {
while (rs.next()) {
lista.add(rs.getInt(1));
}
}
} catch (SQLException e) {
throw new BladBazyDanych("listaIdSprzedawcow: " + e.getMessage(), e);
}
return lista;
}
public Sprzedawca findById(int idSprzedawcy) throws BladBazyDanych, NieznanyRekord {
final String sql = "SELECT * FROM sprzedawcy WHERE id_sprzedawcy = ?";
try (PreparedStatement stmt = db.c().prepareStatement(sql)) {
stmt.setInt(1, idSprzedawcy);
try (ResultSet rs = stmt.executeQuery()) {
if (rs.next()) {
return sprzedawcaZResultSet(rs);
} else {
throw new NieznanyRekord("Nieznany sprzedawca " + idSprzedawcy);
}
}
} catch (SQLException e) {
throw new BladBazyDanych("Sprzedawca byId: " + e.getMessage(), e);
}
}
public List<Sprzedawca> readAll() throws BladBazyDanych {
final String sql = "SELECT * FROM sprzedawcy";
List<Sprzedawca> lista = new LinkedList<>();
try (PreparedStatement stmt = db.c().prepareStatement(sql)) {
try (ResultSet rs = stmt.executeQuery()) {
while (rs.next()) {
lista.add(sprzedawcaZResultSet(rs));
}
}
} catch (SQLException e) {
throw new BladBazyDanych("Sprzedawca readAll: " + e.getMessage(), e);
}
return lista;
}
private Sprzedawca sprzedawcaZResultSet(ResultSet rs) throws SQLException {
Adres adres = new Adres(rs.getString("ulica"),
rs.getString("kod_pocztowy"), rs.getString("miasto"));
return new Sprzedawca(
rs.getInt("id_sprzedawcy"), rs.getString("nazwa"),
adres, rs.getString("telefon"), rs.getString("email")
);
}
}
......@@ -12,35 +12,35 @@ import ogloszenia.Ustawienia;
public class UtworzBaze {
public static void main(String[] args) {
String skrypt = "";
try {
skrypt = String.join("\n", Files.readAllLines(Paths.get("ogloszenia_sqlite.sql")));
if(Files.deleteIfExists(Paths.get(Ustawienia.SQLITE_PATH))) {
System.out.println("Usunięto plik " + Ustawienia.SQLITE_PATH);
}
} catch (IOException e) {
System.err.println("Błąd podczas przygotowania plików: " + e);
}
String[] poleceniaSkryptu = skrypt.split("\\s*;\\s*");
System.out.println("Otwarcie pliku z bazą...");
try(Connection c = DriverManager.getConnection("jdbc:sqlite:" + Ustawienia.SQLITE_PATH);
Statement stmt = c.createStatement()) {
c.setAutoCommit(false);
System.out.println("Wgrywam dane");
for(String sql : poleceniaSkryptu) {
stmt.addBatch(sql);
System.out.print(".");
System.out.flush();
}
stmt.executeBatch();
c.commit();
System.out.println("\nGotowe");
} catch (SQLException e) {
System.err.println("Błąd podczas wgrywania danych: " + e);
e.printStackTrace();
}
}
public static void main(String[] args) {
String skrypt = "";
try {
skrypt = String.join("\n", Files.readAllLines(Paths.get("ogloszenia_sqlite.sql")));
if (Files.deleteIfExists(Paths.get(Ustawienia.SQLITE_PATH))) {
System.out.println("Usunięto plik " + Ustawienia.SQLITE_PATH);
}
} catch (IOException e) {
System.err.println("Błąd podczas przygotowania plików: " + e);
}
String[] poleceniaSkryptu = skrypt.split("\\s*;\\s*");
System.out.println("Otwarcie pliku z bazą...");
try (Connection c = DriverManager.getConnection("jdbc:sqlite:" + Ustawienia.SQLITE_PATH);
Statement stmt = c.createStatement()) {
c.setAutoCommit(false);
System.out.println("Wgrywam dane");
for (String sql : poleceniaSkryptu) {
stmt.addBatch(sql);
System.out.print(".");
System.out.flush();
}
stmt.executeBatch();
c.commit();
System.out.println("\nGotowe");
} catch (SQLException e) {
System.err.println("Błąd podczas wgrywania danych: " + e);
e.printStackTrace();
}
}
}
......@@ -2,19 +2,19 @@ package ogloszenia.exn;
public class BladAplikacji extends Exception {
public BladAplikacji() {
super();
}
public BladAplikacji() {
super();
}
public BladAplikacji(String message, Throwable cause) {
super(message, cause);
}
public BladAplikacji(String message, Throwable cause) {
super(message, cause);
}
public BladAplikacji(String message) {
super(message);
}
public BladAplikacji(String message) {
super(message);
}
public BladAplikacji(Throwable cause) {
super(cause);
}
public BladAplikacji(Throwable cause) {
super(cause);
}
}
......@@ -2,20 +2,20 @@ package ogloszenia.exn;
public class BladBazyDanych extends BladAplikacji {
public BladBazyDanych() {
super();
}
public BladBazyDanych() {
super();
}
public BladBazyDanych(String message, Throwable cause) {
super(message, cause);
}
public BladBazyDanych(String message, Throwable cause) {
super(message, cause);
}
public BladBazyDanych(String message) {
super(message);
}
public BladBazyDanych(String message) {
super(message);
}
public BladBazyDanych(Throwable cause) {
super(cause);
}
public BladBazyDanych(Throwable cause) {
super(cause);
}
}
......@@ -2,12 +2,12 @@ package ogloszenia.exn;
public class NieznanyRekord extends BladAplikacji {
public NieznanyRekord() {
super();
}
public NieznanyRekord() {
super();
}
public NieznanyRekord(String message) {
super(message);
}
public NieznanyRekord(String message) {
super(message);
}
}
package ogloszenia.model;
public class Adres {
private String ulica;
private String kodPocztowy;
private String miasto;
private String ulica;
private String kodPocztowy;
private String miasto;
public Adres() {
}
public Adres() {
}
public Adres(String ulica, String kodPocztowy, String miasto) {
this.ulica = ulica;
this.kodPocztowy = kodPocztowy;
this.miasto = miasto;
}
public Adres(String ulica, String kodPocztowy, String miasto) {
this.ulica = ulica;
this.kodPocztowy = kodPocztowy;
this.miasto = miasto;
}
public String getUlica() {
return ulica;
}
public String getUlica() {
return ulica;
}
public String getKodPocztowy() {
return kodPocztowy;
}
public String getKodPocztowy() {
return kodPocztowy;
}
public String getMiasto() {
return miasto;
}
public String getMiasto() {
return miasto;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((kodPocztowy == null) ? 0 : kodPocztowy.hashCode());
result = prime * result + ((miasto == null) ? 0 : miasto.hashCode());
result = prime * result + ((ulica == null) ? 0 : ulica.hashCode());
return result;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((kodPocztowy == null) ? 0 : kodPocztowy.hashCode());
result = prime * result + ((miasto == null) ? 0 : miasto.hashCode());
result = prime * result + ((ulica == null) ? 0 : ulica.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Adres other = (Adres) obj;
if (kodPocztowy == null) {
if (other.kodPocztowy != null)
return false;
} else if (!kodPocztowy.equals(other.kodPocztowy))
return false;
if (miasto == null) {
if (other.miasto != null)
return false;
} else if (!miasto.equals(other.miasto))
return false;
if (ulica == null) {
if (other.ulica != null)
return false;
} else if (!ulica.equals(other.ulica))
return false;
return true;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Adres other = (Adres) obj;
if (kodPocztowy == null) {
if (other.kodPocztowy != null)
return false;
} else if (!kodPocztowy.equals(other.kodPocztowy))
return false;
if (miasto == null) {
if (other.miasto != null)
return false;
} else if (!miasto.equals(other.miasto))
return false;
if (ulica == null) {
if (other.ulica != null)
return false;
} else if (!ulica.equals(other.ulica))
return false;
return true;
}
@Override
public String toString() {
return String.format("%s, %s %s", ulica, kodPocztowy, miasto);
}
@Override
public String toString() {
return String.format("%s, %s %s", ulica, kodPocztowy, miasto);
}
}
......@@ -3,11 +3,11 @@ package ogloszenia.model;
import java.util.List;
public class ListaOgloszen {
public List<OgloszenieSamochodowe> ogloszenia;
public List<OgloszenieSamochodowe> ogloszenia;
public static ListaOgloszen nowa(List<OgloszenieSamochodowe> ogloszenia) {
ListaOgloszen lista = new ListaOgloszen();
lista.ogloszenia = ogloszenia;
return lista;
}
public static ListaOgloszen nowa(List<OgloszenieSamochodowe> ogloszenia) {
ListaOgloszen lista = new ListaOgloszen();
lista.ogloszenia = ogloszenia;
return lista;
}
}
......@@ -4,156 +4,160 @@ import java.math.BigDecimal;
import java.time.LocalDateTime;
public class Ogloszenie {
private Integer idOgloszenia;
private Integer idSprzedawcy;
private LocalDateTime dataWystawienia;
private BigDecimal cena;
private String tytul;
private String opis;
private Sprzedawca sprzedawca;
public Ogloszenie() {
}
public Ogloszenie(Integer idOgloszenia, Integer idSprzedawcy, LocalDateTime dataWystawienia, BigDecimal cena, String tytul, String opis) {
this.idOgloszenia = idOgloszenia;
this.idSprzedawcy = idSprzedawcy;
this.dataWystawienia = dataWystawienia;
this.cena = cena;
this.tytul = tytul;
this.opis = opis;
}
/** Pozostawia pole sprzedawca równe null. */
public Ogloszenie(Integer idOgloszenia, LocalDateTime dataWystawienia, BigDecimal cena, String tytul, String opis) {
this.idOgloszenia = idOgloszenia;
this.dataWystawienia = dataWystawienia;
this.cena = cena;
this.tytul = tytul;
this.opis = opis;
this.idSprzedawcy = null;
}
/** Wartość idSprzedawcy pobiera z obiektu sprzedawca. */
public Ogloszenie(Integer idOgloszenia, Sprzedawca sprzedawca, LocalDateTime dataWystawienia, BigDecimal cena, String tytul, String opis) {
this.idOgloszenia = idOgloszenia;
this.dataWystawienia = dataWystawienia;
this.cena = cena;
this.tytul = tytul;
this.opis = opis;
this.sprzedawca = sprzedawca;
if(sprzedawca != null) {
this.idSprzedawcy = sprzedawca.getIdSprzedawcy();
}
}
public Integer getIdOgloszenia() {
return idOgloszenia;
}
public void setIdOgloszenia(Integer noweId) {
this.idOgloszenia = noweId;
}
public String getTytul() {
return tytul;
}
public BigDecimal getCena() {
return cena;
}
public Integer getIdSprzedawcy() {
return idSprzedawcy;
}
public Sprzedawca getSprzedawca() {
return sprzedawca;
}
public void setSprzedawca(Sprzedawca sprzedawca) {
this.sprzedawca = sprzedawca;
}
public String getOpis() {
return opis;
}
public void setOpis(String opis) {
this.opis = opis;
}
public void setCena(BigDecimal cena) {
this.cena = cena;
}
public LocalDateTime getDataWystawienia() {
return dataWystawienia;
}
public void setDataWystawienia(LocalDateTime dataWystawienia) {
this.dataWystawienia = dataWystawienia;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((cena == null) ? 0 : cena.hashCode());
result = prime * result + ((dataWystawienia == null) ? 0 : dataWystawienia.hashCode());
result = prime * result + ((idOgloszenia == null) ? 0 : idOgloszenia.hashCode());
result = prime * result + ((idSprzedawcy == null) ? 0 : idSprzedawcy.hashCode());
result = prime * result + ((opis == null) ? 0 : opis.hashCode());
result = prime * result + ((sprzedawca == null) ? 0 : sprzedawca.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Ogloszenie other = (Ogloszenie) obj;
if (cena == null) {
if (other.cena != null)
return false;
} else if (!cena.equals(other.cena))
return false;
if (dataWystawienia == null) {
if (other.dataWystawienia != null)
return false;
} else if (!dataWystawienia.equals(other.dataWystawienia))
return false;
if (idOgloszenia == null) {
if (other.idOgloszenia != null)
return false;
} else if (!idOgloszenia.equals(other.idOgloszenia))
return false;
if (idSprzedawcy == null) {
if (other.idSprzedawcy != null)
return false;
} else if (!idSprzedawcy.equals(other.idSprzedawcy))
return false;
if (opis == null) {
if (other.opis != null)
return false;
} else if (!opis.equals(other.opis))
return false;
if (sprzedawca == null) {
if (other.sprzedawca != null)
return false;
} else if (!sprzedawca.equals(other.sprzedawca))
return false;
return true;
}
@Override
public String toString() {
return String.format("Ogłoszenie #%d: sprzedawca #%s, cena: %.2f\n %s",
idOgloszenia, idSprzedawcy, cena, tytul);
}
private Integer idOgloszenia;
private Integer idSprzedawcy;
private LocalDateTime dataWystawienia;
private BigDecimal cena;
private String tytul;
private String opis;
private Sprzedawca sprzedawca;
public Ogloszenie() {
}
public Ogloszenie(Integer idOgloszenia, Integer idSprzedawcy, LocalDateTime dataWystawienia, BigDecimal cena, String tytul, String opis) {
this.idOgloszenia = idOgloszenia;
this.idSprzedawcy = idSprzedawcy;
this.dataWystawienia = dataWystawienia;
this.cena = cena;
this.tytul = tytul;
this.opis = opis;
}
/**
* Pozostawia pole sprzedawca równe null.
*/
public Ogloszenie(Integer idOgloszenia, LocalDateTime dataWystawienia, BigDecimal cena, String tytul, String opis) {
this.idOgloszenia = idOgloszenia;
this.dataWystawienia = dataWystawienia;
this.cena = cena;
this.tytul = tytul;
this.opis = opis;
this.idSprzedawcy = null;
}
/**
* Wartość idSprzedawcy pobiera z obiektu sprzedawca.
*/
public Ogloszenie(Integer idOgloszenia, Sprzedawca sprzedawca, LocalDateTime dataWystawienia, BigDecimal cena, String tytul, String opis) {
this.idOgloszenia = idOgloszenia;
this.dataWystawienia = dataWystawienia;
this.cena = cena;
this.tytul = tytul;
this.opis = opis;
this.sprzedawca = sprzedawca;
if (sprzedawca != null) {
this.idSprzedawcy = sprzedawca.getIdSprzedawcy();
}
}
public Integer getIdOgloszenia() {
return idOgloszenia;
}
public void setIdOgloszenia(Integer noweId) {
this.idOgloszenia = noweId;
}
public String getTytul() {
return tytul;
}
public BigDecimal getCena() {
return cena;
}
public Integer getIdSprzedawcy() {
return idSprzedawcy;
}
public Sprzedawca getSprzedawca() {
return sprzedawca;
}
public void setSprzedawca(Sprzedawca sprzedawca) {
this.sprzedawca = sprzedawca;
}
public String getOpis() {
return opis;
}
public void setOpis(String opis) {
this.opis = opis;
}
public void setCena(BigDecimal cena) {
this.cena = cena;
}
public LocalDateTime getDataWystawienia() {
return dataWystawienia;
}
public void setDataWystawienia(LocalDateTime dataWystawienia) {
this.dataWystawienia = dataWystawienia;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((cena == null) ? 0 : cena.hashCode());
result = prime * result + ((dataWystawienia == null) ? 0 : dataWystawienia.hashCode());
result = prime * result + ((idOgloszenia == null) ? 0 : idOgloszenia.hashCode());
result = prime * result + ((idSprzedawcy == null) ? 0 : idSprzedawcy.hashCode());
result = prime * result + ((opis == null) ? 0 : opis.hashCode());
result = prime * result + ((sprzedawca == null) ? 0 : sprzedawca.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Ogloszenie other = (Ogloszenie) obj;
if (cena == null) {
if (other.cena != null)
return false;
} else if (!cena.equals(other.cena))
return false;
if (dataWystawienia == null) {
if (other.dataWystawienia != null)
return false;
} else if (!dataWystawienia.equals(other.dataWystawienia))
return false;
if (idOgloszenia == null) {
if (other.idOgloszenia != null)
return false;
} else if (!idOgloszenia.equals(other.idOgloszenia))
return false;
if (idSprzedawcy == null) {
if (other.idSprzedawcy != null)
return false;
} else if (!idSprzedawcy.equals(other.idSprzedawcy))
return false;
if (opis == null) {
if (other.opis != null)
return false;
} else if (!opis.equals(other.opis))
return false;
if (sprzedawca == null) {
if (other.sprzedawca != null)
return false;
} else if (!sprzedawca.equals(other.sprzedawca))
return false;
return true;
}
@Override
public String toString() {
return String.format("Ogłoszenie #%d: sprzedawca #%s, cena: %.2f\n %s",
idOgloszenia, idSprzedawcy, cena, tytul);
}
}
......@@ -4,146 +4,150 @@ import java.math.BigDecimal;
import java.time.LocalDateTime;
public class OgloszenieSamochodowe extends Ogloszenie {
private String marka;
private String model;
private String generacja;
public int rocznik;
private int przebieg;
private String kolor;
private Silnik silnik;
public OgloszenieSamochodowe() {
}
public OgloszenieSamochodowe(Integer idOgloszenia, Integer idSprzedawcy,
LocalDateTime dataWystawienia, BigDecimal cena, String tytul, String opis,
String marka, String model, String generacja, String kolor, int rocznik, int przebieg, Silnik silnik) {
super(idOgloszenia, idSprzedawcy, dataWystawienia, cena, tytul, opis);
this.marka = marka;
this.model = model;
this.generacja = generacja;
this.kolor = kolor;
this.rocznik = rocznik;
this.przebieg = przebieg;
this.silnik = silnik;
}
/** Pozostawia pole sprzedawca równe null. */
public OgloszenieSamochodowe(Integer idOgloszenia, LocalDateTime dataWystawienia, BigDecimal cena, String tytul, String opis,
String marka, String model, String generacja, String kolor, int rocznik, int przebieg, Silnik silnik) {
super(idOgloszenia, dataWystawienia, cena, tytul, opis);
this.marka = marka;
this.model = model;
this.generacja = generacja;
this.kolor = kolor;
this.rocznik = rocznik;
this.przebieg = przebieg;
this.silnik = silnik;
}
/** Wartość idSprzedawcy pobiera z obiektu sprzedawca. */
public OgloszenieSamochodowe(Integer idOgloszenia, Sprzedawca sprzedawca,
LocalDateTime dataWystawienia, BigDecimal cena, String tytul, String opis,
String marka, String model, String generacja, String kolor, int rocznik, int przebieg, Silnik silnik) {
super(idOgloszenia, sprzedawca, dataWystawienia, cena, tytul, opis);
this.marka = marka;
this.model = model;
this.generacja = generacja;
this.kolor = kolor;
this.rocznik = rocznik;
this.przebieg = przebieg;
this.silnik = silnik;
}
public String getMarka() {
return marka.toUpperCase();
}
public void setMarka(String marka) {
this.marka = marka;
}
public String getModel() {
return model;
}
public String getGeneracja() {
return generacja;
}
public String getKolor() {
return kolor;
}
public int getRocznik() {
return rocznik;
}
public int getPrzebieg() {
return przebieg;
}
public Silnik getSilnik() {
return silnik;
}
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + ((generacja == null) ? 0 : generacja.hashCode());
result = prime * result + ((kolor == null) ? 0 : kolor.hashCode());
result = prime * result + ((marka == null) ? 0 : marka.hashCode());
result = prime * result + ((model == null) ? 0 : model.hashCode());
result = prime * result + rocznik;
result = prime * result + ((silnik == null) ? 0 : silnik.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (!super.equals(obj))
return false;
if (getClass() != obj.getClass())
return false;
OgloszenieSamochodowe other = (OgloszenieSamochodowe) obj;
if (generacja == null) {
if (other.generacja != null)
return false;
} else if (!generacja.equals(other.generacja))
return false;
if (kolor == null) {
if (other.kolor != null)
return false;
} else if (!kolor.equals(other.kolor))
return false;
if (marka == null) {
if (other.marka != null)
return false;
} else if (!marka.equals(other.marka))
return false;
if (model == null) {
if (other.model != null)
return false;
} else if (!model.equals(other.model))
return false;
if (rocznik != other.rocznik)
return false;
if (silnik == null) {
if (other.silnik != null)
return false;
} else if (!silnik.equals(other.silnik))
return false;
return true;
}
@Override
public String toString() {
return super.toString() + "\n" +
String.format(" Samochód: %s %s %s (%s), rok %d, silnik: %s",
marka, model, generacja, kolor, rocznik, silnik);
}
private String marka;
private String model;
private String generacja;
public int rocznik;
private int przebieg;
private String kolor;
private Silnik silnik;
public OgloszenieSamochodowe() {
}
public OgloszenieSamochodowe(Integer idOgloszenia, Integer idSprzedawcy,
LocalDateTime dataWystawienia, BigDecimal cena, String tytul, String opis,
String marka, String model, String generacja, String kolor, int rocznik, int przebieg, Silnik silnik) {
super(idOgloszenia, idSprzedawcy, dataWystawienia, cena, tytul, opis);
this.marka = marka;
this.model = model;
this.generacja = generacja;
this.kolor = kolor;
this.rocznik = rocznik;
this.przebieg = przebieg;
this.silnik = silnik;
}
/**
* Pozostawia pole sprzedawca równe null.
*/
public OgloszenieSamochodowe(Integer idOgloszenia, LocalDateTime dataWystawienia, BigDecimal cena, String tytul, String opis,
String marka, String model, String generacja, String kolor, int rocznik, int przebieg, Silnik silnik) {
super(idOgloszenia, dataWystawienia, cena, tytul, opis);
this.marka = marka;
this.model = model;
this.generacja = generacja;
this.kolor = kolor;
this.rocznik = rocznik;
this.przebieg = przebieg;
this.silnik = silnik;
}
/**
* Wartość idSprzedawcy pobiera z obiektu sprzedawca.
*/
public OgloszenieSamochodowe(Integer idOgloszenia, Sprzedawca sprzedawca,
LocalDateTime dataWystawienia, BigDecimal cena, String tytul, String opis,
String marka, String model, String generacja, String kolor, int rocznik, int przebieg, Silnik silnik) {
super(idOgloszenia, sprzedawca, dataWystawienia, cena, tytul, opis);
this.marka = marka;
this.model = model;
this.generacja = generacja;
this.kolor = kolor;
this.rocznik = rocznik;
this.przebieg = przebieg;
this.silnik = silnik;
}
public String getMarka() {
return marka.toUpperCase();
}
public void setMarka(String marka) {
this.marka = marka;
}
public String getModel() {
return model;
}
public String getGeneracja() {
return generacja;
}
public String getKolor() {
return kolor;
}
public int getRocznik() {
return rocznik;
}
public int getPrzebieg() {
return przebieg;
}
public Silnik getSilnik() {
return silnik;
}
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + ((generacja == null) ? 0 : generacja.hashCode());
result = prime * result + ((kolor == null) ? 0 : kolor.hashCode());
result = prime * result + ((marka == null) ? 0 : marka.hashCode());
result = prime * result + ((model == null) ? 0 : model.hashCode());
result = prime * result + rocznik;
result = prime * result + ((silnik == null) ? 0 : silnik.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (!super.equals(obj))
return false;
if (getClass() != obj.getClass())
return false;
OgloszenieSamochodowe other = (OgloszenieSamochodowe) obj;
if (generacja == null) {
if (other.generacja != null)
return false;
} else if (!generacja.equals(other.generacja))
return false;
if (kolor == null) {
if (other.kolor != null)
return false;
} else if (!kolor.equals(other.kolor))
return false;
if (marka == null) {
if (other.marka != null)
return false;
} else if (!marka.equals(other.marka))
return false;
if (model == null) {
if (other.model != null)
return false;
} else if (!model.equals(other.model))
return false;
if (rocznik != other.rocznik)
return false;
if (silnik == null) {
if (other.silnik != null)
return false;
} else if (!silnik.equals(other.silnik))
return false;
return true;
}
@Override
public String toString() {
return super.toString() + "\n" +
String.format(" Samochód: %s %s %s (%s), rok %d, silnik: %s",
marka, model, generacja, kolor, rocznik, silnik);
}
}
package ogloszenia.model;
public enum Paliwo {
BENZYNA,
OLEJ,
GAZ,
HYBRYDA,
ELEKTRYCZNY;
BENZYNA,
OLEJ,
GAZ,
HYBRYDA,
ELEKTRYCZNY;
}
package ogloszenia.model;
public class Silnik {
private Float moc;
private Float pojemnosc;
private Paliwo paliwo;
public Silnik() {
}
private Float moc;
private Float pojemnosc;
private Paliwo paliwo;
public Silnik(Float moc, Float pojemnosc, Paliwo paliwo) {
this.moc = moc;
this.pojemnosc = pojemnosc;
this.paliwo = paliwo;
}
public Silnik() {
}
public Float getMoc() {
return moc;
}
public Silnik(Float moc, Float pojemnosc, Paliwo paliwo) {
this.moc = moc;
this.pojemnosc = pojemnosc;
this.paliwo = paliwo;
}
public Float getPojemnosc() {
return pojemnosc;
}
public Float getMoc() {
return moc;
}
public Paliwo getPaliwo() {
return paliwo;
}
public Float getPojemnosc() {
return pojemnosc;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((moc == null) ? 0 : moc.hashCode());
result = prime * result + ((paliwo == null) ? 0 : paliwo.hashCode());
result = prime * result + ((pojemnosc == null) ? 0 : pojemnosc.hashCode());
return result;
}
public Paliwo getPaliwo() {
return paliwo;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Silnik other = (Silnik) obj;
if (moc == null) {
if (other.moc != null)
return false;
} else if (!moc.equals(other.moc))
return false;
if (paliwo != other.paliwo)
return false;
if (pojemnosc == null) {
if (other.pojemnosc != null)
return false;
} else if (!pojemnosc.equals(other.pojemnosc))
return false;
return true;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((moc == null) ? 0 : moc.hashCode());
result = prime * result + ((paliwo == null) ? 0 : paliwo.hashCode());
result = prime * result + ((pojemnosc == null) ? 0 : pojemnosc.hashCode());
return result;
}
@Override
public String toString() {
return String.format("%.1f %s, %.0f KM", pojemnosc, paliwo, moc);
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Silnik other = (Silnik) obj;
if (moc == null) {
if (other.moc != null)
return false;
} else if (!moc.equals(other.moc))
return false;
if (paliwo != other.paliwo)
return false;
if (pojemnosc == null) {
if (other.pojemnosc != null)
return false;
} else if (!pojemnosc.equals(other.pojemnosc))
return false;
return true;
}
@Override
public String toString() {
return String.format("%.1f %s, %.0f KM", pojemnosc, paliwo, moc);
}
}
package ogloszenia.model;
public class Sprzedawca {
private Integer idSprzedawcy;
private String nazwa;
private Adres adres;
private String telefon;
private String email;
public Sprzedawca() {
}
private Integer idSprzedawcy;
private String nazwa;
private Adres adres;
private String telefon;
private String email;
public Sprzedawca(Integer idSprzedawcy, String nazwa, Adres adres, String telefon, String email) {
this.idSprzedawcy = idSprzedawcy;
this.nazwa = nazwa;
this.adres = adres;
this.telefon = telefon;
this.email = email;
}
public Sprzedawca() {
}
public Integer getIdSprzedawcy() {
return idSprzedawcy;
}
public Sprzedawca(Integer idSprzedawcy, String nazwa, Adres adres, String telefon, String email) {
this.idSprzedawcy = idSprzedawcy;
this.nazwa = nazwa;
this.adres = adres;
this.telefon = telefon;
this.email = email;
}
public String getNazwa() {
return nazwa;
}
public Integer getIdSprzedawcy() {
return idSprzedawcy;
}
public Adres getAdres() {
return adres;
}
public String getNazwa() {
return nazwa;
}
public String getTelefon() {
return telefon;
}
public Adres getAdres() {
return adres;
}
public String getEmail() {
return email;
}
public String getTelefon() {
return telefon;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((adres == null) ? 0 : adres.hashCode());
result = prime * result + ((email == null) ? 0 : email.hashCode());
result = prime * result + ((idSprzedawcy == null) ? 0 : idSprzedawcy.hashCode());
result = prime * result + ((nazwa == null) ? 0 : nazwa.hashCode());
result = prime * result + ((telefon == null) ? 0 : telefon.hashCode());
return result;
}
public String getEmail() {
return email;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Sprzedawca other = (Sprzedawca) obj;
if (adres == null) {
if (other.adres != null)
return false;
} else if (!adres.equals(other.adres))
return false;
if (email == null) {
if (other.email != null)
return false;
} else if (!email.equals(other.email))
return false;
if (idSprzedawcy == null) {
if (other.idSprzedawcy != null)
return false;
} else if (!idSprzedawcy.equals(other.idSprzedawcy))
return false;
if (nazwa == null) {
if (other.nazwa != null)
return false;
} else if (!nazwa.equals(other.nazwa))
return false;
if (telefon == null) {
if (other.telefon != null)
return false;
} else if (!telefon.equals(other.telefon))
return false;
return true;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((adres == null) ? 0 : adres.hashCode());
result = prime * result + ((email == null) ? 0 : email.hashCode());
result = prime * result + ((idSprzedawcy == null) ? 0 : idSprzedawcy.hashCode());
result = prime * result + ((nazwa == null) ? 0 : nazwa.hashCode());
result = prime * result + ((telefon == null) ? 0 : telefon.hashCode());
return result;
}
@Override
public String toString() {
return String.format("Sprzedawca #%d: %s adres: %s, tel.: %s, email: %s",
idSprzedawcy, nazwa, adres, telefon, email);
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Sprzedawca other = (Sprzedawca) obj;
if (adres == null) {
if (other.adres != null)
return false;
} else if (!adres.equals(other.adres))
return false;
if (email == null) {
if (other.email != null)
return false;
} else if (!email.equals(other.email))
return false;
if (idSprzedawcy == null) {
if (other.idSprzedawcy != null)
return false;
} else if (!idSprzedawcy.equals(other.idSprzedawcy))
return false;
if (nazwa == null) {
if (other.nazwa != null)
return false;
} else if (!nazwa.equals(other.nazwa))
return false;
if (telefon == null) {
if (other.telefon != null)
return false;
} else if (!telefon.equals(other.telefon))
return false;
return true;
}
@Override
public String toString() {
return String.format("Sprzedawca #%d: %s adres: %s, tel.: %s, email: %s",
idSprzedawcy, nazwa, adres, telefon, email);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment