Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright (c) 2012, Francis Galiegue <fgaliegue@gmail.com>
   *
   * This program is free software: you can redistribute it and/or modify
   * it under the terms of the Lesser GNU General Public License as
   * published by the Free Software Foundation, either version 3 of the
   * License, or (at your option) any later version.
   *
   * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * Lesser GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
 package com.github.fge.jsonschema.ref;
 
Abstract class for fragment resolution

In a JSON Reference, a fragment can only be a JSON Pointer. All other fragments are illegal.

The only possibility for a non JSON Pointer fragment to appear is when inline addressing mode is used.

 
 public abstract class JsonFragment
     implements Comparable<JsonFragment>
 {
    
Special case fragment (empty)
 
     private static final JsonFragment EMPTY = new JsonFragment("")
     {
         @Override
         public JsonNode resolve(final JsonNode node)
         {
             return node;
         }
     };

    
This fragment as a string value
 
     protected final String asString;

    
Constructor

Parameters:
input the input fragment
 
     protected JsonFragment(final String input)
     {
          = input;
     }

    
The only static factory method to obtain a fragment

Depending on the situation, this method will either return a JsonPointer, an IllegalFragment or EMPTY.

Parameters:
fragment the fragment as a string
Returns:
the fragment
 
     public static JsonFragment fromFragment(final String fragment)
     {
         if (fragment.isEmpty())
             return ;
 
         try {
             return new JsonPointer(fragment);
         } catch (JsonSchemaException ignored) {
             // Not a valid JSON Pointer: illegal
             return new IllegalFragment(fragment);
         }
     }

    
Resolve this fragment against a given node

Parameters:
node the node
Returns:
the result node (com.fasterxml.jackson.databind.node.MissingNode if the fragment is not found)
 
     public abstract JsonNode resolve(final JsonNode node);

    
Tell whether this fragment is empty

Returns:
true if this fragment is (reference wise) equal to EMPTY
See also:
JsonRef.isAbsolute()
    public final boolean isEmpty()
    {
        // This works: we always return EMPTY with a null fragment
        return this == ;
    }
    @Override
    public final int compareTo(final JsonFragment o)
    {
        return .compareTo(o.asString);
    }
    @Override
    public final int hashCode()
    {
        return .hashCode();
    }
    @Override
    public final boolean equals(final Object obj)
    {
        if (obj == null)
            return false;
        if (this == obj)
            return true;
        if (!(obj instanceof JsonFragment))
            return false;
        final JsonFragment other = (JsonFragmentobj;
        return .equals(other.asString);
    }
    @Override
    public final String toString()
    {
        return ;
    }
New to GrepCode? Check out our FAQ X