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

com.proofpoint.tracetoken.TraceToken Maven / Gradle / Ivy

There is a newer version: 3.23
Show newest version
/*
 * Copyright 2016 Proofpoint, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.proofpoint.tracetoken;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import com.google.common.collect.ForwardingMap;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;

import java.util.Map;

import static java.util.Objects.requireNonNull;

public class TraceToken
    extends ForwardingMap
{
    private final Map delegate;

    TraceToken(Map map)
    {
        requireNonNull(map, "map is null");
        requireNonNull(map.get("id"), "map{id} is null");
        delegate = ImmutableMap.copyOf(map);
    }

    @JsonCreator
    static TraceToken createJson(Map map)
    {
        return new TraceToken(Maps.filterKeys(map, key -> !key.startsWith("_")));
    }

    @JsonValue
    Map getJson()
    {
        return Maps.filterKeys(this, key -> !key.startsWith("_"));
    }

    @Override
    protected Map delegate()
    {
        return delegate;
    }

    @Override
    public String toString()
    {
        if (delegate.size() == 1) {
            return delegate.get("id");
        }
        return super.toString();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy