All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.infinispan.commons.util.ByRef Maven / Gradle / Ivy

There is a newer version: 15.1.0.Dev04
Show newest version
package org.infinispan.commons.util;

/**
 * This class can be used to pass an argument by reference.
 * @param  The wrapped type.
 *
 * @author Dan Berindei
 * @since 5.1
 */
public class ByRef {
   private T ref;

   public ByRef(T t) {
      ref = t;
   }

   public static  ByRef create(T t) {
      return new ByRef(t);
   }

   public T get() {
      return ref;
   }

   public void set(T t) {
      ref = t;
   }

   /**
    * Implementation for primitive type
    */
   public static class Boolean {
      boolean ref;

      public Boolean(boolean b) {
         ref = b;
      }

      public boolean get() {
         return ref;
      }

      public void set(boolean b) {
         this.ref = b;
      }
   }

   public static class Integer {
      int ref;

      public Integer(int i) {
         ref = i;
      }

      public int get() {
         return ref;
      }

      public void set(int i) {
         ref = i;
      }

      public void inc() {
         ref++;
      }

      public void dec() {
         ref--;
      }
   }

   public static class Long {
      long ref;

      public Long(long i) {
         ref = i;
      }

      public long get() {
         return ref;
      }

      public void set(long i) {
         ref = i;
      }

      public long getAndAdd(long i) {
         long ret = ref;
         ref += i;
         return ret;
      }

      public void inc() {
         ref++;
      }

      public void dec() {
         ref--;
      }
   }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy