All Downloads are FREE. Search and download functionalities are using the official Maven repository.

fr.ird.observe.spi.map.ImmutableSetMap Maven / Gradle / Ivy

There is a newer version: 4.34
Show newest version
package fr.ird.observe.spi.map;

/*-
 * #%L
 * ObServe Toolkit :: Common Dto
 * %%
 * Copyright (C) 2017 - 2020 IRD, Ultreia.io
 * %%
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public
 * License along with this program.  If not, see
 * .
 * #L%
 */

import com.google.common.collect.ImmutableMap;
import fr.ird.observe.dto.ObserveDto;
import fr.ird.observe.spi.type.TypeTranslators;

import java.util.Collection;
import java.util.Set;

/**
 * A special map to store string values using the {@link #key0(Class)} method to produce keys.
 * 

* Created by tchemit on 01/09/17. * * @author Tony Chemit - [email protected] */ public abstract class ImmutableSetMap implements ObserveDto { private final ImmutableMap> data; private final ImmutableMap types; ImmutableSetMap(ImmutableMap> data, ImmutableMap types) { this.data = data; this.types = types; } public int size() { return data.size(); } public boolean isEmpty() { return data.isEmpty(); } public Set get(Class key) { return data.get(key0(key)); } public Set keySet() { return data.keySet(); } public Collection> values() { return data.values(); } public boolean containsEntry(Class type, V value) { String key = key0(type); return data.containsKey(key) && data.get(key).contains(value); } // @SuppressWarnings("unchecked") // public Set> referentialReferenceTypes() { // return (Set) types.values().stream().filter(IdHelper::isReferential).collect(Collectors.toSet()); // } // @SuppressWarnings("unchecked") // public Set> dataReferenceTypes() { // return (Set) types.values().stream().filter(IdHelper::isData).collect(Collectors.toSet()); // } public ImmutableMap> getData() { return data; } public ImmutableMap getTypes() { return types; } @SuppressWarnings("unchecked") public Collection> types() { return (Collection) types.values(); } protected static String key0(Class type) { return TypeTranslators.getTranslator(type).cleanType(type); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy