Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package vds.jfx.window;
- import java.lang.reflect.Field;
- import java.lang.reflect.Method;
- import java.util.ArrayList;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- import vds.jfx.code.VDSList;
- import vds.jfx.code.VNode;
- /**
- *
- * @author Alexandros Delas
- * @param <T>
- */
- public class Transformer<T extends VDSList> {
- private VDSList tlist;
- private VNode first;
- private VNode last;
- private VNode prev;
- private VNode next;
- private VNode temp;
- ArrayList<VNode> list = new ArrayList<VNode>();
- public Transformer(T tlist) {
- this.tlist = tlist;
- System.out.println(tlist.getClass().getName());
- Field f = null;
- /
- try {
- //was eigentlich fehlt: unnötigen Anhang entfernen
- //ODER Verknüpfungen mit prev, next und payload selber erstellen
- //eigene Funktion statt Wiederholung
- //first element
- f = tlist.getClass().getDeclaredField("first"); //NoSuchFieldException
- f.setAccessible(true);
- if (f.get(tlist) != null) {
- first = (VNode) f.get(tlist); //IllegalAccessException
- list.add(first);
- System.out.println(first);
- }
- //second element
- f = first.getClass().getDeclaredField("next"); //NoSuchFieldException
- f.setAccessible(true);
- if (f.get(first) != null) {
- next = (VNode) f.get(first); //IllegalAccessException
- list.add(next);
- System.out.println(next);
- }
- //more elements
- while (f.get(next) != null) {
- f = next.getClass().getDeclaredField("next"); //NoSuchFieldException
- f.setAccessible(true);
- next = (VNode) f.get(next); //IllegalAccessException
- list.add(next);
- System.out.println(next);
- }
- //was eigentlich fehlt: unnötigen Anhang entfernen
- //ODER Verknüpfungen mit prev, next und payload selber erstellen
- //eigene Funktion statt Wiederholung
- } catch (IllegalAccessException | NoSuchFieldException | SecurityException ex) {
- Logger.getLogger(VDSList.class.getName()).log(Level.SEVERE, null, ex);
- }
- VDSWindow win = new VDSWindow();
- for (VNode s : list) {
- System.out.println(s.payload);
- }
- //win.addString(myS);
- // win.main();
- }
- private void addNodeToList() {
- VNode temp = null;
- temp.payload = getNodeField(first, "payload");
- temp.next = getNodeField(first, "next");
- temp.prev = getNodeField(first, "prev");
- }
- //Parameter: z.B. list->first, first->next
- private VNode getNodeField(Object lOrN, String field) {
- VNode temp = null;
- try {
- //set Object
- Field f = lOrN.getClass().getDeclaredField(field); //NoSuchFieldException
- f.setAccessible(true);
- if (f.get(lOrN) != null) {
- temp = (VNode) f.get(lOrN); //IllegalAccessException
- }
- //set Payload
- f = temp.getClass().getDeclaredField("payload"); //NoSuchFieldException
- f.setAccessible(true);
- if (f.get(temp) != null) {
- temp.payload = (String) f.get(temp); //IllegalAccessException
- System.out.println(temp.payload);
- }
- //next
- f = temp.getClass().getDeclaredField("next"); //NoSuchFieldException
- f.setAccessible(true);
- if (f.get(temp) != null) {
- temp.next = (VNode) f.get(temp); //IllegalAccessException
- }
- //prev
- f = temp.getClass().getDeclaredField("prev"); //NoSuchFieldException
- f.setAccessible(true);
- if (f.get(temp) != null) {
- temp.next = (VNode) f.get(temp); //IllegalAccessException
- }
- //add Node to List
- list.add(temp);
- } catch (IllegalAccessException | NoSuchFieldException | SecurityException ex) {
- Logger.getLogger(VDSList.class.getName()).log(Level.SEVERE, null, ex);
- }
- return temp;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement