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

org.deephacks.tools4j.config.internal.core.runtime.typesafe.impl.ConfigNull Maven / Gradle / Ivy

There is a newer version: 0.15.0
Show newest version
/**
 *   Copyright (C) 2011-2012 Typesafe Inc. 
 */
package org.deephacks.tools4j.config.internal.core.runtime.typesafe.impl;

import java.io.ObjectStreamException;
import java.io.Serializable;

import org.deephacks.tools4j.config.internal.core.runtime.typesafe.ConfigOrigin;
import org.deephacks.tools4j.config.internal.core.runtime.typesafe.ConfigRenderOptions;
import org.deephacks.tools4j.config.internal.core.runtime.typesafe.ConfigValueType;

/**
 * This exists because sometimes null is not the same as missing. Specifically,
 * if a value is set to null we can give a better error message (indicating
 * where it was set to null) in case someone asks for the value. Also, null
 * overrides values set "earlier" in the search path, while missing values do
 * not.
 *
 */
final class ConfigNull extends AbstractConfigValue implements Serializable {

    private static final long serialVersionUID = 2L;

    ConfigNull(ConfigOrigin origin) {
        super(origin);
    }

    @Override
    public ConfigValueType valueType() {
        return ConfigValueType.NULL;
    }

    @Override
    public Object unwrapped() {
        return null;
    }

    @Override
    String transformToString() {
        return "null";
    }

    @Override
    protected void render(StringBuilder sb, int indent, ConfigRenderOptions options) {
        sb.append("null");
    }

    @Override
    protected ConfigNull newCopy(ConfigOrigin origin) {
        return new ConfigNull(origin);
    }

    // serialization list goes through SerializedConfigValue
    private Object writeReplace() throws ObjectStreamException {
        return new SerializedConfigValue(this);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy