Example usage for java.util Collections unmodifiableMap

List of usage examples for java.util Collections unmodifiableMap

Introduction

In this page you can find the example usage for java.util Collections unmodifiableMap.

Prototype

public static <K, V> Map<K, V> unmodifiableMap(Map<? extends K, ? extends V> m) 

Source Link

Document

Returns an unmodifiable view of the specified map.

Usage

From source file:Main.java

/**
 * Creates an unmodifiable shallow copy of the given original {@link Map}. <p> While the copy returns an immutable
 * copy of the {@link Map} the content is not cloned in any way. Unless the content is immutable by itself the
 * result is not fully immutable. In the shallow copy all references are the same as in the original {@link Map}!
 * </p>/*  w  ww.j a  v a2 s  . c  o m*/
 *
 * @param original The {@link Map} to copy the elements fro.
 * @param <K>      The type of the key
 * @param <V>      The type of the value
 *
 * @return Returns an immutable (unmodifiable) copy of the original {@link Map} with all the elements added but not
 * cloned!
 */
public static <K, V> Map<K, V> createUnmodifiableShallowCopy(final Map<K, V> original) {
    if (original == null || original.isEmpty()) {
        return Collections.emptyMap();
    } else {
        return Collections.unmodifiableMap(new HashMap<K, V>(original));
    }
}

From source file:de.huberlin.wbi.cfjava.data.Amap.java

public Amap(K key, V value) {

    Map<K, V> m;/*from w ww  .ja va2s  .c  o  m*/

    if (key == null)
        throw new IllegalArgumentException("Key term must not be null.");

    if (value == null)
        throw new IllegalArgumentException("Value term must not be null.");

    m = new HashMap<>();
    m.put(key, value);

    content = Collections.unmodifiableMap(m);
}

From source file:com.imhasan.beingjava.test.ImageController.java

public Map<String, List<ImgEntry>> createHwAddressToImgEntriesMap(String directory) throws ParseException {
    for (File f : getFilesFromDirectory(directory)) {
        ImgEntry imgEntry = getObjFromFilePath(f);
        if (imageMap.keySet().contains(imgEntry.getHwAddress())) {
            imageMap.get(imgEntry.hwAddress).add(imgEntry);
        } else {//from ww w.java 2s .  co m
            List<ImgEntry> entrys = new ArrayList<>();
            entrys.add(imgEntry);
            imageMap.put(imgEntry.getHwAddress(), entrys);
        }
    }
    return Collections.unmodifiableMap(imageMap);
}

From source file:net.openid.appauth.AdditionalParamsProcessor.java

static Map<String, String> checkAdditionalParams(@Nullable Map<String, String> params,
        @NonNull Set<String> builtInParams) {
    if (params == null) {
        return Collections.emptyMap();
    }/*from   ww  w .  ja v  a2  s.  co  m*/

    Map<String, String> additionalParams = new LinkedHashMap<>();
    for (Map.Entry<String, String> entry : params.entrySet()) {
        String key = entry.getKey();
        String value = entry.getValue();
        checkNotNull(key, "additional parameter keys cannot be null");
        checkNotNull(value, "additional parameter values cannot be null");

        checkArgument(!builtInParams.contains(key),
                "Parameter %s is directly supported via the authorization request builder, "
                        + "use the builder method instead",
                key);
        additionalParams.put(key, value);
    }

    return Collections.unmodifiableMap(additionalParams);
}

From source file:com.skcraft.launcher.creator.util.NemModList.java

public void load(String version) throws IOException, InterruptedException {
    checkNotNull(version, "version");

    List<ModEntry> mods = HttpRequest.get(HttpRequest.url("https://bot.notenoughmods.com/" + version + ".json"))
            .execute().expectResponseCode(200).returnContent().asJson(new TypeReference<List<ModEntry>>() {
            });//  www.j ava  2  s  . c  om

    Map<String, ModEntry> index = Maps.newHashMap();

    for (ModEntry entry : mods) {
        index.put(entry.getModId(), entry);
    }

    this.mods = Collections.unmodifiableMap(index);
}

From source file:io.cloudslang.lang.runtime.env.Context.java

public Map<String, Value> getImmutableViewOfLanguageVariables() {
    return Collections.unmodifiableMap(langVariables);
}

From source file:org.cloudfoundry.identity.uaa.authentication.AuthzAuthenticationRequest.java

public AuthzAuthenticationRequest(Map<String, String> info, UaaAuthenticationDetails details) {
    this.info = Collections.unmodifiableMap(info);
    Assert.notNull(details);//  w  w  w.  j  a v  a 2 s . c  o  m
    this.details = details;
}

From source file:com.precioustech.fxtrading.instrument.InstrumentService.java

public InstrumentService(InstrumentDataProvider<T> instrumentDataProvider) {
    Preconditions.checkNotNull(instrumentDataProvider);
    Collection<TradeableInstrument<T>> instruments = instrumentDataProvider.getInstruments();
    Map<String, TradeableInstrument<T>> tradeableInstrumenMap = Maps.newTreeMap();
    for (TradeableInstrument<T> instrument : instruments) {
        tradeableInstrumenMap.put(instrument.getInstrument(), instrument);
    }// w ww. j  a v a 2 s .c  o  m
    this.instrumentMap = Collections.unmodifiableMap(tradeableInstrumenMap);
}

From source file:am.ik.categolj2.infra.codelist.EnumCodeList.java

@Override
public Map<String, String> asMap() {
    Map<String, String> codeList = new LinkedHashMap<String, String>();
    Method method = ReflectionUtils.findMethod(enumClass, "values");

    Enum<?>[] result = (Enum<?>[]) ReflectionUtils.invokeMethod(method, enumClass);
    for (Enum<?> e : result) {
        CodeListItem item = (CodeListItem) e;
        codeList.put(item.getCodeValue(), item.getCodeLabel());
    }//  ww  w.  java 2 s .co  m

    return Collections.unmodifiableMap(codeList);
}