diff options
author | Erich Schubert <erich@debian.org> | 2012-12-14 20:45:15 +0100 |
---|---|---|
committer | Andrej Shadura <andrewsh@debian.org> | 2019-03-09 22:30:35 +0000 |
commit | 357b2761a2c0ded8cad5e4d3c1e667b7639ff7a6 (patch) | |
tree | 3dd8947bb70a67c221adc3cd4359ba1d385e2f3c /src/de/lmu/ifi/dbs/elki/data/SimpleClassLabel.java | |
parent | 4343785ebed9d4145f417d86d581f18a0d31e4ac (diff) | |
parent | b7b404fd7a726774d442562d11659d7b5368cdb9 (diff) |
Import Debian changes 0.5.5-1
elki (0.5.5-1) unstable; urgency=low
* New upstream release: 0.5.5 interim release.
Diffstat (limited to 'src/de/lmu/ifi/dbs/elki/data/SimpleClassLabel.java')
-rw-r--r-- | src/de/lmu/ifi/dbs/elki/data/SimpleClassLabel.java | 59 |
1 files changed, 53 insertions, 6 deletions
diff --git a/src/de/lmu/ifi/dbs/elki/data/SimpleClassLabel.java b/src/de/lmu/ifi/dbs/elki/data/SimpleClassLabel.java index ad88295e..b0ee779c 100644 --- a/src/de/lmu/ifi/dbs/elki/data/SimpleClassLabel.java +++ b/src/de/lmu/ifi/dbs/elki/data/SimpleClassLabel.java @@ -23,6 +23,14 @@ package de.lmu.ifi.dbs.elki.data; along with this program. If not, see <http://www.gnu.org/licenses/>. */ +import java.io.IOException; +import java.nio.ByteBuffer; + +import de.lmu.ifi.dbs.elki.data.type.SimpleTypeInformation; +import de.lmu.ifi.dbs.elki.data.type.TypeUtil; +import de.lmu.ifi.dbs.elki.persistent.ByteArrayUtil; +import de.lmu.ifi.dbs.elki.persistent.ByteBufferSerializer; + /** * A simple class label casting a String as it is as label. * @@ -32,6 +40,11 @@ package de.lmu.ifi.dbs.elki.data; */ public class SimpleClassLabel extends ClassLabel { /** + * Serializer. + */ + public static final ByteBufferSerializer<SimpleClassLabel> SERIALIZER = new Serializer(); + + /** * Holds the String designating the label. */ private String label; @@ -51,6 +64,8 @@ public class SimpleClassLabel extends ClassLabel { * Strings they represent. * <p/> * That is, the result equals <code>this.label.compareTo(o.label)</code>. + * + * {@inheritDoc} */ @Override public int compareTo(ClassLabel o) { @@ -61,6 +76,8 @@ public class SimpleClassLabel extends ClassLabel { /** * The hash code of a simple class label is the hash code of the String * represented by the ClassLabel. + * + * {@inheritDoc} */ @Override public int hashCode() { @@ -78,13 +95,13 @@ public class SimpleClassLabel extends ClassLabel { */ @Override public boolean equals(Object o) { - if(this == o) { + if (this == o) { return true; } - if(o == null || getClass() != o.getClass()) { + if (o == null || getClass() != o.getClass()) { return false; } - if(!super.equals(o)) { + if (!super.equals(o)) { return false; } final SimpleClassLabel that = (SimpleClassLabel) o; @@ -103,7 +120,31 @@ public class SimpleClassLabel extends ClassLabel { } /** - * Factory class + * Serialization class. + * + * @author Erich Schubert + * + * @apiviz.uses SimpleClassLabel - - «serializes» + */ + public static class Serializer implements ByteBufferSerializer<SimpleClassLabel> { + @Override + public SimpleClassLabel fromByteBuffer(ByteBuffer buffer) throws IOException { + return new SimpleClassLabel(ByteArrayUtil.STRING_SERIALIZER.fromByteBuffer(buffer)); + } + + @Override + public void toByteBuffer(ByteBuffer buffer, SimpleClassLabel object) throws IOException { + ByteArrayUtil.STRING_SERIALIZER.toByteBuffer(buffer, object.label); + } + + @Override + public int getByteSize(SimpleClassLabel object) throws IOException { + return ByteArrayUtil.STRING_SERIALIZER.getByteSize(object.label); + } + } + + /** + * Factory class. * * @author Erich Schubert * @@ -113,12 +154,18 @@ public class SimpleClassLabel extends ClassLabel { public static class Factory extends ClassLabel.Factory<SimpleClassLabel> { @Override public SimpleClassLabel makeFromString(String lbl) { + lbl = lbl.intern(); SimpleClassLabel l = existing.get(lbl); - if(l == null) { + if (l == null) { l = new SimpleClassLabel(lbl); existing.put(lbl, l); } return l; } + + @Override + public SimpleTypeInformation<? super SimpleClassLabel> getTypeInformation() { + return TypeUtil.SIMPLE_CLASSLABEL; + } } -}
\ No newline at end of file +} |