-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #35 from saalfeldlab/fix/serializationHashCollision
Fix/serialization hash collision
- Loading branch information
Showing
5 changed files
with
96 additions
and
26 deletions.
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
src/main/java/net/imglib2/type/label/ComparableLabelMultisetEntryList.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package net.imglib2.type.label; | ||
|
||
class ComparableLabelMultisetEntryList extends LabelMultisetEntryList implements Comparable<LabelMultisetEntryList> { | ||
|
||
private final LabelMultisetEntry ref; | ||
|
||
ComparableLabelMultisetEntryList() { | ||
this(new LabelMultisetEntry()); | ||
} | ||
|
||
ComparableLabelMultisetEntryList(final LabelMultisetEntry ref) { | ||
|
||
this.ref = ref; | ||
} | ||
|
||
ComparableLabelMultisetEntryList(final LabelMultisetEntryList list) { | ||
this(list, new LabelMultisetEntry()); | ||
|
||
} | ||
ComparableLabelMultisetEntryList(final LabelMultisetEntryList list, final LabelMultisetEntry ref) { | ||
|
||
this.ref = ref; | ||
referToDataAt(list.data, list.getBaseOffset()); | ||
} | ||
|
||
@Override public LabelMultisetEntry createRef() { | ||
|
||
return ref; | ||
} | ||
|
||
@Override public int compareTo(LabelMultisetEntryList o) { | ||
|
||
final int size = size(); | ||
|
||
/* if different sizes or empty, return result of compare size*/ | ||
final int sizeCompare = Integer.compare(size, o.size()); | ||
if (sizeCompare != 0 || size == 0) | ||
return sizeCompare; | ||
|
||
final RefIterator<LabelMultisetEntry> thisIter = iterator(); | ||
final RefIterator<LabelMultisetEntry> otherIter = o.iterator(); | ||
|
||
for (int i = 0; i < size; i++) { | ||
final LabelMultisetEntry thisNext = thisIter.next(); | ||
final LabelMultisetEntry otherNext = otherIter.next(); | ||
|
||
final int idCompare = Long.compare(thisNext.getId(), otherNext.getId()); | ||
if (idCompare != 0) | ||
return idCompare; | ||
|
||
final int countCompare = Integer.compare(thisNext.getCount(), otherNext.getCount()); | ||
if (countCompare != 0) | ||
return countCompare; | ||
} | ||
|
||
return 0; | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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