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

org.snapscript.platform.InvocationCacheArray Maven / Gradle / Ivy

There is a newer version: 1.4.6
Show newest version
package org.snapscript.platform;

import java.util.concurrent.atomic.AtomicReferenceArray;

public class InvocationCacheArray {
   
   private final AtomicReferenceArray array;
   private final int capacity;
   private final int expand;
   
   public InvocationCacheArray(int capacity, int expand) {
      this.array = new AtomicReferenceArray(capacity);
      this.capacity = capacity;
      this.expand = expand;
   }
   
   public InvocationCacheArray copy(int require) {
      int length = array.length();
      
      if(require >= length) {
         InvocationCacheArray copy = new InvocationCacheArray(require + expand, expand);
         
         for(int i = 0; i < length; i++) {
            InvocationCache cache = array.get(i);
            copy.set(i, cache);
         }
         return copy;
      }
      return this;
   }
   
   public InvocationCache get(int index) {
      return array.get(index);
   }
   
   public void set(int index, InvocationCache cache) {
      array.set(index, cache);
   }

   public int length(){
      return capacity;
   }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy