-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathCRUDDemo.java
More file actions
122 lines (101 loc) · 2.17 KB
/
CRUDDemo.java
File metadata and controls
122 lines (101 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import java.util.ArrayList;
class Employee implements Comparable<Employee>
{
private Integer id;
private String name;
Employee(int id , String name){
this.id = id;
this.name = name;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public int compareTo(Employee o ){
//Employee e = (Employee)o;
//return this.id.compareTo(o.id);
return this.name.compareToIgnoreCase(o.name);
//return o.name.compareTo(this.name);
}
/*@Override
public boolean equals(Object o){
boolean isFound = false;
Employee e = (Employee)o;
if(this.id>0 && e.id>0){
if(this.id ==e.id){
isFound = true;
}
}
if(this.name!=null && e.name!=null){
if(this.name.trim().length()>0 && e.name.trim().length()>0){
if(this.name.equals(e.name)){
isFound = true;
}
else
{
isFound = false;
}
}
}
if(this.id==e.id && this.name.equals(e.name)){
return true;
}
else
{
return false;
}
return isFound;
}*/
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Employee other = (Employee) obj;
if (id != other.id)
return false;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
return false;
return true;
}
@Override
public String toString() {
return "Employee [id=" + id + ", name=" + name + "]";
}
}
public class CRUDDemo {
public static void main(String[] args) {
ArrayList<Employee> empList = new ArrayList<Employee>();
Employee ram = new Employee(1001, "Ram");
empList.add(ram);
Employee shyam = new Employee(1002, "Shyam");
empList.add(shyam);
System.out.println(empList);
int id = 1001;
Employee ramSearch = new Employee(id, "Ram");
if(empList.contains(ramSearch)){
System.out.println("Found...");
empList.set(empList.indexOf(ramSearch),ram);
//empList.remove(empList.indexOf(ramSearch));
}
else
{
System.out.println("Not Found...");
}
}
}