Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
DAAExample
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alejandro Borrajo Viéitez
DAAExample
Commits
ba8d769a
Commit
ba8d769a
authored
Mar 07, 2019
by
Alejandro
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Pet Entity
This Java Class has been created to represent the entity of a pet.
parent
e30dae2c
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
116 additions
and
0 deletions
+116
-0
Pet.java
src/main/java/es/uvigo/esei/daa/entities/Pet.java
+116
-0
No files found.
src/main/java/es/uvigo/esei/daa/entities/Pet.java
0 → 100644
View file @
ba8d769a
package
es
.
uvigo
.
esei
.
daa
.
entities
;
import
static
java
.
util
.
Objects
.
requireNonNull
;
/**
* An entity that represents a pet
*
* @author albovy
*/
public
class
Pet
{
private
int
id
;
private
String
name
;
private
String
type
;
private
int
person
;
//Constructor needed for JSON conversion
Pet
(){}
/**
* Constructs a new instance of {@link Pet}.
*
* @param id identifier of the pet.
* @param name name of the pet.
* @param type specie of the pet.
* @param person owner of the pet.
*/
public
Pet
(
int
id
,
String
name
,
String
type
,
int
person
)
{
this
.
id
=
id
;
this
.
setName
(
name
);
this
.
setType
(
type
);
this
.
person
=
person
;
}
/**
* Returns the identifier of the pet.
*
* @return the identifier of the pet.
*/
public
int
getId
()
{
return
id
;
}
/**
* Returns the name of the pet.
*
* @return the name of the pet.
*/
public
String
getName
()
{
return
name
;
}
/**
* Returns the specie of the pet.
*
* @return the specie of the pet.
*/
public
String
getType
()
{
return
type
;
}
/**
* Returns the owner of the pet.
*
* @return the owner of the pet.
*/
public
int
getPerson
()
{
return
person
;
}
/**
* Set the name of this pet.
*
* @param name the new name of the pet.
* @throws NullPointerException if the{@code name} is {@code null}.
*/
public
void
setName
(
String
name
)
{
this
.
name
=
requireNonNull
(
name
,
"Name can't be null"
);
}
/**
* Set the specie of the pet.
*
* @param type the new specie of the pet.
* @throws NullPointerException if the{@code type} is {@code null}.
*/
public
void
setType
(
String
type
)
{
this
.
type
=
requireNonNull
(
type
,
"Type can't be null"
);
}
/**
* Set the owner of the pet.
*
* @param person the owner of the pet
* @throws NullPointerException if the {@code person} is {@code null}
*/
public
void
setPerson
(
Integer
person
){
this
.
person
=
requireNonNull
(
person
,
"Person can't be null"
);
}
@Override
public
int
hashCode
(){
final
int
prime
=
31
;
int
result
=
1
;
result
=
prime
*
result
+
id
;
return
result
;
}
@Override
public
boolean
equals
(
Object
obj
)
{
if
(
this
==
obj
)
return
true
;
if
(
obj
==
null
)
return
false
;
if
(!(
obj
instanceof
Pet
))
return
false
;
Pet
other
=
(
Pet
)
obj
;
if
(
id
!=
other
.
id
)
return
false
;
return
true
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment