Skip to content

Commit

Permalink
Create MutableMapFromJavaTest
Browse files Browse the repository at this point in the history
  • Loading branch information
Glavo committed Jan 19, 2025
1 parent a999499 commit 8272e71
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions src/test/java/kala/collection/mutable/MutableMapFromJavaTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright 2025 Glavo
*
* 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 kala.collection.mutable;

import kala.collection.factory.MapFactory;

import java.util.HashMap;

public final class MutableMapFromJavaTest implements MutableMapTestTemplate {
@Override
public <K, V> MapFactory<K, V, ?, MutableMap<K, V>> factory() {
return new Factory<>();
}

@Override
public Class<?> mapType() {
return null;
}

private static final class Factory<K, V> implements MapFactory<K, V, HashMap<K, V>, MutableMap<K, V>> {

@Override
public HashMap<K, V> newBuilder() {
return new HashMap<>();
}

@Override
public MutableMap<K, V> build(HashMap<K, V> builder) {
return MutableMap.wrapJava(builder);
}

@Override
public void addToBuilder(HashMap<K, V> builder, K key, V value) {
builder.put(key, value);
}

@Override
public HashMap<K, V> mergeBuilder(HashMap<K, V> builder1, HashMap<K, V> builder2) {
builder1.putAll(builder2);
return builder1;
}
}
}

0 comments on commit 8272e71

Please sign in to comment.