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

com.github.chaosfirebolt.converter.BiDirectionalMapRomanIntegerCache Maven / Gradle / Ivy

There is a newer version: 3.7.0
Show newest version
package com.github.chaosfirebolt.converter;

import com.github.chaosfirebolt.converter.api.cache.ParserCache;

import java.util.Map;
import java.util.function.Function;

/**
 * Caches result in both directions - arabic and roman representations are mapped to the same {@link RomanInteger} instance.
 *
 * @deprecated Deprecated in favour of {@link BiDirectionalRomanIntegerCache}
 */
@Deprecated(since = "3.3.0", forRemoval = true)
public class BiDirectionalMapRomanIntegerCache extends MapRomanIntegerCache {

  /**
   * Constructs an instance of Map based bidirectional roman integer cache
   *
   * @param parserCache parsers cache
   */
  public BiDirectionalMapRomanIntegerCache(ParserCache parserCache) {
    super(parserCache);
  }

  @Override
  protected RomanInteger cacheIfAbsent(Map cache, String key, Function computation) {
    RomanInteger cached = cache.get(key);
    if (cached != null) {
      return cached;
    }
    RomanInteger computed = computation.apply(key);
    cache.putIfAbsent(computed.getRoman(), computed);
    cache.putIfAbsent(Integer.toString(computed.getArabic()), computed);
    return computed;
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy