Storage (Storage storage) { if (!(storage instanceof Storage.MapStorage)) { throw new UnsupportedOperationException(storage.getClass().getName()); } Iterator<String> keys = ((Storage.MapStorage)storage).getKeys(); Storage.MapStorage copy = new Storage.MapStorage(); while (keys.hasNext()) { String key = keys.next(); copy.put(key, storage.get(key)); } return copy; }