Advertisement
Guest User

Untitled

a guest
Apr 1st, 2015
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.77 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package vds.jfx.window;
  7.  
  8.  
  9. import java.lang.reflect.Field;
  10. import java.lang.reflect.Method;
  11. import java.util.ArrayList;
  12.  
  13. import java.util.logging.Level;
  14. import java.util.logging.Logger;
  15. import vds.jfx.code.VDSList;
  16. import vds.jfx.code.VNode;
  17.  
  18. /**
  19.  *
  20.  * @author Alexandros Delas
  21.  * @param <T>
  22.  */
  23. public class Transformer<T extends VDSList> {
  24.    
  25.     private VDSList tlist;
  26.     private VNode first;
  27.     private VNode last;
  28.     private VNode prev;
  29.     private VNode next;
  30.     private VNode temp;
  31.  
  32.      ArrayList<VNode> list = new ArrayList<VNode>();
  33.  
  34.  
  35.     public Transformer(T tlist) {
  36.        
  37.         this.tlist = tlist;      
  38.         System.out.println(tlist.getClass().getName());
  39.         Field f = null;
  40.        
  41.         /
  42.         try {
  43.            
  44.             //was eigentlich fehlt: unnötigen Anhang entfernen
  45.             //ODER Verknüpfungen mit prev, next und payload selber erstellen
  46.             //eigene Funktion statt Wiederholung
  47.             //first element
  48.             f = tlist.getClass().getDeclaredField("first"); //NoSuchFieldException
  49.             f.setAccessible(true);
  50.             if (f.get(tlist) != null) {
  51.                 first = (VNode) f.get(tlist); //IllegalAccessException
  52.                 list.add(first);
  53.                 System.out.println(first);
  54.                
  55.             }
  56.            
  57.             //second element
  58.             f = first.getClass().getDeclaredField("next"); //NoSuchFieldException
  59.             f.setAccessible(true);
  60.             if (f.get(first) != null) {
  61.                 next = (VNode) f.get(first); //IllegalAccessException
  62.                 list.add(next);
  63.                 System.out.println(next);
  64.             }
  65.            
  66.             //more elements
  67.             while (f.get(next) != null) {
  68.                 f = next.getClass().getDeclaredField("next"); //NoSuchFieldException
  69.                 f.setAccessible(true);
  70.                 next = (VNode) f.get(next); //IllegalAccessException
  71.                 list.add(next);
  72.                 System.out.println(next);        
  73.             }
  74.             //was eigentlich fehlt: unnötigen Anhang entfernen
  75.             //ODER Verknüpfungen mit prev, next und payload selber erstellen
  76.             //eigene Funktion statt Wiederholung
  77.         } catch (IllegalAccessException | NoSuchFieldException | SecurityException ex) {
  78.             Logger.getLogger(VDSList.class.getName()).log(Level.SEVERE, null, ex);
  79.         }        
  80.         VDSWindow win = new VDSWindow();
  81.        
  82.         for (VNode s : list) {
  83.             System.out.println(s.payload);
  84.         }
  85.        
  86.         //win.addString(myS);
  87.        // win.main();
  88.  
  89.     }
  90.    
  91.     private void addNodeToList() {
  92.         VNode temp = null;
  93.        
  94.        
  95.         temp.payload = getNodeField(first, "payload");
  96.         temp.next = getNodeField(first, "next");
  97.         temp.prev = getNodeField(first, "prev");
  98.     }
  99.    
  100.     //Parameter: z.B. list->first, first->next
  101.     private VNode getNodeField(Object lOrN, String field) {
  102.         VNode temp = null;
  103.        
  104.        
  105.         try {
  106.            
  107.             //set Object
  108.             Field f = lOrN.getClass().getDeclaredField(field); //NoSuchFieldException
  109.             f.setAccessible(true);
  110.             if (f.get(lOrN) != null) {
  111.                 temp = (VNode) f.get(lOrN); //IllegalAccessException
  112.             }
  113.            
  114.             //set Payload
  115.             f = temp.getClass().getDeclaredField("payload"); //NoSuchFieldException
  116.             f.setAccessible(true);
  117.             if (f.get(temp) != null) {
  118.                 temp.payload = (String) f.get(temp); //IllegalAccessException
  119.                 System.out.println(temp.payload);
  120.             }
  121.            
  122.             //next
  123.             f = temp.getClass().getDeclaredField("next"); //NoSuchFieldException
  124.             f.setAccessible(true);
  125.             if (f.get(temp) != null) {
  126.                 temp.next = (VNode) f.get(temp); //IllegalAccessException
  127.             }
  128.            
  129.             //prev
  130.             f = temp.getClass().getDeclaredField("prev"); //NoSuchFieldException
  131.             f.setAccessible(true);
  132.             if (f.get(temp) != null) {
  133.                 temp.next = (VNode) f.get(temp); //IllegalAccessException
  134.             }
  135.            
  136.             //add Node to List
  137.             list.add(temp);
  138.         } catch (IllegalAccessException | NoSuchFieldException | SecurityException ex) {
  139.             Logger.getLogger(VDSList.class.getName()).log(Level.SEVERE, null, ex);
  140.         }    
  141.        
  142.         return temp;
  143.        
  144.        
  145.     }
  146.    
  147.  
  148.  
  149.  
  150.  
  151.  
  152.  
  153.    
  154. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement