com.fitbur.fasterxml.jackson.databind.node.BooleanNode Maven / Gradle / Ivy
package com.fitbur.fasterxml.jackson.databind.node;
import java.io.IOException;
import com.fitbur.fasterxml.jackson.core.*;
import com.fitbur.fasterxml.jackson.databind.SerializerProvider;
/**
* This concrete value class is used to contain boolean (true / false)
* values. Only two instances are ever created, to minimize memory
* usage
*/
public final class BooleanNode
extends ValueNode
{
// // Just need two instances...
public final static BooleanNode TRUE = new BooleanNode();
public final static BooleanNode FALSE = new BooleanNode();
private BooleanNode() { }
public static BooleanNode getTrue() { return TRUE; }
public static BooleanNode getFalse() { return FALSE; }
public static BooleanNode valueOf(boolean b) { return b ? TRUE : FALSE; }
// Interesting... two choices...
@Override public JsonToken asToken() {
return (this == TRUE) ? JsonToken.VALUE_TRUE : JsonToken.VALUE_FALSE;
}
@Override
public boolean isBoolean() { return true; }
@Override
public boolean booleanValue() {
return (this == TRUE);
}
@Override
public String asText() {
return (this == TRUE) ? "true" : "false";
}
@Override
public boolean asBoolean() {
return (this == TRUE);
}
@Override
public boolean asBoolean(boolean com.fitburfaultValue) {
return (this == TRUE);
}
@Override
public int asInt(int com.fitburfaultValue) {
return (this == TRUE) ? 1 : 0;
}
@Override
public long asLong(long com.fitburfaultValue) {
return (this == TRUE) ? 1L : 0L;
}
@Override
public double asDouble(double com.fitburfaultValue) {
return (this == TRUE) ? 1.0 : 0.0;
}
@Override
public final void serialize(JsonGenerator jg, SerializerProvider provider)
throws IOException, JsonProcessingException
{
jg.writeBoolean(this == TRUE);
}
@Override
public boolean equals(Object o)
{
/* Since there are only ever two instances in existence
* can do identity com.fitburparison
*/
return (o == this);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy