1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-11-24 07:12:05 +01:00

Add MemoryAvatarMetadataStore

This commit is contained in:
Paul Schaub 2020-02-09 19:44:56 +01:00
parent c6e9e5c717
commit 516c61500f

View file

@ -0,0 +1,68 @@
package org.jivesoftware.smackx.avatar;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.jivesoftware.smack.util.HashCode;
import org.jivesoftware.smack.util.Objects;
import org.jxmpp.jid.EntityBareJid;
public class MemoryAvatarMetadataStore implements AvatarMetadataStore {
private Map<Tuple<EntityBareJid, String>, Boolean> availabilityMap = new ConcurrentHashMap<>();
@Override
public boolean hasAvatarAvailable(EntityBareJid jid, String itemId) {
Boolean available = availabilityMap.get(new Tuple<>(jid, itemId));
return available != null && available;
}
@Override
public void setAvatarAvailable(EntityBareJid jid, String itemId) {
availabilityMap.put(new Tuple<>(jid, itemId), Boolean.TRUE);
}
private static class Tuple<A, B> {
private final A first;
private final B second;
public Tuple(A first, B second) {
this.first = first;
this.second = second;
}
public A getFirst() {
return first;
}
public B getSecond() {
return second;
}
@Override
public int hashCode() {
return HashCode.builder()
.append(first)
.append(second)
.build();
}
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (obj == this) {
return true;
}
if (!(obj instanceof Tuple)) {
return false;
}
@SuppressWarnings("unchecked") Tuple<A, B> other = (Tuple<A, B>) obj;
return Objects.equals(getFirst(), other.getFirst())
&& Objects.equals(getSecond(), other.getSecond());
}
}
}