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

com.wise.common.environment.CachingWiseActiveProfilesProvider Maven / Gradle / Ivy

The newest version!
package com.wise.common.environment;

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

public class CachingWiseActiveProfilesProvider implements WiseActiveProfilesProvider {

  private final List activeProfiles;

  private Map isActiveCache = new ConcurrentHashMap<>();

  public CachingWiseActiveProfilesProvider(List activeProfiles) {
    this.activeProfiles = activeProfiles;
  }

  @Override
  public List getActiveProfiles() {
    return activeProfiles;
  }

  @Override
  public boolean isProfileActive(WiseProfile profile) {
    return isActiveCache.computeIfAbsent(profile, k -> {
      var activeProfiles = getActiveProfiles();

      for (var activeProfile : activeProfiles) {
        while (activeProfile != null) {
          if (activeProfile == profile) {
            return true;
          }
          activeProfile = activeProfile.parent();
        }
      }

      return false;
    });
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy