Skip to content

Commit 3b6d709

Browse files
Egima profilepivovarit
authored andcommitted
Code for Map (eugenp#909)
* made changes to java reflection * removed redundant method makeSound in Animal abstract class * added project for play-framework article * added project for regex * changed regex project from own model to core-java * added project for routing in play * made changes to regex project * refactored code for REST API with Play project * refactored student store indexing to zero base * added unit tests, removed bad names * added NIO Selector project under core-java module * requested changes made * added project for nio2 * standardized exception based tests * fixed exception based tests * removed redundant files * added network interface project * used UUID other than timestamps * fixed network interface tests * removed filetest change * made changes to NIO2 FileTest names * added project for asyncronous channel apis * added project for NIO2 advanced filesystems APIS * merge conflicts * merged changes to asyncfiletest with future get API * removed while loops from async client and server * added project for java8 optional * fixed merge conflicts in spring-core * fixed optional * fixed optional * fixed asyncechotest * shifted optional to own package * made additional tests to demo filter API * added code for Map
1 parent acdea70 commit 3b6d709

3 files changed

Lines changed: 434 additions & 0 deletions

File tree

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package com.baeldung.java.map;
2+
3+
public class MyKey {
4+
private String name;
5+
private int id;
6+
7+
public MyKey(int id, String name) {
8+
this.id = id;
9+
this.name = name;
10+
}
11+
12+
public String getName() {
13+
return name;
14+
}
15+
16+
public void setName(String name) {
17+
this.name = name;
18+
}
19+
20+
public int getId() {
21+
return id;
22+
}
23+
24+
public void setId(int id) {
25+
this.id = id;
26+
}
27+
28+
@Override
29+
public int hashCode() {
30+
System.out.println("Calling hashCode()");
31+
return id;
32+
}
33+
34+
@Override
35+
public String toString() {
36+
return "MyKey [name=" + name + ", id=" + id + "]";
37+
}
38+
39+
@Override
40+
public boolean equals(Object obj) {
41+
System.out.println("Calling equals() for key: " + obj);
42+
if (this == obj)
43+
return true;
44+
if (obj == null)
45+
return false;
46+
if (getClass() != obj.getClass())
47+
return false;
48+
MyKey other = (MyKey) obj;
49+
if (id != other.id)
50+
return false;
51+
if (name == null) {
52+
if (other.name != null)
53+
return false;
54+
} else if (!name.equals(other.name))
55+
return false;
56+
return true;
57+
}
58+
59+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.baeldung.java.map;
2+
3+
import java.util.LinkedHashMap;
4+
import java.util.Map;
5+
6+
public class MyLinkedHashMap<K, V> extends LinkedHashMap<K, V> {
7+
8+
/**
9+
*
10+
*/
11+
private static final long serialVersionUID = 1L;
12+
private static final int MAX_ENTRIES = 5;
13+
14+
15+
public MyLinkedHashMap(int initialCapacity, float loadFactor, boolean accessOrder) {
16+
super(initialCapacity, loadFactor, accessOrder);
17+
}
18+
19+
20+
@Override
21+
protected boolean removeEldestEntry(Map.Entry eldest) {
22+
return size() > MAX_ENTRIES;
23+
}
24+
25+
}

0 commit comments

Comments
 (0)