JavaScript is disabled on your browser.
javolution.context

Class LocalContext



  • public abstract class LocalContext
    extends AbstractContext 

    A context holding locally scoped parameters values.

    For example, when performing modulo arithmetics the actual modulo being used is usually the same for most operations and does not need to be specified for each operation.

     import javolution.context.LocalContext.Parameter;
     public class ModuloInteger extends Number {
     public static final Parameter<Integer> MODULO = new Parameter<Integer>() {
     protected Integer getDefault() { return -1; }
     }; 
     public ModuloInteger times(ModuloInteger that) { ... } 
     } 
     LocalContext ctx = LocalContext.enter(); 
     try {
     ctx.supersede(ModuloInteger.MODULO, 13); // Sets local modulo value.
     x = a.times(b).plus(c.times(d)); // Operations modulo 13
     ...
     } finally {
     ctx.exit(); // Reverts to previous modulo setting. 
     }

    As for any context, local context settings are inherited during ConcurrentContext executions.

    Version:
    6.0 December 12, 2012
    Author:
    Jean-Marie Dautelle
    • Constructor Detail

      • LocalContext

        protected LocalContext()
        Default constructor.
    • Method Detail

      • enter

        public static LocalContext enter()
        Enters and returns a new local context instance.
      • supersede

        public abstract <T> void supersede(LocalContext.Parameter<T> param,
         T localValue)
        Supersedes the value of the specified parameter.
        Parameters:
        param - the local parameter whose local value is overridden.
        localValue - the new local value.
        Throws:
        SecurityException - if the permission to override the specified parameter is not granted.
        NullPointerException - if the specified local value is null.
      • getValue

        protected abstract <T> T getValue(LocalContext.Parameter<T> param,
         T defaultValue)
        Returns the local value of the specified parameter or the specified default value if not superseded.
        Parameters:
        param - the local parameter whose local value is returned.
        defaultValue - the parameter value if not superseded.

Copyright © 2005-2013 Javolution. All Rights Reserved.

AltStyle によって変換されたページ (->オリジナル) /