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

org.snapscript.studio.agent.debug.ArrayScopeNode Maven / Gradle / Ivy

There is a newer version: 1.4.6
Show newest version
package org.snapscript.studio.agent.debug;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.List;

import org.snapscript.studio.agent.debug.ScopeNode;
import org.snapscript.studio.agent.debug.ScopeNodeBuilder;

public class ArrayScopeNode implements ScopeNode {
   
   private final ScopeNodeBuilder builder;
   private final List nodes;
   private final Object object;
   private final String alias;
   private final String name;
   private final String path;
   private final int depth;
   
   public ArrayScopeNode(ScopeNodeBuilder builder, Object object, String path, String name, String alias, int depth) {
      this.nodes = new ArrayList();
      this.builder = builder;
      this.object = object;
      this.depth = depth;
      this.alias = alias;
      this.path = path;
      this.name = name;
   }
   
   @Override
   public int getDepth() {
      return depth;
   }
   
   @Override
   public String getName() {
      return name;
   }
   
   @Override
   public String getAlias() {
      return alias;
   }   
   
   @Override
   public String getPath() {
      return path;
   }

   @Override
   public List getNodes() {
      if(nodes.isEmpty()) {
         int length = Array.getLength(object);
         
         if(length > 0) {
            for(int i = 0; i < length; i++) {
               try {
                  Object value = Array.get(object, i);
                  
                  if(value != null) {
                     String index =  "[" + i + "]";
                     ScopeNode node = builder.createNode(path + "." + index,  index, index, value, 0, depth);
                     
                     if(node != null) {
                        nodes.add(node);
                     }
                  }
               } catch(Exception e) {
                  e.printStackTrace();
               }
            }
         }
      }
      return nodes;
   }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy