// Path: src/main/java/com/papercut/dust/model/TransactionalMapProducer.java
// public interface TransactionalMapProducer {
// 
//     <T> TransactionalMap<T> createStore(final String name);
// 
// }
// 
// Path: src/main/java/com/papercut/dust/device/DeviceEvent.java
// public class DeviceEvent implements Serializable {
// 
//     public enum DeviceEventType {
//         CLAIMED, UNCLAIMED
//     };
// 
//     public final Claim claim;
//     public final DeviceEventType type;
// 
//     public DeviceEvent(final Claim claim, final DeviceEventType type) {
//         this.claim = claim;
//         this.type = type;
//     }
// 
// }
// 
// Path: src/main/java/com/papercut/dust/device/DeviceEvent.java
// public enum DeviceEventType {
//     CLAIMED, UNCLAIMED
// };
// 
// Path: src/main/java/com/papercut/dust/model/Repository.java
// public abstract class Repository<T extends Identifiable<T>> {
// 
//     protected final Map<Long, T> store;
//     private final Class<T> entityClass;
// 
//     protected Repository(final Class<T> entityClass, final Map<Long, T> store) {
//         this.entityClass = entityClass;
//         this.store = store;
//     }
// 
//     protected void load(final String dataDir, final boolean update) {
//         try {
//             final File dir = new File("data/fixtures/" + dataDir);
//             final File[] files = dir.listFiles((d, name) -> name.endsWith(".json"));
// 
//             if (files == null) {
//                 throw new IOException("No files found in " + dir.getAbsolutePath());
//             }
// 
//             final ObjectMapper mapper = new ObjectMapper();
//             mapper.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE);
//             for (File jsonFile : files) {
//                 final T entity = mapper.readValue(jsonFile, entityClass);
//                 if (update && entity.getId() != null) {
//                     update(entity);
//                 } else {
//                     create(entity);
//                 }
//             }
//         } catch (IOException ioex) {
//             throw new RuntimeException(ioex);
//         }
// 
//     }
// 
//     protected T create(final T entity) {
//         final Long newId = maxId() + 1;
//         final T newEntity = entity.withId(newId);
//         final T existing = store.putIfAbsent(newId, newEntity);
//         if (existing != null) {
//             throw new IllegalArgumentException("Entity already exists");
//         }
//         return newEntity;
//     }
// 
//     protected T update(final T entity) {
//         if (!store.containsKey(entity.getId())) {
//             throw new IllegalArgumentException("Cannot update entity, it does not exist");
//         }
//         return store.put(entity.getId(), entity);
//     }
// 
//     protected T delete(final long id) {
//         return store.remove(id);
//     }
// 
//     protected Collection<T> findAll() {
//         return store.values();
//     }
// 
//     protected T findById(final long id) {
//         return Optional.ofNullable(store.get(id))
//                 .orElseThrow(() -> NoSuchUniqueDeviceException.none(String.valueOf(id)));
//     }
// 
//     protected Collection<T> findByKeyword(final String keyword) {
//         return store.values().stream().filter(e -> hasKeyword(e, keyword)).collect(toList());
//     }
// 
//     protected abstract boolean hasKeyword(final T entity, final String keyword);
// 
//     protected static boolean containsKeyword(final String text, final String keyword) {
//         return text != null && keyword != null && text.toLowerCase().contains(keyword.toLowerCase());
//     }
// 
//     private long maxId() {
//         return store.keySet().stream().mapToLong(x -> x).max().orElse(0L);
//     }
// }


import com.papercut.dust.model.TransactionalMapProducer;
import com.papercut.dust.device.DeviceEvent;
import com.papercut.dust.device.DeviceEvent.DeviceEventType;
import com.papercut.dust.model.Repository;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.event.Event;
import javax.inject.Inject;
import static java.util.stream.Collectors.toList;
    }

    @Override
    protected Collection<Claim> findByKeyword(final String keyword) {
        return super.findByKeyword(keyword);
    }

    @Override
    protected Claim findById(final long id) {
        return super.findById(id);
    }

    public Collection<Claim> find(final Long deviceId, final Long userId, final Boolean active) {
        return store.values().stream()
                .filter(c
                        -> (deviceId == null || c.deviceId == deviceId)
                        && (userId == null || c.userId == userId)
                        && (active == null || (active
                                ? c.endDate == null
                                : c.endDate.isBefore(LocalDateTime.now())))
                )
                .collect(toList());
    }

    public Claim findActive(final long deviceId, final long userId) throws NoSuchClaimException {
        return find(deviceId, userId, true).stream()
                .findFirst()
                .orElseThrow(() -> new NoSuchClaimException(deviceId, userId));
    }

// Path: src/main/java/com/papercut/dust/model/TransactionalMapProducer.java
// public interface TransactionalMapProducer {
// 
//     <T> TransactionalMap<T> createStore(final String name);
// 
// }
// 
// Path: src/main/java/com/papercut/dust/device/DeviceEvent.java
// public class DeviceEvent implements Serializable {
// 
//     public enum DeviceEventType {
//         CLAIMED, UNCLAIMED
//     };
// 
//     public final Claim claim;
//     public final DeviceEventType type;
// 
//     public DeviceEvent(final Claim claim, final DeviceEventType type) {
//         this.claim = claim;
//         this.type = type;
//     }
// 
// }
// 
// Path: src/main/java/com/papercut/dust/device/DeviceEvent.java
// public enum DeviceEventType {
//     CLAIMED, UNCLAIMED
// };
// 
// Path: src/main/java/com/papercut/dust/model/Repository.java
// public abstract class Repository<T extends Identifiable<T>> {
// 
//     protected final Map<Long, T> store;
//     private final Class<T> entityClass;
// 
//     protected Repository(final Class<T> entityClass, final Map<Long, T> store) {
//         this.entityClass = entityClass;
//         this.store = store;
//     }
// 
//     protected void load(final String dataDir, final boolean update) {
//         try {
//             final File dir = new File("data/fixtures/" + dataDir);
//             final File[] files = dir.listFiles((d, name) -> name.endsWith(".json"));
// 
//             if (files == null) {
//                 throw new IOException("No files found in " + dir.getAbsolutePath());
//             }
// 
//             final ObjectMapper mapper = new ObjectMapper();
//             mapper.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE);
//             for (File jsonFile : files) {
//                 final T entity = mapper.readValue(jsonFile, entityClass);
//                 if (update && entity.getId() != null) {
//                     update(entity);
//                 } else {
//                     create(entity);
//                 }
//             }
//         } catch (IOException ioex) {
//             throw new RuntimeException(ioex);
//         }
// 
//     }
// 
//     protected T create(final T entity) {
//         final Long newId = maxId() + 1;
//         final T newEntity = entity.withId(newId);
//         final T existing = store.putIfAbsent(newId, newEntity);
//         if (existing != null) {
//             throw new IllegalArgumentException("Entity already exists");
//         }
//         return newEntity;
//     }
// 
//     protected T update(final T entity) {
//         if (!store.containsKey(entity.getId())) {
//             throw new IllegalArgumentException("Cannot update entity, it does not exist");
//         }
//         return store.put(entity.getId(), entity);
//     }
// 
//     protected T delete(final long id) {
//         return store.remove(id);
//     }
// 
//     protected Collection<T> findAll() {
//         return store.values();
//     }
// 
//     protected T findById(final long id) {
//         return Optional.ofNullable(store.get(id))
//                 .orElseThrow(() -> NoSuchUniqueDeviceException.none(String.valueOf(id)));
//     }
// 
//     protected Collection<T> findByKeyword(final String keyword) {
//         return store.values().stream().filter(e -> hasKeyword(e, keyword)).collect(toList());
//     }
// 
//     protected abstract boolean hasKeyword(final T entity, final String keyword);
// 
//     protected static boolean containsKeyword(final String text, final String keyword) {
//         return text != null && keyword != null && text.toLowerCase().contains(keyword.toLowerCase());
//     }
// 
//     private long maxId() {
//         return store.keySet().stream().mapToLong(x -> x).max().orElse(0L);
//     }
// }


// Path: src/main/java/com/papercut/dust/claim/ClaimRepository.java
import com.papercut.dust.model.TransactionalMapProducer;
import com.papercut.dust.device.DeviceEvent;
import com.papercut.dust.device.DeviceEvent.DeviceEventType;
import com.papercut.dust.model.Repository;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.event.Event;
import javax.inject.Inject;
import static java.util.stream.Collectors.toList;

    }

    @Override
    protected Collection<Claim> findByKeyword(final String keyword) {
        return super.findByKeyword(keyword);
    }

    @Override
    protected Claim findById(final long id) {
        return super.findById(id);
    }

    public Collection<Claim> find(final Long deviceId, final Long userId, final Boolean active) {
        return store.values().stream()
                .filter(c
                        -> (deviceId == null || c.deviceId == deviceId)
                        && (userId == null || c.userId == userId)
                        && (active == null || (active
                                ? c.endDate == null
                                : c.endDate.isBefore(LocalDateTime.now())))
                )
                .collect(toList());
    }

    public Claim findActive(final long deviceId, final long userId) throws NoSuchClaimException {
        return find(deviceId, userId, true).stream()
                .findFirst()
                .orElseThrow(() -> new NoSuchClaimException(deviceId, userId));
    }

    public List<Claim> findActives(final long userId) {