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

io.polyglotted.pgmodel.ac.Environment Maven / Gradle / Ivy

Go to download

Standard set of models for geo coding, access control and elastic search abstraction

There is a newer version: 1.4.1
Show newest version
package io.polyglotted.pgmodel.ac;

import com.google.common.collect.ImmutableMap;
import lombok.RequiredArgsConstructor;
import lombok.ToString;

import java.time.Clock;
import java.util.Map;
import java.util.Objects;

import static com.google.common.base.Preconditions.checkNotNull;
import static io.polyglotted.pgmodel.util.ModelUtil.jsonEquals;
import static io.polyglotted.pgmodel.util.MapRetriever.deepRetrieve;

@ToString(includeFieldNames = false)
@RequiredArgsConstructor
public final class Environment {
    public final ImmutableMap properties;

    public final int apiRef() {
        return checkNotNull((Integer) property("API_REF"));
    }

    public final String resource() {
        return checkNotNull(property("RESOURCE"));
    }

    public final  T property(String path) {
        return deepRetrieve(properties, path);
    }

    @Override
    public boolean equals(Object o) {
        return jsonEquals(this, o);
    }

    @Override
    public int hashCode() {
        return Objects.hash(properties);
    }

    public static Environment from(Map map, Clock clock) {
        return new Environment(ImmutableMap.builder().putAll(map).put("TIMESTAMP", clock.millis()).build());
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy