Created
March 20, 2014 15:16
-
-
Save Miuler/9666090 to your computer and use it in GitHub Desktop.
Probando la mutabilidad en un hashmap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.aep.billing.dao.dialect; | |
import static org.junit.Assert.assertEquals; | |
import java.util.HashMap; | |
import java.util.Map; | |
import org.junit.Test; | |
/** | |
* @author: miuler | |
* <p/> | |
* date: 20/03/14 time: 10:01 AM | |
*/ | |
public class PruebaMutable { | |
class Point { | |
private int x, y; | |
public Point(int x, int y) { | |
this.x = x; | |
this.y = y; | |
} | |
public Point move(int x, int y) { | |
this.x = x; | |
this.y = y; | |
return this; | |
} | |
@Override | |
public boolean equals(Object o) { | |
if (this == o) return true; | |
if (o == null || getClass() != o.getClass()) return false; | |
Point point = (Point) o; | |
if (x != point.x) return false; | |
if (y != point.y) return false; | |
return true; | |
} | |
@Override | |
public int hashCode() { | |
int result = x; | |
result = 31 * result + y; | |
return result; | |
} | |
} | |
@Test | |
public void pruebaInmutable() { | |
final Map<Point, String> map = new HashMap<Point, String>(); | |
Point p1 = new Point(1, 1); | |
Point p2 = new Point(2, 2); | |
map.put(p1, "p1"); | |
map.put(p2, "p2"); | |
assertEquals("p1", map.get(p1)); | |
p1.move(10, 10); | |
assertEquals("p1", map.get(p1)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment