Skip to content

Commit

Permalink
ServiceMap (basically a key/value map interface)
Browse files Browse the repository at this point in the history
  • Loading branch information
fugerit79 committed Feb 1, 2024
1 parent 62bb2af commit 4229582
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 0 deletions.
4 changes: 4 additions & 0 deletions data-service-base/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- ServiceMap (basically a key/value map interface)

## [0.2.5 - 2023-11-12]

### Added
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.fugerit.java.dsb.attributes;

public interface ServiceMap<K,V> {

V get(K key);

void set(K key, V value);

void remove(K key);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package org.fugerit.java.dsb.attributes;

public interface SimpleServiceMap extends ServiceMap<String, String> {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package org.fugerit.java.dsb.attributes.impl;

import org.fugerit.java.dsb.attributes.ServiceMap;

import java.util.HashMap;
import java.util.Map;

public class ServiceMapDefault<K, V> implements ServiceMap<K, V> {

private Map<K, V> map;
public ServiceMapDefault() {
this.map = new HashMap<K, V>();
}

@Override
public V get(K key) {
return this.map.get( key );
}

@Override
public void set(K key, V value ) {
this.map.put( key, value );
}

@Override
public void remove(K key) {
this.map.remove( key );
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package org.fugerit.java.dsb.attributes.impl;

public class SimpleServiceMapDefault extends ServiceMapDefault<String, String> implements org.fugerit.java.dsb.attributes.SimpleServiceMap {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package test.org.fugerit.java.dsb.attributes.impl;

import lombok.extern.slf4j.Slf4j;
import org.fugerit.java.dsb.attributes.SimpleServiceMap;
import org.fugerit.java.dsb.attributes.impl.SimpleServiceMapDefault;
import org.junit.Assert;
import org.junit.Test;

import static org.junit.Assert.*;

@Slf4j
public class ServiceMapDefaultTest {

@Test
public void testMapSimple() {
String key = "testKey";
String value = "testValue";
SimpleServiceMap map = new SimpleServiceMapDefault();
map.set( key, value );
Assert.assertEquals( value, map.get( key ) );
map.remove( key );
Assert.assertNull( map.get( key ) );
log.info( "test key:{}, value:{} ok", key, value );
}

}

0 comments on commit 4229582

Please sign in to comment.