Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue#19 car entity #26

Merged
merged 5 commits into from
Sep 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
139 changes: 139 additions & 0 deletions src/main/java/dto/CarDTO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
package dto;

import entities.Car;
import java.util.Objects;

public class CarDTO
{

private Long ID;
private int Year;
private String Make;
private String Model;
private double Price;

public CarDTO()
{
}

public CarDTO(Long ID, int Year, String Make, String Model, double Price)
{
this.ID = ID;
this.Year = Year;
this.Make = Make;
this.Model = Model;
this.Price = Price;
}

public CarDTO(Car car)
{
this.ID = car.getId();
this.Year = Year;
this.Make = Make;
this.Model = Model;
this.Price = Price;
}

public Long getID()
{
return ID;
}

public void setID(Long ID)
{
this.ID = ID;
}

public int getYear()
{
return Year;
}

public void setYear(int Year)
{
this.Year = Year;
}

public String getMake()
{
return Make;
}

public void setMake(String Make)
{
this.Make = Make;
}

public String getModel()
{
return Model;
}

public void setModel(String Model)
{
this.Model = Model;
}

public double getPrice()
{
return Price;
}

public void setPrice(double Price)
{
this.Price = Price;
}

@Override
public int hashCode()
{
int hash = 7;
hash = 97 * hash + Objects.hashCode(this.ID);
hash = 97 * hash + this.Year;
hash = 97 * hash + Objects.hashCode(this.Make);
hash = 97 * hash + Objects.hashCode(this.Model);
hash = 97 * hash + (int) (Double.doubleToLongBits(this.Price) ^ (Double.doubleToLongBits(this.Price) >>> 32));
return hash;
}

@Override
public boolean equals(Object obj)
{
if (this == obj)
{
return true;
}
if (obj == null)
{
return false;
}
if (getClass() != obj.getClass())
{
return false;
}
final CarDTO other = (CarDTO) obj;
if (this.Year != other.Year)
{
return false;
}
if (Double.doubleToLongBits(this.Price) != Double.doubleToLongBits(other.Price))
{
return false;
}
if (!Objects.equals(this.Make, other.Make))
{
return false;
}
if (!Objects.equals(this.Model, other.Model))
{
return false;
}
if (!Objects.equals(this.ID, other.ID))
{
return false;
}
return true;
}


}
158 changes: 158 additions & 0 deletions src/main/java/entities/Car.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
package entities;

import java.io.Serializable;
import java.util.Objects;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQuery;


@Entity
@NamedQuery(name = "Car.deleteAllRows", query = "DELETE from Car")
public class Car implements Serializable {

private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private int car_year;
private String car_make;
private String car_model;
private double car_price;
//The buyer is only allowed information about the car's condition if they
//contact us directly (which they can't)
private String car_condition;


public Car() {
}

public Long getId() {
return id;
}

public void setId(Long id) {
this.id = id;
}

public int getCar_year()
{
return car_year;
}

public void setCar_year(int car_year)
{
this.car_year = car_year;
}

public String getCar_make()
{
return car_make;
}

public void setCar_make(String car_make)
{
this.car_make = car_make;
}

public String getCar_model()
{
return car_model;
}

public void setCar_model(String car_model)
{
this.car_model = car_model;
}

public double getCar_price()
{
return car_price;
}

public void setCar_price(double car_price)
{
this.car_price = car_price;
}

public String getCar_condition()
{
return car_condition;
}

public void setCar_condition(String car_condition)
{
this.car_condition = car_condition;
}

@Override
public int hashCode()
{
int hash = 7;
hash = 71 * hash + Objects.hashCode(this.id);
hash = 71 * hash + this.car_year;
hash = 71 * hash + Objects.hashCode(this.car_make);
hash = 71 * hash + Objects.hashCode(this.car_model);
hash = 71 * hash + (int) (Double.doubleToLongBits(this.car_price) ^ (Double.doubleToLongBits(this.car_price) >>> 32));
hash = 71 * hash + Objects.hashCode(this.car_condition);
return hash;
}

@Override
public boolean equals(Object obj)
{
if (this == obj)
{
return true;
}
if (obj == null)
{
return false;
}
if (getClass() != obj.getClass())
{
return false;
}
final Car other = (Car) obj;
if (this.car_year != other.car_year)
{
return false;
}
if (Double.doubleToLongBits(this.car_price) != Double.doubleToLongBits(other.car_price))
{
return false;
}
if (!Objects.equals(this.car_make, other.car_make))
{
return false;
}
if (!Objects.equals(this.car_model, other.car_model))
{
return false;
}
if (!Objects.equals(this.car_condition, other.car_condition))
{
return false;
}
if (!Objects.equals(this.id, other.id))
{
return false;
}
return true;
}



@Override
public String toString()
{
return "\nCar with ID: " + id + "\nYear: " + car_year +
"\nMake: " + car_make + "\nModel: " + car_model +
"\nPrice: " + car_price + "\nCondition: " + car_condition;
}



}
1 change: 1 addition & 0 deletions src/main/resources/META-INF/persistence.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<persistence-unit name="pu" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>entities.RenameMe</class>
<class>entities.Car</class>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<!-- DO NOT remove the line below. It's not set by the entityUtils.EMF_Creator -->
Expand Down