diff --git a/src/main/java/com/github/shyiko/mysql/binlog/GtidSet.java b/src/main/java/com/github/shyiko/mysql/binlog/GtidSet.java index b37ff527..6899eafe 100644 --- a/src/main/java/com/github/shyiko/mysql/binlog/GtidSet.java +++ b/src/main/java/com/github/shyiko/mysql/binlog/GtidSet.java @@ -83,6 +83,16 @@ public UUIDSet getUUIDSet(String uuid) { return map.get(uuid); } + /** + * Add or replace the UUIDSet + * @param uuidSet UUIDSet to be added + * @return the old {@link UUIDSet} for the server given in uuidSet param, + * or {@code null} if there are no UUIDSet for the given server. + */ + public UUIDSet putUUIDSet(UUIDSet uuidSet) { + return map.put(uuidSet.getUUID(), uuidSet); + } + /** * @param gtid GTID ("source_id:transaction_id") * @return whether or not gtid was added to the set (false if it was already there) @@ -170,7 +180,7 @@ public static final class UUIDSet { private String uuid; private List intervals; - UUIDSet(String uuid, List intervals) { + public UUIDSet(String uuid, List intervals) { this.uuid = uuid; this.intervals = intervals; if (intervals.size() > 1) { @@ -339,7 +349,7 @@ public static final class Interval implements Comparable { private long start; private long end; - Interval(long start, long end) { + public Interval(long start, long end) { this.start = start; this.end = end; } diff --git a/src/test/java/com/github/shyiko/mysql/binlog/GtidSetTest.java b/src/test/java/com/github/shyiko/mysql/binlog/GtidSetTest.java index b2215a9c..79318aa6 100644 --- a/src/test/java/com/github/shyiko/mysql/binlog/GtidSetTest.java +++ b/src/test/java/com/github/shyiko/mysql/binlog/GtidSetTest.java @@ -154,4 +154,14 @@ public void testMultipleIntervalsThatMayBeAdjacent() { assertEquals(gtidSet.toString(), UUID + ":1-199:1000-1033:1035-1036:1038-1039"); } + @Test + public void testPutUUIDSet() { + GtidSet gtidSet = new GtidSet(UUID + ":1-191"); + UUIDSet uuidSet = gtidSet.getUUIDSet(UUID); + GtidSet gtidSet2 = new GtidSet(UUID + ":1-190"); + UUIDSet uuidSet2 = gtidSet2.getUUIDSet(UUID); + gtidSet.putUUIDSet(uuidSet2); + assertEquals(gtidSet, gtidSet2); + } + }