Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package com.fasterxml.jackson.databind;
  
Simple value class used for containing names of properties as defined by annotations (and possibly other configuration sources).

Since:
2.1
 
 public class PropertyName
     implements java.io.Serializable
 {
     private static final long serialVersionUID = 7930806520033045126L;
 
     private final static String _USE_DEFAULT = "";
     private final static String _NO_NAME = "";

    
Special placeholder value that indicates that name to use should be based on the standard heuristics. This can be different from returning null, as null means "no information available, whereas this value indicates explicit defaulting.
 
     public final static PropertyName USE_DEFAULT = new PropertyName(null);

    
Special placeholder value that indicates that there is no name associated. Exact semantics to use (if any) depend on actual annotation in use, but commonly this value disables behavior for which name would be needed.
 
     public final static PropertyName NO_NAME = new PropertyName(new String(), null);
    
    
Basic name of the property.
 
     protected final String _simpleName;

    
Additional namespace, for formats that have such concept (JSON does not, XML does, for example).
 
     protected final String _namespace;
 
     public PropertyName(String simpleName) {
         this(simpleNamenull);
     }
 
     public PropertyName(String simpleNameString namespace)
     {
          = (simpleName == null) ? "" : simpleName;
          = namespace;
     }
 
     // To support JDK serialization, recovery of Singleton instance
     protected Object readResolve() {
         if ( == null || .equals()) {
             return ;
         }
         if (.equals() &&  == null) {
             return ;
         }
         return this;
     }
     
     public static PropertyName construct(String simpleNameString ns)
     {
         if (simpleName == null) {
             simpleName = "";
         }
         if (ns == null && simpleName.length() == 0) {
             return ;
         }
         return new PropertyName(simpleNamens);
     }
 
     public PropertyName internSimpleName()
     {
         if (.length() == 0) { // empty String is canonical already
             return this;
         }
         String interned = ..intern();
         if (interned == ) { // was already interned
             return this;
         }
         return new PropertyName(interned);
     }

    
    
Fluent factory method for constructing an instance with different simple name.
 
     public PropertyName withSimpleName(String simpleName)
     {
         if (simpleName == null) {
             simpleName = "";
         }
         if (simpleName.equals()) {
            return this;
        }
        return new PropertyName(simpleName);
    }
    
    
Fluent factory method for constructing an instance with different namespace.
    public PropertyName withNamespace(String ns) {
        if (ns == null) {
            if ( == null) {
                return this;
            }
        } else if (ns.equals()) {
            return this;
        }
        return new PropertyName(ns);
    }
    
    /*
    /**********************************************************
    /* Accessors
    /**********************************************************
     */
    
    public String getSimpleName() {
        return ;
    }
    public String getNamespace() {
        return ;
    }
    public boolean hasSimpleName() {
        return .length() > 0;
    }

    

Since:
2.3
    public boolean hasSimpleName(String str) {
        if (str == null) {
            return  == null;
        }
        return str.equals();
    }
    
    public boolean hasNamespace() {
        return  != null;
    }
    
    /*
    /**********************************************************
    /* Std method overrides
    /**********************************************************
     */
    @Override
    public boolean equals(Object o)
    {
        if (o == thisreturn true;
        if (o == nullreturn false;
        /* 13-Nov-2012, tatu: by default, require strict type equality.
         *   Re-evaluate if this becomes an issue.
         */
        if (o.getClass() != getClass()) return false;
        // 13-Nov-2012, tatu: Should we have specific rules on matching USE_DEFAULT?
        //   (like, it only ever matching exact instance)
        //   If we did, would need to check symmetrically; that is, if either 'this'
        //   or 'o' was USE_DEFAULT, both would have to be.
        PropertyName other = (PropertyNameo;
        if ( == null) {
            if (other._simpleName != nullreturn false;
        } else if (!.equals(other._simpleName)) {
            return false;
        }
        if ( == null) {
            return (null == other._namespace);
        }
        return .equals(other._namespace);
    }
    
    @Override
    public int hashCode() {
        if ( == null) {
            return .hashCode();
        }
        return .hashCode() ^  .hashCode();
    }
    
    @Override
    public String toString() {
        if ( == null) {
            return ;
        }
        return "{"+ + "}" + ;
    }
New to GrepCode? Check out our FAQ X