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

com.vladsch.flexmark.util.data.DataHolder Maven / Gradle / Ivy

There is a newer version: 4.15.102
Show newest version
package com.vladsch.flexmark.util.data;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.Collection;
import java.util.Map;

public interface DataHolder extends MutableDataSetter {
    DataHolder NULL = new DataSet();

    @NotNull Map, Object> getAll();
    @NotNull Collection> getKeys();

    boolean contains(@NotNull DataKeyBase key);

    /**
     * @param key data key
     * @param  Type returned by key
     * @return Use key.get(dataHolder) instead
     */
    @Deprecated
    @Nullable
    default  T get(@NotNull DataKey key) {
        return key.get(this);
    }

    @Override
    default @NotNull MutableDataHolder setIn(@NotNull MutableDataHolder dataHolder) {
        return dataHolder.setAll(this);
    }

    /**
     * Get key if it exists or compute using supplier
     * 

* Method used by DataKey classes to access data. *

* NOTE: MutableDataHolders will compute an absent key and add it to its dataSet. * DataHolders will return computed value but not change contained dataSet * because they are immutable. So value will be computed every time it is requested. * * @param key data key * @param factory factory taking this data holder and computing/providing default value * @return object value for the key */ Object getOrCompute(@NotNull DataKeyBase key, @NotNull DataValueFactory factory); @NotNull MutableDataHolder toMutable(); @NotNull DataHolder toImmutable(); @NotNull default DataSet toDataSet() { return this instanceof DataSet ? (DataSet) this : this instanceof MutableDataHolder ? new MutableDataSet(this) : new DataSet(this); } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy