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

com.contentful.java.cda.Cache Maven / Gradle / Ivy

There is a newer version: 9.1.0
Show newest version
package com.contentful.java.cda;

import java.util.List;
import java.util.Map;

class Cache {
  private List locales;

  protected CDALocale defaultLocale;

  private Map types;

  private final Object localesLock = new Object();

  private final Object typesLock = new Object();

  List locales() {
    return locales;
  }

  protected CDALocale defaultLocale() {
    return defaultLocale;
  }

  void setLocales(List locales) {
    synchronized (localesLock) {
      this.locales = locales;

      updateDefaultLocale();
    }
  }

  void updateDefaultLocale() {
    if (this.locales != null) {
      for (final CDALocale locale : this.locales) {
        if (locale.isDefaultLocale()) {
          this.defaultLocale = locale;
        }
      }
    }
  }

  Map types() {
    synchronized (typesLock) {
      return types;
    }
  }

  void setTypes(Map types) {
    synchronized (typesLock) {
      this.types = types;
    }
  }

  void clear() {
    synchronized (localesLock) {
      locales = null;
      defaultLocale = null;
    }

    synchronized (typesLock) {
      types = null;
    }
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy