Skip to content

Commit

Permalink
Start on kryo-jdkgdxds.
Browse files Browse the repository at this point in the history
That means FilteredStringSetSerializer for now.
  • Loading branch information
tommyettinger committed Dec 9, 2023
1 parent d053578 commit 6c1bc55
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 4 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ funderbyVersion=0.1.1
regexodusVersion=0.1.15
digitalVersion=0.4.5
juniperVersion=0.5.0
jdkgdxdsVersion=1.4.4
jdkgdxdsVersion=1.4.6
simpleGraphsVersion=v5.1.1

GROUP=com.github.tommyettinger
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
2 changes: 1 addition & 1 deletion kryo-jdkgdxds/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ if(JavaVersion.current().isJava9Compatible()) {
}

dependencies {
api "com.github.tommyettinger:kryo-digital:0.4.3.0"
api "com.github.tommyettinger:kryo-digital:0.4.5.0"
api "com.esotericsoftware:kryo:$kryoVersion"
api "com.github.tommyettinger:jdkgdxds:$jdkgdxdsVersion"
testImplementation "junit:junit:4.13.2"
Expand Down
2 changes: 1 addition & 1 deletion kryo-jdkgdxds/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ POM_ARTIFACT_ID=kryo-jdkgdxds
POM_NAME=kryo-jdkgdxds
POM_DESCRIPTION=Kryo 5.x serializers for jdkgdxds types
POM_INCEPTION_YEAR=2022
VERSION_NAME=1.4.4.1-SNAPSHOT
VERSION_NAME=1.4.6.0-SNAPSHOT
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright (c) 2022-2023 See AUTHORS file.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

package com.github.tommyettinger.kryo.jdkgdxds;

import com.esotericsoftware.kryo.Kryo;
import com.esotericsoftware.kryo.io.Input;
import com.esotericsoftware.kryo.io.Output;
import com.esotericsoftware.kryo.serializers.CollectionSerializer;
import com.github.tommyettinger.ds.CharFilter;
import com.github.tommyettinger.ds.FilteredStringSet;
import com.github.tommyettinger.ds.Utilities;

import java.util.NoSuchElementException;

public class FilteredStringSetSerializer extends CollectionSerializer<FilteredStringSet> {
public FilteredStringSetSerializer() {
super();
setElementsCanBeNull(false);
}

@Override
protected void writeHeader(Kryo kryo, Output output, FilteredStringSet collection) {
CharFilter fil = collection.getFilter();
if(fil == null)
throw new NoSuchElementException("A FilteredStringSet must have a non-null filter to be serialized.");
output.writeString(fil.getName());
}

@Override
protected FilteredStringSet create(Kryo kryo, Input input, Class<? extends FilteredStringSet> type, int size) {
return new FilteredStringSet(CharFilter.get(input.readString()), size, Utilities.getDefaultLoadFactor());
}

@Override
protected FilteredStringSet createCopy(Kryo kryo, FilteredStringSet original) {
return new FilteredStringSet(original.getFilter(), original.size(), original.getLoadFactor());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -247,4 +247,26 @@ public void testHolderOrderedSet() {
Assert.assertEquals(data, data2);
}
}


@Test
public void testFilteredStringSet() {
CharFilter filter = CharFilter.getOrCreate("LettersOnlyIgnoreCase", Character::isLetter, Character::toUpperCase);
Kryo kryo = new Kryo();
kryo.register(String.class);
kryo.register(FilteredStringSet.class, new FilteredStringSetSerializer());

FilteredStringSet data = FilteredStringSet.with(filter, "Hello", "World", "!", "YES", "HELLO", "WORLD", "!");

ByteArrayOutputStream baos = new ByteArrayOutputStream(32);
Output output = new Output(baos);
kryo.writeObject(output, data);
byte[] bytes = output.toBytes();
try (Input input = new Input(bytes)) {
FilteredStringSet data2 = kryo.readObject(input, FilteredStringSet.class);
Assert.assertEquals(data, data2);
}
}


}

0 comments on commit 6c1bc55

Please sign in to comment.