Code for Map (#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
This commit is contained in:
committed by
Grzegorz Piwowarek
parent
acdea70d4c
commit
3b6d709108
59
core-java/src/main/java/com/baeldung/java/map/MyKey.java
Normal file
59
core-java/src/main/java/com/baeldung/java/map/MyKey.java
Normal file
@@ -0,0 +1,59 @@
|
||||
package com.baeldung.java.map;
|
||||
|
||||
public class MyKey {
|
||||
private String name;
|
||||
private int id;
|
||||
|
||||
public MyKey(int id, String name) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
System.out.println("Calling hashCode()");
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "MyKey [name=" + name + ", id=" + id + "]";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
System.out.println("Calling equals() for key: " + obj);
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
MyKey other = (MyKey) 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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.baeldung.java.map;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class MyLinkedHashMap<K, V> extends LinkedHashMap<K, V> {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final int MAX_ENTRIES = 5;
|
||||
|
||||
|
||||
public MyLinkedHashMap(int initialCapacity, float loadFactor, boolean accessOrder) {
|
||||
super(initialCapacity, loadFactor, accessOrder);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected boolean removeEldestEntry(Map.Entry eldest) {
|
||||
return size() > MAX_ENTRIES;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user