Last active
February 9, 2018 06:17
-
-
Save 180254/0866b155a27add56cd02f65407ee0a1c to your computer and use it in GitHub Desktop.
IgniteCache as Map viewer
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
package pl.cee.util; | |
import org.apache.ignite.IgniteCache; | |
import org.jetbrains.annotations.NotNull; | |
import java.util.Collection; | |
import java.util.Map; | |
import java.util.Set; | |
/* | |
The MIT License | |
Copyright (c) 2017 180254 | |
Permission is hereby granted, free of charge, to any person obtaining a copy | |
of this software and associated documentation files (the "Software"), to deal | |
in the Software without restriction, including without limitation the rights | |
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
copies of the Software, and to permit persons to whom the Software is | |
furnished to do so, subject to the following conditions: | |
The above copyright notice and this permission notice shall be included in | |
all copies or substantial portions of the Software. | |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |
THE SOFTWARE. | |
*/ | |
public class IgniteCacheMapView<K, V> implements Map<K, V> { | |
private final IgniteCache<K, V> cache; | |
public IgniteCacheMapView(IgniteCache<K, V> cache) { | |
this.cache = cache; | |
} | |
@Override | |
public int size() { | |
return cache.size(); | |
} | |
@Override | |
public boolean isEmpty() { | |
return cache.size() == 0; | |
} | |
@Override | |
@SuppressWarnings("unchecked") | |
public boolean containsKey(Object key) { | |
return cache.containsKey((K) key); | |
} | |
@Override | |
public boolean containsValue(Object value) { | |
throw new UnsupportedOperationException(); | |
} | |
@Override | |
@SuppressWarnings("unchecked") | |
public V get(Object key) { | |
return cache.get((K) key); | |
} | |
@Override | |
@SuppressWarnings("unchecked") | |
public V put(Object key, Object value) { | |
return cache.getAndPut((K) key, (V) value); | |
} | |
@Override | |
@SuppressWarnings("unchecked") | |
public V remove(Object key) { | |
return cache.getAndRemove((K) key); | |
} | |
@Override | |
public void putAll(@NotNull Map<? extends K, ? extends V> m) { | |
m.forEach(cache::put); | |
} | |
@Override | |
public void clear() { | |
cache.clear(); | |
} | |
@NotNull | |
@Override | |
public Set<K> keySet() { | |
throw new UnsupportedOperationException(); | |
} | |
@NotNull | |
@Override | |
public Collection<V> values() { | |
throw new UnsupportedOperationException(); | |
} | |
@NotNull | |
@Override | |
public Set<Entry<K, V>> entrySet() { | |
throw new UnsupportedOperationException(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment