Skip to content

Commit

Permalink
Use strings for session keys, so that we can later serialize the session
Browse files Browse the repository at this point in the history
  • Loading branch information
testinfected committed Nov 17, 2015
1 parent b5bc0f1 commit ed69f4e
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/main/java/com/vtence/molecule/session/Session.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
public class Session {

private final String id;
private final Map<Object, Object> attributes = new ConcurrentHashMap<>();
private final Map<String, Object> attributes = new ConcurrentHashMap<>();

private Instant createdAt = Instant.now();
private Instant updatedAt = Instant.now();
Expand Down Expand Up @@ -92,31 +92,31 @@ public boolean isEmpty() {
}

public boolean contains(Object key) {
return attributes.containsKey(key);
return attributes.containsKey(String.valueOf(key));
}

@SuppressWarnings("unchecked")
public <T> T get(Object key) {
return (T) attributes.get(key);
return (T) attributes.get(String.valueOf(key));
}

@SuppressWarnings("unchecked")
public <T> T put(Object key, Object value) {
checkValid();
return (T) attributes.put(key, value);
return (T) attributes.put(String.valueOf(key), value);
}

@SuppressWarnings("unchecked")
public <T> T remove(Object key) {
checkValid();
return (T) attributes.remove(key);
return (T) attributes.remove(String.valueOf(key));
}

private void checkValid() {
if (invalid) throw new IllegalStateException("Session invalidated");
}

public Set<Object> keys() {
public Set<String> keys() {
return Collections.unmodifiableSet(attributes.keySet());
}

Expand Down

0 comments on commit ed69f4e

Please sign in to comment.