io.ultreia.java4all.classmapping.ImmutableClassMapping Maven / Gradle / Ivy
package io.ultreia.java4all.classmapping;
/*-
* #%L
* Class Mapping tools
* %%
* Copyright (C) 2017 Ultreia.io
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* .
* #L%
*/
import com.google.common.collect.ImmutableCollection;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import java.util.LinkedHashMap;
import java.util.Map;
/**
* Created by tchemit on 28/08/17.
*
* @author Tony Chemit - [email protected]
*/
public class ImmutableClassMapping {
private final ImmutableMap, Class extends V>> mapping;
public static Builder builder() {
return new Builder<>();
}
public static class Builder {
private final Map, Class extends V>> mappingBuilder = new LinkedHashMap<>();
public Builder put(Class extends K> k, Class extends V> v) {
mappingBuilder.put(k, v);
return this;
}
public ImmutableClassMapping build() {
return new ImmutableClassMapping<>(getMappingBuilder());
}
public ImmutableMap, Class extends V>> getMappingBuilder() {
return ImmutableMap.copyOf(mappingBuilder);
}
}
public boolean containsKey(Class key) {
return mapping.containsKey(key);
}
@SuppressWarnings("unchecked")
public Class get(Class key) {
return (Class) mapping.get(key);
}
public ImmutableSet> keySet() {
return mapping.keySet();
}
public ImmutableCollection> values() {
return mapping.values();
}
public ImmutableMap, Class extends V>> getMapping() {
return mapping;
}
public int size() {
return mapping.size();
}
protected ImmutableClassMapping(ImmutableMap, Class extends V>> mapping) {
this.mapping = mapping;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy