Class Context

java.lang.Object
org.apache.jena.sparql.util.Context
Direct Known Subclasses:
JsonLDReadContext, JsonLDWriteContext

public class Context extends Object
A class for setting and keeping named values. Used to pass implementation-specific parameters across general interfaces.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Create an empty context
    Create a context and initialize it with a copy of the named values of another one.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
     
    Return a copy of this context.
    static Context
    Create an empty context
    static final Context
    Empty, immutable context
    boolean
     
    static Context
    Return the context of the dataset (not copied); if the dataset is null, return null
    <T> T
    get(Symbol property)
    Get the object value of a property or null
    <T> T
    get(Symbol property, T defaultValue)
    Get the object value of a property - return the default value if not present .
    getAsString(Symbol property)
    Get the value a string (uses .toString() if the value is not null)
    getAsString(Symbol property, String defaultValue)
    Get the value a string (uses .toString() if the value is not null) - supply a default string value
    int
    getInt(Symbol symbol, int defaultValue)
    Get the value as a long value.
    long
    getLong(Symbol symbol, long defaultValue)
    Get the value as a long value.
    int
     
    boolean
    hasValue(Symbol property, Object value)
    Test whether a named value is a specific value (.equals)
    boolean
    hasValueAsString(Symbol property, String value)
    Test whether a named value (as a string) has a specific string form
    boolean
    hasValueAsString(Symbol property, String value, boolean ignoreCase)
    Test whether a named value (as a string) has a specific string form - can ignore case
    boolean
    isDefined(Symbol property)
    Is a property set?
    boolean
    isFalse(Symbol property)
    Is the value 'false' (either set to the string "false" or Boolean.FALSE)
    boolean
    Is the value 'false' (either set to the string "false" or Boolean.FALSE) or undefined
    boolean
    isTrue(Symbol property)
    Is the value 'true' (either set to the string "true" or Boolean.TRUE)
    boolean
    Is the value 'true' (either set to the string "true" or Boolean.TRUE) or undefined?
    boolean
    isUndef(Symbol property)
    Is a property not set?
    Set of properties (as Symbols) currently defined
    static Context
    mergeCopy(Context contextGlobal, Context contextLocal)
    Merge an outer (defaults to the system global context) and local context to produce a new context The new context is always a separate copy.
    void
    put(Symbol property, Object value)
    Store a named value - overwrites any previous set value
    void
    putAll(Context other)
     
    void
    remove(Symbol property)
    Remove any value associated with a property
    set(Symbol property, boolean value)
    Store a named value - overwrites any previous set value.
    set(Symbol property, Object value)
    Store a named value - overwrites any previous set value.
    static void
     
    setFalse(Symbol property)
    Set property value to be false.
    setIfUndef(Symbol property, Object value)
    Store a named value only if it is not currently set.
    setTrue(Symbol property)
    Set property value to be true.
    static Context
    setupContextForDataset(Context globalContext, DatasetGraph dataset)
    Setup a context using another context and a dataset.
    int
    Return the number of context items
     
    void
    unset(Symbol property)
    Remove any value associated with a property - alternative method name

    Methods inherited from class java.lang.Object

    getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • Context

      public Context()
      Create an empty context
    • Context

      public Context(Context cxt)
      Create a context and initialize it with a copy of the named values of another one. Shallow copy: the values themselves are not copied
  • Method Details

    • emptyContext

      public static final Context emptyContext()
      Empty, immutable context
    • create

      public static Context create()
      Create an empty context
    • copy

      public Context copy()
      Return a copy of this context. Modifications of the copy do not affect the original context.
    • get

      public <T> T get(Symbol property)
      Get the object value of a property or null
    • get

      public <T> T get(Symbol property, T defaultValue)
      Get the object value of a property - return the default value if not present .
    • put

      public void put(Symbol property, Object value)
      Store a named value - overwrites any previous set value
    • set

      public Context set(Symbol property, Object value)
      Store a named value - overwrites any previous set value. Returns "this".
    • set

      public Context set(Symbol property, boolean value)
      Store a named value - overwrites any previous set value. Returns "this".
    • setIfUndef

      public Context setIfUndef(Symbol property, Object value)
      Store a named value only if it is not currently set. Returns "this".
    • setTrue

      public Context setTrue(Symbol property)
      Set property value to be true. Returns "this".
    • setFalse

      public Context setFalse(Symbol property)
      Set property value to be false. Returns "this".
    • putAll

      public void putAll(Context other)
    • remove

      public void remove(Symbol property)
      Remove any value associated with a property
    • unset

      public void unset(Symbol property)
      Remove any value associated with a property - alternative method name
    • isDefined

      public boolean isDefined(Symbol property)
      Is a property set?
    • isUndef

      public boolean isUndef(Symbol property)
      Is a property not set?
    • getAsString

      public String getAsString(Symbol property, String defaultValue)
      Get the value a string (uses .toString() if the value is not null) - supply a default string value
    • getAsString

      public String getAsString(Symbol property)
      Get the value a string (uses .toString() if the value is not null)
    • getInt

      public int getInt(Symbol symbol, int defaultValue)
      Get the value as a long value. The context entry can be a string, Integer or Long.
    • getLong

      public long getLong(Symbol symbol, long defaultValue)
      Get the value as a long value. The context entry can be a string, Integer or Long.
    • isTrue

      public boolean isTrue(Symbol property)
      Is the value 'true' (either set to the string "true" or Boolean.TRUE)
    • isTrueOrUndef

      public boolean isTrueOrUndef(Symbol property)
      Is the value 'true' (either set to the string "true" or Boolean.TRUE) or undefined?
    • isFalse

      public boolean isFalse(Symbol property)
      Is the value 'false' (either set to the string "false" or Boolean.FALSE)
    • isFalseOrUndef

      public boolean isFalseOrUndef(Symbol property)
      Is the value 'false' (either set to the string "false" or Boolean.FALSE) or undefined
    • hasValue

      public boolean hasValue(Symbol property, Object value)
      Test whether a named value is a specific value (.equals)
    • hasValueAsString

      public boolean hasValueAsString(Symbol property, String value)
      Test whether a named value (as a string) has a specific string form
    • hasValueAsString

      public boolean hasValueAsString(Symbol property, String value, boolean ignoreCase)
      Test whether a named value (as a string) has a specific string form - can ignore case
    • keys

      public Set<Symbol> keys()
      Set of properties (as Symbols) currently defined
    • size

      public int size()
      Return the number of context items
    • clear

      public void clear()
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • fromDataset

      public static Context fromDataset(DatasetGraph dataset)
      Return the context of the dataset (not copied); if the dataset is null, return null
    • setupContextForDataset

      public static Context setupContextForDataset(Context globalContext, DatasetGraph dataset)
      Setup a context using another context and a dataset.
    • setCurrentDateTime

      public static void setCurrentDateTime(Context context)
    • mergeCopy

      public static Context mergeCopy(Context contextGlobal, Context contextLocal)
      Merge an outer (defaults to the system global context) and local context to produce a new context The new context is always a separate copy.
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object