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:net.daboross.bukkitdev.skywars.api.kits.impl.SkyKitItemConfig.java

@Override
public Map<Enchantment, Integer> getEnchantments() {
    return enchantments == null ? null : Collections.unmodifiableMap(enchantments);
}

From source file:com.clustercontrol.hub.util.CollectStringDataParser.java

public CollectStringDataParser(LogFormat format) {
    this.format = format;

    Pattern timestampPattern = null;
    try {//ww  w  .  ja  v a2  s . c  o  m
        timestampPattern = format.getTimestampRegex() == null ? null
                : Pattern.compile(format.getTimestampRegex());
    } catch (PatternSyntaxException e) {
        log.warn(String.format("invalid regex : ignored format.timestampRegex = %s",
                format.getTimestampRegex()));
    } finally {
        this.timestampPattern = timestampPattern;
    }

    DateTimeFormatter timestampFormatter = null;
    try {
        //??IllegalArgument??????null?????
        timestampFormatter = (format.getTimestampFormat() == null || format.getTimestampFormat().equals(""))
                ? null
                : DateTimeFormat.forPattern(format.getTimestampFormat()).withLocale(timestampLocale)
                        .withDefaultYear(0);
    } catch (IllegalArgumentException e) {
        log.warn(String.format("invalid format : ignored format.timestampFormat  = %s",
                format.getTimestampFormat()));
    } finally {
        this.timestampFormatter = timestampFormatter == null
                ? DateTimeFormat.forPattern("yyyy/MM/dd HH:mm:ss.SSS").withLocale(timestampLocale)
                        .withDefaultYear(0)
                : timestampFormatter;
    }

    Map<String, Pattern> keywordPatternMap = new TreeMap<String, Pattern>();
    for (LogFormatKey keyword : format.getKeyPatternList()) {
        try {
            Pattern keywordPattern = keyword.getPattern() == null ? null
                    : Pattern.compile(keyword.getPattern());
            keywordPatternMap.put(keyword.getKey(), keywordPattern);
        } catch (PatternSyntaxException e) {
            log.warn(String.format("invalid regex : ignored keyword.regex = %s", keyword.getPattern()));
        }
    }

    this.keywordPatternMap = Collections.unmodifiableMap(keywordPatternMap);
}

From source file:com.vmware.identity.saml.config.Config.java

/**
 *
 * Creates a new configuration//from   w ww  .jav a 2  s .c  o  m
 *
 * @param samlAuthorityConfig
 *           Saml authority configuration properties, required
 * @param tokenRestrictions
 *           token issuance configuration properties, required
 * @param validCerts
 *           not empty array of SAML authority certificates, required. No
 *           assumptions should be made for the order of the certificate
 *           chains. However, within certificate chains, the certificates are
 *           ordered from leaf to root CA. Entire chains can be kept even if
 *           some of them is no longer valid, because when certificate is
 *           checked if it is signed with a certificate among those chains,
 *           this certificate will be no longer valid itself. required
 * @param clockTolerance
 *           Maximum allowed clock skew between token sender and consumer, in
 *           milliseconds, required.
 * @param inExternalIdps a list of external idps registered.
 * @throws IllegalArgumentException
 *            when some of the arguments are invalid
 */
public Config(SamlAuthorityConfiguration samlAuthorityConfig, TokenRestrictions tokenRestrictions,
        Collection<List<Certificate>> validCerts, long clockTolerance, Collection<IDPConfig> inExternalIdps) {

    Validate.notNull(samlAuthorityConfig);
    Validate.notNull(tokenRestrictions);
    Validate.notEmpty(validCerts);

    List<Certificate> authorityCert = samlAuthorityConfig.getSigningCertificateChain();
    boolean authorityCertInValidCerts = false;

    for (List<Certificate> currentChain : validCerts) {
        Validate.notEmpty(currentChain);
        Validate.noNullElements(currentChain);
        if (!authorityCertInValidCerts && currentChain.equals(authorityCert)) {
            authorityCertInValidCerts = true;
        }
    }
    Validate.isTrue(authorityCertInValidCerts, "signing certificate chain is not in valid chains.");
    Validate.isTrue(clockTolerance >= 0);

    this.samlAuthorityConfig = samlAuthorityConfig;
    this.validCerts = validCerts;
    this.clockTolerance = clockTolerance;
    this.tokenRestrictions = tokenRestrictions;
    HashMap<String, IDPConfig> idpsSet = new HashMap<String, IDPConfig>();
    if (inExternalIdps != null) {
        for (IDPConfig conf : inExternalIdps) {
            if (conf != null) {
                idpsSet.put(conf.getEntityID(), conf);
            }
        }
    }
    this.externalIdps = Collections.unmodifiableMap(idpsSet);
}

From source file:com.monarchapis.driver.servlet.ApiRequest.java

/**
 * Returns the request headers are a convenient map.
 * //from w w  w  .  ja v  a2  s. com
 * @return The request headers as a map.
 */
public Map<String, List<String>> getHeaderMap() {
    if (this.headers == null) {
        Map<String, List<String>> headers = new LinkedHashMap<String, List<String>>();
        Enumeration<String> e = getHeaderNames();

        while (e.hasMoreElements()) {
            String headerName = e.nextElement();
            ArrayList<String> values = new ArrayList<String>();
            Enumeration<String> e2 = getHeaders(headerName);

            while (e2.hasMoreElements()) {
                values.add(e2.nextElement());
            }

            headers.put(headerName, values);
        }

        this.headers = Collections.unmodifiableMap(headers);
    }

    return this.headers;
}

From source file:info.magnolia.content2bean.TypeDescriptor.java

/**
 * This method is not synchronized to avoid thread blocking, but the method guarantees that the returned map is not mutated afterward.
 *///from w  ww .  j av  a 2  s.  co m
public Map<String, PropertyTypeDescriptor> getPropertyDescriptors(TypeMapping typeMapping) {
    //TODO ---- moved this out to TypeDescriptorFactory or something ?
    if (this.descriptors == null) {

        // for not making this method synchronized we create a local variable first
        // this guarantees that the map you get is not changed after return
        final Map<String, PropertyTypeDescriptor> tmpDescriptors = new HashMap<String, PropertyTypeDescriptor>();
        PropertyDescriptor[] dscrs = PropertyUtils.getPropertyDescriptors(this.getType());
        for (int i = 0; i < dscrs.length; i++) {
            PropertyDescriptor descriptor = dscrs[i];
            tmpDescriptors.put(descriptor.getName(),
                    typeMapping.getPropertyTypeDescriptor(this.getType(), descriptor.getName()));
        }

        this.descriptors = Collections.unmodifiableMap(tmpDescriptors);
    }
    return this.descriptors;
}

From source file:io.hops.erasure_coding.Codec.java

public static void initializeCodecs(Configuration conf) throws IOException {
    try {/*from ww w.  j a va2s .  co m*/
        String source = conf.get(DFSConfigKeys.ERASURE_CODING_CODECS_KEY);
        if (source == null) {
            codecs = Collections.emptyList();
            idToCodec = Collections.emptyMap();
            if (LOG.isDebugEnabled()) {
                LOG.info("No codec is specified");
            }
            return;
        }
        JSONArray jsonArray = new JSONArray(source);
        List<Codec> localCodecs = new ArrayList<>();
        Map<String, Codec> localIdToCodec = new HashMap<>();
        for (int i = 0; i < jsonArray.length(); ++i) {
            Codec codec = new Codec(jsonArray.getJSONObject(i));
            localIdToCodec.put(codec.id, codec);
            localCodecs.add(codec);
        }
        Collections.sort(localCodecs, new Comparator<Codec>() {
            @Override
            public int compare(Codec c1, Codec c2) {
                // Higher priority on top
                return c2.priority - c1.priority;
            }
        });
        codecs = Collections.unmodifiableList(localCodecs);
        idToCodec = Collections.unmodifiableMap(localIdToCodec);
    } catch (JSONException e) {
        throw new IOException(e);
    }
}

From source file:com.github.achatain.nopasswordauthentication.utils.FakeHttpServletRequest.java

public Map<String, String[]> getParameterMap() {
    return Collections
            .unmodifiableMap(Maps.transformValues(this.parameters.asMap(), STRING_COLLECTION_TO_ARRAY));
}

From source file:de.johni0702.minecraft.gui.container.AbstractGuiContainer.java

@Override
public Map<GuiElement, LayoutData> getElements() {
    return Collections.unmodifiableMap(elements);
}

From source file:com.scvngr.levelup.core.net.AbstractRequest.java

/**
 * Create a new {@link AbstractRequest}.
 * <p>/* w w  w  .j  a va 2  s.c o  m*/
 * Note that there are some representation invariants for the {@link AbstractRequest} object.
 * For example, a {@link HttpMethod#GET} cannot contain a {@code body}.
 *
 * @param method the {@code HttpMethod} of the request type.
 * @param url the URL to request (and to append query string parameters to).
 * @param requestHeaders the headers to add to the request. This cannot contain null keys or
 *        null values.
 * @param queryParams the query string parameters. This cannot contain null keys or null values.
 */
public AbstractRequest(@NonNull final HttpMethod method, @NonNull final String url,
        @Nullable final Map<String, String> requestHeaders, @Nullable final Map<String, String> queryParams) {

    PreconditionUtil.assertNotNull(method, "method");
    PreconditionUtil.assertNotNull(url, "url");

    if (null != requestHeaders) {
        mRequestHeaders = NullUtils
                .nonNullContract(Collections.unmodifiableMap(new HashMap<String, String>(requestHeaders)));
    } else {
        mRequestHeaders = NullUtils.nonNullContract(Collections.unmodifiableMap(new HashMap<String, String>()));
    }

    if (null != queryParams) {
        mQueryParams = NullUtils
                .nonNullContract(Collections.unmodifiableMap(new HashMap<String, String>(queryParams)));
    } else {
        mQueryParams = NullUtils.nonNullContract(Collections.unmodifiableMap(new HashMap<String, String>()));
    }

    mUrlString = url;
    mMethod = method;

    checkRep();
}

From source file:lshw.types.Capabilities.java

/**
 * Returns the capabilities as an unmodifiable {@link Map} where the key is the capability id and the value is the capability value.
 * //from   w  w w . ja v  a 2 s  .com
 * @return the capabilities as an unmodifiable {@link Map} where the key is the capability id and the value is the capability value.
 */
public Map<String, String> getCapabilitiesMap() {
    Map<String, String> capabilities = new HashMap<>();

    for (Capability capability : this.getCapabilities()) {
        capabilities.put(capability.getId(), capability.getValue());
    }
    return Collections.unmodifiableMap(capabilities);
}