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

com.intellij.openapi.util.KeyWithDefaultValue Maven / Gradle / Ivy

// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.openapi.util;

import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;

import java.util.function.Supplier;

public abstract class KeyWithDefaultValue extends Key {
  public KeyWithDefaultValue(@NotNull @NonNls String name) {
    super(name);
  }

  public abstract T getDefaultValue();

  public static @NotNull  KeyWithDefaultValue create(@NotNull @NonNls String name, T defValue) {
    return new KeyWithDefaultValue<>(name) {
      @Override
      public T getDefaultValue() {
        return defValue;
      }
    };
  }

  public static @NotNull  KeyWithDefaultValue create(@NotNull @NonNls String name, @NotNull Supplier factory) {
    return new KeyWithDefaultValue<>(name) {
      @Override
      public T getDefaultValue() {
        return factory.get();
      }
    };
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy