Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package com.fasterxml.jackson.databind;

Simple container class used for storing "additional" metadata about properties. Carved out to reduce number of distinct properties that actual property implementations and placeholders need to store; since this instances are immutable, they can be freely shared.

Since:
2.3
public class PropertyMetadata
    implements java.io.Serializable
    private static final long serialVersionUID = -1;
    public final static PropertyMetadata STD_REQUIRED = new PropertyMetadata(.null);
    public final static PropertyMetadata STD_OPTIONAL = new PropertyMetadata(.null);
    public final static PropertyMetadata STD_REQUIRED_OR_OPTIONAL = new PropertyMetadata(nullnull);
    
    
Three states: required, not required and unknown; unknown represented as null.
    protected final Boolean _required;

    
Optional human-readable description associated with the property.
    protected final String _description;
    /*
    /**********************************************************
    /* Construction, configuration
    /**********************************************************
     */
    
    protected PropertyMetadata(Boolean reqString desc)
    {
         = req;
         = desc;
    }
    public static PropertyMetadata construct(boolean reqString desc) {
        PropertyMetadata md = req ?  : ;
        if (desc != null) {
            return md.withDescription(desc);
        }
        return md;
    }
    
    
Minor optimization: let's canonicalize back to placeholders in cases where there is no real data to consider
    protected Object readResolve()
    {
        if ( == null) {
            if ( == null) {
                return ;
            }
            return .booleanValue() ?  : ;
        }
        return this;
    }
    public PropertyMetadata withDescription(String desc) {
        return new PropertyMetadata(desc);
    }
    public PropertyMetadata withRequired(Boolean b) {
        if (b == null) {
            if ( == null) {
                return this;
            }
        } else {
            if ( != null && .booleanValue() == b.booleanValue()) {
                return this;
            }
        }
        return new PropertyMetadata(b);
    }
    
    /*
    /**********************************************************
    /* Accessors
    /**********************************************************
     */
    public String getDescription() { return ; }
    public boolean isRequired() { return ( != null) && .booleanValue(); }
    
    public Boolean getRequired() { return ; }
New to GrepCode? Check out our FAQ X