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

io.github.mmm.marshall.impl.EnumMappings Maven / Gradle / Ivy

There is a newer version: 0.9.11
Show newest version
/* Copyright (c) The m-m-m Team, Licensed under the Apache License, Version 2.0
 * http://www.apache.org/licenses/LICENSE-2.0 */
package io.github.mmm.marshall.impl;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * Container for {@link EnumMapping}s. Supports thread-safe unmarshalling of any {@link Enum}.
 */
public class EnumMappings {

  private static final EnumMappings INSTANCE = new EnumMappings();

  private Map>, EnumMapping> mappings;

  /**
   * The constructor.
   */
  public EnumMappings() {

    super();
    this.mappings = new ConcurrentHashMap<>();
  }

  /**
   * @param  type of the {@link Enum}.
   * @param enumType the {@link Class} reflecting the {@link Enum}.
   * @return the requested {@link EnumMapping}.
   */
  @SuppressWarnings({ "rawtypes", "unchecked" })
  public > EnumMapping getMapping(Class enumType) {

    return (EnumMapping) this.mappings.computeIfAbsent(enumType, e -> new EnumMapping<>(enumType));
  }

  /**
   * @return the singleton instance of {@link EnumMappings}.
   */
  public static EnumMappings get() {

    return INSTANCE;
  }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy