Παρασκευή 13 Σεπτεμβρίου 2019

Xonly Function Parser Mononym as Polyonym

package dim.math.func;

import dim.A;
import dim.ext.javax.swing.tree.Dmtn;//DefaultMutableTreeNode
import java.lang.reflect.Constructor;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.Vector;


/**
 *
 * @author jimidimi
 */
public class Parser extends Dmtn{
    public static Parser main=new Parser();
 
    public static void main(String[] args) {
        //test1();
        build();
    }
    static void test1(){
        Mononymo m=new Mononymo(8);
        m.xDyn=2.0;
        System.out.println(""+m.f(2));
        m.addDia(new Mononymo(2));
        System.out.println(""+m.f(2));
        m.addDia(new Mononymo(4));
        System.out.println(""+m.f(2));


        System.out.println(""+m);

     
    }
    static void build(){
        String testBrack="5x+(x-3-pe)+pow(x+3,sum(1,2pow(2,x+1),3x+1))";
        testBrack="geom(0,e,44)";
        Parser t=new Parser();
        t.parse(testBrack);
        //new Efr(new Etr(t)).setBounds(0,0,400,700);
     
    }
 
    protected Hashtable<Character, Double> statheres=new Hashtable<>();
    protected String telestes="+-/*%^,";
    protected Vector<String> funks=new Vector<>();
    protected Vector<Constructor> funksCons=new Vector<>();
    public Parser(){
        super("Function Parser version 1 - only x");
     
        statheres.put('p',Math.PI);
        statheres.put('e',Math.E);
        statheres.put('f',(1.0+Math.sqrt(5.0))/2.0);
             
        //0 params
        putClass(Rand.class);

     
        //1 params
        putClass(Abs.class);
        putClass(Sqrt.class);
        putClass(Cbrt.class);
        putClass(Ceil.class);
        putClass(Floor.class);
        putClass(Exp.class);
        putClass(Ln.class);
        putClass(Log.class);
        putClass(Rint.class);
        putClass(Round.class);
        putClass(Signum.class);
        putClass(Rad.class);
        putClass(Deg.class);
        putClass(Sin.class);
        putClass(Cos.class);
        putClass(Tan.class);
        putClass(Asin.class);
        putClass(Acos.class);
        putClass(Atan.class);
        putClass(Sinh.class);
        putClass(Cosh.class);
        putClass(Tanh.class);
         
     
        //2 params
        putClass(Min.class);
        putClass(Max.class);
        putClass(Pow.class);
        putClass(Atanpol.class);
        putClass(Hypot.class);
        putClass(Rem.class);
     
 
     
        //3 params
        putClass(Geom.class);
     
        //multi params
        putClass(Sum.class);
        putClass(Mul.class);
        putClass(Div.class);
     
     
     
    }
    protected synchronized Constructor putClass(Class cl){
        String cln=cl.getSimpleName().toLowerCase();
        Constructor con=null;
        try{
            con=cl.getConstructor(A.azcl);
            funks.add(cln);
            funksCons.add(con);
            //System.out.println(cln+" = "+con);
        }catch(NoSuchMethodException nsme){
            nsme.printStackTrace();
        }
        return con;
    }

    public Mononymo parse(String text){
        Mononymo m=null;
        try{
            Dmtn it,out=parseLevel1(text);
            Object uo;
            Enumeration en=out.depthFirstEnumeration();
            HashSet<Class> hs=new HashSet();
            while(en.hasMoreElements()){
                it=(Dmtn)en.nextElement();
                uo=it.getUserObject();
                if(uo instanceof String){
                    //System.out.println("Mononymizing : "+uo);
                    m=mononimize(it);
                    m.setUserObject(uo);
                    it.setUserObject(m);
                    //System.out.println("-----------");
                }
                hs.add(uo.getClass());
            }
            A.enln(hs.iterator());
         
            //new Efr(new Etr(m).scr()).q(600, 400, 230, 333).qExitOnClose();
            System.out.println("f(-2) = "+m.f(-2));
            System.out.println("f(-1) = "+m.f(-1));
            System.out.println("f(0) = "+m.f(0));
            System.out.println("f(1) = "+m.f(1));
            System.out.println("f(2) = "+m.f(2));
        }catch(Exception e){
            e.printStackTrace();
        }
        return m;
    }
 
    protected Mononymo mononimize(Dmtn level2){
        return mononimize(level2,new Mononymo(1),0,level2.getChildCount());
    }
    protected Mononymo mononimize(Dmtn level2,Mononymo theOut,int i ,int l){
        Mononymo out=theOut;
        if(l>0){
            Dmtn it;
            Object ito;
            char ch,prevch='*';
            double d;
            Func fn;
            if(level2.dmtn(i).getUserObject().equals('-')){
                //System.out.println("-------------");
                out.c=-out.c;
                ++i;
            }
            while(i<l){
                it=level2.dmtn(i);
                ito=it.getUserObject();
                if(ito instanceof Double){
                    d=(Double)ito;
                    if(prevch=='*'){out.c*=d;}
                    else if(prevch=='/'){out.c/=d;}
                    else if(prevch=='%'){out.c%=d;}
                    else if(prevch=='+'){System.err.println("Error +");}
                    else if(prevch=='-'){System.err.println("Error -");}
                }
                else if(ito instanceof Character){
                    ch=(Character)ito;
                    if(ch=='x'){out.xDyn+=1.0;}
                    else if(ch=='*'){prevch=ch;}
                    else if(ch=='/'){prevch=ch;}
                    else if(ch=='%'){prevch=ch;}
                    else if(ch=='+'){prevch='*';
                        Mononymo nm=new Mononymo(1.0);
                        theOut.addSum(nm);
                        out=nm;
                    }
                    else if(ch=='-'){prevch='*';
                        Mononymo nm=new Mononymo(-1.0);
                        theOut.addSum(nm);
                        out=nm;
                    }
                 
                }
                else if(ito instanceof Func){
                   fn=(Func)ito;
                   if(fn.getChildCount()>0){
                       System.err.println("Error on level for "+it);
                   }
                   else{
                       int j=0,k=it.getChildCount();Dmtn fch;Object fo;
                       System.out.println(fn+" ...Functioning "+k+" with ,kommas");
                       int flushedj=0;
                       while(j<k){
                           fch=it.dmtn(j);
                           fo=fch.getUserObject();
                           if(fo.equals(',')){
                               System.out.println("\t"+fo.getClass().getSimpleName()+" = "+fo);
                               fn.add(mononimize(it,new Mononymo(1.0),flushedj,j));
                               flushedj=j+1;
                           }
                           ++j;
                       }
                       fn.add(mononimize(it,new Mononymo(1.0),flushedj,j));
                   }
                    if(prevch=='*'){out.addGin(fn);}
                    else if(prevch=='/'){out.addDia(fn);}
                    else if(prevch=='%'){out.addYpol(fn);}
                    else if(prevch=='+'){out.addSum(fn);}
                    else if(prevch=='-'){System.err.println("Must Mononymo");out.addSum(fn);}
                 
                }
             
                ++i;
            }
        }
     
        return theOut;
    }
 
    protected Dmtn parseLevel1(String text)throws Exception{
        int l=text.length();
        int i=0,j,jl;
        Dmtn out=crad(text);
        char ch;
        String buf;
        Double d;
        while(i<l){
            ch=text.charAt(i);
            if(ch=='('){
                ++i;
                int opened=1;
                buf="";
                while(i<l){
                    ch=text.charAt(i);
                    if(ch=='('){++opened;buf+=ch;}
                    else if(ch==')'){
                        --opened;
                        if(opened<1){break;}
                        else{buf+=ch;}
                    }
                    else{buf+=ch;}
                    ++i;
                }
                //System.out.println("Anadromic parse = "+buf);
                out.add(parseLevel1(buf));
            }
            else if(ch==')'){
                //System.out.println("Closed error?");
                throw new Exception("Brackets closed without opened");
            }
            else if(Character.isLetter(ch)){
                //System.out.println("Initilising constants and ending function names");
                buf=""+ch;
                ++i;
                while(i<l){
                    ch=text.charAt(i);
                    if(Character.isLetter(ch)){buf+=ch;}
                    else{--i;break;}
                    ++i;
                }
                buf=buf.toLowerCase();
                //System.out.println("Hole String = "+buf);
                jl=buf.length();
                Constructor methFound=null;
                if(jl>1){//if more than one char find function from end
                    j=0;
                    jl=funks.size();
                    String meth;
                    while(j<jl){
                        meth=funks.get(j);
                        if(buf.endsWith(meth)){
                            methFound=funksCons.get(j);
                            buf=buf.substring(0,buf.length()-meth.length());
                            break;
                        }
                        ++j;
                    }
                }
                j=0;jl=buf.length();
                //check every char(before function founded or not if it is constant
                while(j<jl){
                    ch=buf.charAt(j);
                    if(ch=='x'){out.crad('x');}
                    else{
                        d=statheres.get(ch);
                        if(d!=null){out.crad(d);}
                        else{throw new IllegalArgumentException("Unknown char = "+ch); }
                    }
                    ++j;
                }
                if(methFound!=null){
                    Func newf=(Func)methFound.newInstance(A.azo);
                    out.crad(newf);
                    //System.out.println("new "+newf.getClass().getSimpleName());
                }
             
            }
            else if(Character.isDigit(ch)||ch=='.'){
                //System.out.println("Initilising numbers");
                buf=""+ch;
                ++i;
                while(i<l){
                    ch=text.charAt(i);
                    if(Character.isDigit(ch)||ch=='.'){buf+=ch;}
                    else{--i;break;}
                    ++i;
                }
                d=Double.parseDouble(buf);
                out.crad(d);//double
            }
            else{
                if(telestes.contains(ch+"")){
                    out.crad(ch);//char
                }
                else{
                    throw new IllegalArgumentException("Unknown char = "+ch);
                }
            }

            ++i;
        }
        //return out;
        return parseLevel2(out);
    }
 
    protected Dmtn parseLevel2(Dmtn out){
        //System.out.println("replace ^ with pow()");
        int l=out.getChildCount();
        Dmtn it;Object uo;
        --l;
        char ch;
        while(l>=0){
            it=out.dmtn(l);
            uo=it.getUserObject();
            if(uo instanceof Character){
                ch=(Character)uo;
                if(l>0&&ch=='^'){
                    //System.out.println("Replacing ^ with pow");
                    Dmtn prev=out.dmtn(l-1);
                    Dmtn aft=out.dmtn(l+1);
                    Dmtn newPow=new Dmtn(new Pow());
                    newPow.add(prev);
                    newPow.add(it);
                    newPow.add(aft);
                    it.setUserObject(',');
                    out.insert(newPow, l-1);
                    --l;
                }
            }
            else if(uo instanceof Func){
                if(it.getChildCount()==0){
                    Dmtn aft=out.dmtn(l+1);
                    if(aft.getUserObject() instanceof String){
                        //System.out.println("Transferring parameters inside");
                        out.remove(l+1);
                        int jl=aft.getChildCount()-1;
                        while(jl>=0){
                            it.insert(aft.dmtn(jl), 0);
                            --jl;
                        }
                    }
                }
            }
            --l;
        }
     
     
        return out;
    }
 
}


////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////

public class Mononymo extends Func{

    double c=1.0;
    double xDyn=0.0;

    public Mononymo(String sometext) {
        super();
        setUserObject(sometext);
    }
    public Mononymo(double ac){
        c=ac;
    }
    public Mononymo(double ac,Double axpow){
        c=ac;
        xDyn=axpow;
    }

    @Override
    public Dmtn cr() {
        return new Mononymo("");
    }
    
    

    public String toString(){
        String out="";
        if(c<0.0){out+=c+"";}
        else{out+="+"+c;}
        if(xDyn!=0.0){
            out+="x";
            if(xDyn!=1.0){
                out+="^("+xDyn+")";
            }
        }
        //return getUserObject().toString();
        return out+" @ "+getUserObject();
    }
    public boolean hasX(){
        if(xDyn!=0.0){
            return true;
        }
        return super.hasX();
    } 
    
    
    
    private int gin=0,dia=0,ypol=0,sum=0;
    public int gins(){return gin;}
    public int dias(){return dia-gin;}
    public int ypols(){return ypol-dia;}
    public int sums(){return sum-ypol;}
    public double f(double x){
        double out=c;
        out*=Math.pow(x, xDyn);
        int i=0;
        while(i<gin){
            out*=func(i).f(x);
            ++i;
        }
        while(i<dia){
            out/=func(i).f(x);
            ++i;
        }
        while(i<ypol){
            out%=func(i).f(x);
            ++i;
        }
        while(i<sum){
            out+=func(i).f(x);
            ++i;
        }
        return out;
    }
    
    public void addGin(Func f){
        insert(f, gin);
        gin++;
        dia++;
        ypol++;
        sum++;
    }
    public void addDia(Func f){
        insert(f, dia);
        dia++;
        ypol++;
        sum++;
    }
    public void addYpol(Func f){
        insert(f, ypol);
        ypol++;
        sum++;
    }
    public void addSum(Func f){
        add(f);
        ++sum;
    }

}








class Func extends Dmtn{
    public Func(){}
    public String toString(){
        return getClass().getSimpleName();
    }
    public double f(double x){
        return x;
    }
    public Func func(int index){
        return (Func)getChildAt(index);
    }
    public boolean hasX(){
        int l=getChildCount();
        if(l>0){
            int i=0;
            while(i<l){
                if(func(i).hasX()){return true;}
                ++i;
            }
        }
        return false;
    } 

}
class Pow extends Func{
    public Pow() {}
    public double f(double x){
        return Math.pow(func(0).f(x),func(1).f(x));
    }
}
class Min extends Func{
    public Min() {}
    public double f(double x){
        return Math.min(func(0).f(x),func(1).f(x));
    }
}
class Max extends Func{
    public Max() {}
    public double f(double x){
        return Math.max(func(0).f(x),func(1).f(x));
    }
}
class Abs extends Func{
    public Abs() {}
    public double f(double x){
        return Math.abs(func(0).f(x));
    }
}
class Rad extends Func{
    public Rad() {}
    public double f(double x){
        return Math.toRadians(func(0).f(x));
    }
}
class Deg extends Func{
    public Deg() {}
    public double f(double x){
        return Math.toDegrees(func(0).f(x));
    }
}
class Sin extends Func{
    public Sin() {}
    public double f(double x){
        return Math.sin(func(0).f(x));
    }
}
class Asin extends Func{
    public Asin() {}
    public double f(double x){
        return Math.asin(func(0).f(x));
    }
}
class Sinh extends Func{
    public Sinh() {}
    public double f(double x){
        return Math.sinh(func(0).f(x));
    }
}
class Cos extends Func{
    public Cos() {}
    public double f(double x){
        return Math.cos(func(0).f(x));
    }
}
class Acos extends Func{
    public Acos() {}
    public double f(double x){
        return Math.acos(func(0).f(x));
    }
}
class Cosh extends Func{
    public Cosh() {}
    public double f(double x){
        return Math.cosh(func(0).f(x));
    }
}
class Tan extends Func{
    public Tan() {}
    public double f(double x){
        return Math.tan(func(0).f(x));
    }
}
class Atan extends Func{
    public Atan() {}
    public double f(double x){
        return Math.atan(func(0).f(x));
    }
}
class Tanh extends Func{
    public Tanh() {}
    public double f(double x){
        return Math.tanh(func(0).f(x));
    }
}
class Atanpol extends Func{
    public Atanpol() {}
    public double f(double x){
        return Math.atan2(func(0).f(x),func(1).f(x));
    }
}


class Sqrt extends Func{
    public Sqrt() {}
    public double f(double x){
        return Math.sqrt(func(0).f(x));
    }
}
class Cbrt extends Func{
    public Cbrt() {}
    public double f(double x){
        return Math.cbrt(func(0).f(x));
    }
}
class Ceil extends Func{
    public Ceil() {}
    public double f(double x){
        return Math.ceil(func(0).f(x));
    }
}
class Floor extends Func{
    public Floor() {}
    public double f(double x){
        return Math.floor(func(0).f(x));
    }
}
class Rem extends Func{
    public Rem() {}
    public double f(double x){
        return Math.IEEEremainder(func(0).f(x),func(1).f(x));
    }
}
class Exp extends Func{
    public Exp() {}
    public double f(double x){
        return Math.exp(func(0).f(x));
    }
}
class Hypot extends Func{
    public Hypot() {}
    public double f(double x){
        return Math.hypot(func(0).f(x),func(1).f(x));
    }
}

class Ln extends Func{
    public Ln() {}
    public double f(double x){
        return Math.log(func(0).f(x));
    }
}
class Log extends Func{
    public Log() {}
    public double f(double x){
        return Math.log10(func(0).f(x));
    }
}
class Rand extends Func{
    public Rand() {}
    public double f(double x){
        return Math.random();
    }
}
class Rint extends Func{
    public Rint() {}
    public double f(double x){
        return Math.rint(func(0).f(x));
    }
}
class Round extends Func{
    public Round() {}
    public double f(double x){
        return Math.round(func(0).f(x));
    }
}
class Signum extends Func{
    public Signum() {}
    public double f(double x){
        return Math.signum(func(0).f(x));
    }
}

class Sum extends Func{
    public Sum() {}
    public double f(double x){
        int l=getChildCount();
        double out=0.0;
        if(l>0){
            int i=0;
            Func it=func(i);
            out=it.f(x);
            ++i;
            while(i<l){
                out+=func(i).f(x);
                ++i;
            }
        }
        return out;
    }
}
class Mul extends Func{
    public Mul() {}
    public double f(double x){
        int l=getChildCount();
        double out=0.0;
        if(l>0){
            int i=0;
            Func it=func(i);
            out=it.f(x);
            ++i;
            while(i<l){
                out*=func(i).f(x);
                ++i;
            }
        }
        return out;
    }
}
class Div extends Func{
    public Div() {}
    public double f(double x){
        int l=getChildCount();
        double out=0.0;
        if(l>0){
            int i=0;
            Func it=func(i);
            out=it.f(x);
            ++i;
            while(i<l){
                out/=func(i).f(x);
                ++i;
            }
        }
        return out;
    }
}
class Poly extends Func{
    public Poly() {}
    public double f(double x){
        int l=getChildCount();
        double out=0.0;
        if(l>0){
            int i=0;
            Func it=func(i);
            out=it.f(x);
            ++i;
            while(i<l){
                out+=Math.pow(func(i).f(x),i+1);
                ++i;
            }
        }
        return out;
    }
}
class Geom extends Func{
    public Geom() {}
    public double f(double x){
        int l=getChildCount();
        double out=0.0;
        if(l>0){
            int i=0;
            double startFrom=func(i).f(x);
            double lamda=0.5;
            double times=10;
            
            ++i;
            if(i<l){
                lamda=func(i).f(x);
            }
            ++i;
            if(i<l){
                times=func(i).f(x);
            }
            
            
            out=startFrom;
            
            i=0;
            while(i<times){
                startFrom*=lamda;
                out+=startFrom;
                ++i;
            }
        }
        return out;
    }
}


Τρίτη 20 Αυγούστου 2019

java.awt.Splitpane

/*
updated 2/4/2021 simplest version
 */
package jim3d;

import java.awt.Color;
import java.awt.Component;
import java.awt.Frame;
import java.awt.Panel;
import java.awt.TextArea;
import java.awt.TextField;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;

/**
 *
 * @author jimakoskx
 */
public class Spl extends Panel implements ComponentListener,MouseListener,MouseMotionListener,KeyListener{
    public static void main(String[] args) {
        Frame fr=new Frame();
        fr.setBounds(0,0,555,555);
        fr.setVisible(true);
        
        Spl s=new Spl();
        fr.add(s);
        fr.validate();
        
        TextField tf=new TextField("hfgh");
        TextArea ta=new TextArea("Area");  
        s.add(tf);
        s.add(ta);
        s.resetLayout();
        
        s.setDividerSize(6);
    }
    private int orientation=1;
    private double divloc=0.2;
    
    private int firstsize=1;
    private int divsizehalf=5;
    private int secondsize=1;
    
    

    public Spl() {
        super();
        super.setBackground(Color.red);
        super.setLayout(null);
        super.addComponentListener(this);
        super.addMouseListener(this);
        super.addMouseMotionListener(this);
        super.addKeyListener(this);
        
    }
    public int getOrientation(){
        return orientation;
    }
    public Spl setOrientation(int i01){
        orientation=Math.abs(i01)%2;
        resetLayout();
        return this;
    }
    public Spl setDividerLocation(double middle){
        if(middle<0.0){middle=0.0;}
        else if(middle>0.99){middle=0.99;}
        divloc=middle;
        resetLayout();
        return this;
    }
    public Spl setDividerSize(int uptocurrsize){
        if(orientation==0){
            uptocurrsize=Math.min(getHeight(), uptocurrsize);
        }
        else{
            uptocurrsize=Math.min(getWidth(), uptocurrsize);
        }
        if(uptocurrsize<2){
            uptocurrsize=2;
        }
        divsizehalf=uptocurrsize/2;
        resetLayout();
        return this;
    }
    public void switchOrientation(){
        setOrientation(getOrientation()+1);
    }
    
    public void switchComponents(){
        Component cs[]=getComponents();
        if(cs.length>1){
            removeAll();
            add(cs[1]);
            add(cs[0]);
            int i=2;
            while(i<cs.length){
                add(cs[i]);
                ++i;
            }
        }
        resetLayout();
    }
    protected void resetLayout(){
        Component cs[]=getComponents();
        if(cs.length>0){
            int w=getWidth();
            int h=getHeight();
            if(cs.length==1){
                cs[0].setBounds(0,0,w,h);
            }
            else {
                if(orientation==0){
                    firstsize=(int)(divloc*h)-divsizehalf-1;
                    secondsize=h-firstsize-divsizehalf-divsizehalf-1;
                    cs[0].setBounds(0, 0,w, firstsize);
                    cs[1].setBounds(0, firstsize+divsizehalf+divsizehalf,w, secondsize);
                }
                else{
                    firstsize=(int)(divloc*w)-divsizehalf-1;
                    secondsize=w-firstsize-divsizehalf-divsizehalf-1;
                    cs[0].setBounds(0, 0,firstsize, h);
                    cs[1].setBounds(firstsize+divsizehalf+divsizehalf,0,secondsize,h);
                }
                //System.out.println(w+" , "+h);  
                //System.out.println(divloc+"  +2*"+divsizehalf);
                //System.out.println(firstsize+" - "+secondsize);
                //System.out.println(""+cs[0].getBounds());
                //System.out.println(""+cs[1].getBounds());
                //System.out.println("");
            }
        }  
        validate();
        repaint();
    }

    @Override
    public void componentResized(ComponentEvent e) {
        resetLayout();
    }

    @Override
    public void componentMoved(ComponentEvent e) {
    }

    @Override
    public void componentShown(ComponentEvent e) {
    }

    @Override
    public void componentHidden(ComponentEvent e) {
    }

    @Override
    public void mouseClicked(MouseEvent e) {
    }
    @Override
    public void mousePressed(MouseEvent e) {
        requestFocus();
    }

    @Override
    public void mouseReleased(MouseEvent e) {
    }

    @Override
    public void mouseEntered(MouseEvent e) {
    }

    @Override
    public void mouseExited(MouseEvent e) {
    }

    @Override
    public void mouseDragged(MouseEvent e) {
        if(orientation==0){
            int h=getHeight();
            double dif=e.getY();
            dif/=h;
            setDividerLocation(dif);
            
        }
        else{
            int w=getWidth();
            double dif=e.getX();
            dif/=w;
            setDividerLocation(dif);
        }
    }

    @Override
    public void mouseMoved(MouseEvent e) {
    }

    @Override
    public void keyTyped(KeyEvent e) {
    }

    @Override
    public void keyPressed(KeyEvent e) {
        int kc=e.getKeyCode();
        if(kc==KeyEvent.VK_F2){
            VK_F2();
        }
        else if(kc==KeyEvent.VK_F3){
            VK_F3();
        }
        else if(kc==KeyEvent.VK_F4){
            VK_F4();
        }
    }

    @Override
    public void keyReleased(KeyEvent e) {
    }

    public void VK_F2(){
        switchOrientation();
    }
    public void VK_F3(){
        setDividerLocation(0.5);
    }
    public void VK_F4(){
        switchComponents();
    }
    

}

Πέμπτη 25 Ιανουαρίου 2018

Programming notes

26//3/2025 
...still learning !!!
    public static void techo(String s,Object ... args){
        int i=0;
        while(i<args.length){
            System.out.println(i+" : "+args[i]);
            ++i;
        }
    }
    public static void main(String[] args) {
        //new JHerosOfHistory();
        techo("f",0);
        techo("f",0,1,3);
        techo("f",0,1,2,3,"as much ");
    }
(
how much times i need and didnt knew writing code like 
    public Vect(E e0){this();
        super.add(e0);
    }
    public Vect(E e0,E e1){this();
        super.add(e0);super.add(e1);
    }
    public Vect(E e0,E e1,E e2){this();
        super.add(e0);super.add(e1);super.add(e2);
    }
)hahhahahhaha

Now solved as 
    public Vect(E ... oar) {
        this();
        if(oar!=null){
            int i=0,l=oar.length;
            super.ensureCapacity(l);
            while(i<l){
                super.add(oar[i]);
                ++i;
            }
        }
    }






15/10/21
public class Thr extends Thread{
    public volatile boolean keeprun=true;
    public boolean paused=true;
    public long slwork=1000;
    public long slbig=mday;
    public void run(){
        while(keeprun){
            if(paused){
                slbig();
            }
            else{
                worksimple();
                slwork();
            }
        }
    }

}
Volatile otherwise fucked up !!!!!!!!!!!!!!!!!!!!!!!
when from somewhere i execute
somethread.keeprun=false;/////will not 'break'.....if not volatile
http://tutorials.jenkov.com/java-concurrency/volatile.html

-------------------------------------------

    static double a=1,b=2;
    static long counter=0;
    static int st=0;//no volatile and only ++counter seems giving
    3.145.893.960 about processor speed =3Ghertz but does not break from 
while(st<5)

  //static volatile int st=0;//making it volatile will give ~582.862.710 increasements per second
  diladi speed / 5,3 !!!!!!
    public static void main(String[] args) { 
        Thread multiplier=new Thread(){
            public void run(){
                while(st<5){//while(true) instead of local boolean also gives /5 time
                    ++counter;
                    //a*=b;
                    //a=System.currentTimeMillis();
                }
            }
        };
        long prevc=0;
        multiplier.start();
        while(true){
            ++st;
            System.out.println(counter+" dif:  "+(counter-prevc));
            prevc=counter;
            Thr.slep(1000);
        }
    }
--------------------------------------

1/10/2021















System.setProperty("sun.awt.noerasebackground","true");



















Note: Using the static import language feature, you don't have to write Math in front of every math function:

import static java.lang.Math.*;
This allows you to invoke the Math class methods by their simple names. For example:
cos(angle);

1\7/18

//
/**/
package jbuilder;
import java.io.Serializable;
public abstract class MinJavaFileMaxKeywordsClassShow extends Object implements Serializable{
    strictfp interface classSubfile1{}
    protected enum classSubfile2{name;}
    final native long bitsFlash()throws IllegalArgumentException;
    private transient volatile boolean ProcessorRunFlag=

((this instanceof MinJavaFileMaxKeywordsClassShow));
   
    static void b(){
        String ss="!\"%&\\()*+-./:;<=>?[]{|},'";
        byte i=0;
        short j=0;
        int k=0;       
        float m=0;
        double n=0;
        assert (k<n) ;
        try{
            do{ 
                for(;;){
                    switch(k){
                        case  0 :
                        default :
                        if(true){
                            synchronized(ss){
                                continue;
                            }
                        }
                    }       
                    break;
                }
            }while(false);
           
        }catch(Exception e){
            throw new IllegalArgumentException();
        }
        finally{
        }
        return;
    }
}  

"How many pins are there in processor?


Intel 8086 came in DIP and had 40 pins.
Original Pentium came in PGA and had 273 pins.
Opteron 6000 series server CPUs come in LGA and have 1974 pads.
Intel LGA 2011 Xeon / Core i7 chips come in LGA and have 2011 pads.
AMD AM4 CPUs will come in PGA and have 1331 pins.
 "


public class A extends Object{
   
}

class B extends A {
    Boolean b;
}
class C extends A{
    Character c;
}
class D extends A{
    Double d;
}
class E extends A{
   
}
public class Oktadion {
    public static void main(String[] args) {
        System.out.println(""+Long.MAX_VALUE);
    }
    private dion ar[]=new dion[8];
}
class Tetradion {
    private dion ar[]=new dion[4];
}
class on{}
class mhon{
    private on ar[]=new on[0];
}
class monon{
    private on ar[]=new on[1];
}
class dion{
    private on ar[]=new on[2];
}
class trion{
    private on ar[]=new on[3];
}
class ennon{
    private on ar[]=new on[9];
}

///////////////////////////////////////////////////

/*
 * 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 jan;

import java.util.Enumeration;
import java.util.Iterator;
import java.util.StringTokenizer;
import java.util.Vector;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.TreeNode;

/**
 *
 * @author jimakoskx
 */
public class Dyn extends java.lang.Object implements
        TreeNode
{
   
    public static void main(String[] args) {
       
        Dyn test=new Dyn();

       
        test.addObject("V_2");
        test.addObject("V_3");
        test.addObject("V_4");
        test.debugln();
       
       
       
       
       

       
       
        System.out.println("Removed/Founded at: "+test.removeObject("V_35"));
        test.debugln();
       
        test.jfrDebug();

    }

   
    protected int childCounts=0;
    private Vector<Object> v;
    public Dyn(){
        this(Thread.currentThread());
    }
    public Dyn(Object userObject){
        super();
        v=new Vector<Object>();
        v.add("null");
        v.add(userObject);
    }

   
    /**
     * clear the programming (after userObject) objects from vector<br>
     * one by one<br>
     * better if we have v.removeRange(int,int)<br>
     * ram overheading by arrays ?...?
     */
    public void removeAllObjects(){
        //heavy
        int i=getSize();
        int l=childCounts+2;
        while(i>0){
            --i;
            v.remove(l);
            //System.out.println(v.remove(l)+" Removed:OP"+i);
        }
        //System.out.println("Lefted : "+v.size());
    }
    /**
     * System.out.println("Removed/Founded at: "+test.removeObject("V_35"));
     * @param searchIf
     * @return the index on virtual vector,if founded or -1
     */
    public int removeObject(Object searchIf){
        int i=childCounts+2;
        int l=v.size();
        while(i<l){
            if(v.get(i) ==  searchIf){
                v.remove(i);
                i-=childCounts;
                i-=2;
                return i;
            }
            ++i;
        }
        return -1;
       
    }
    /**
     * v.remove(childCounts+2+IndexAfterUserObject);
     * @param IndexAfterUserObject
     */
    public void removeObject(int IndexAfterUserObject){
        v.remove(childCounts+2+IndexAfterUserObject);
    }
    /**
     * v.add(afterOnlineCurrentLast);
     * @param afterOnlineCurrentLast
     */
    public void addObject(Object afterOnlineCurrentLast){
        v.add(afterOnlineCurrentLast);
    }
    /**
     *
     * @return v.size()-childCounts-2;
     */
    public int getSize(){
        return v.size()-childCounts-2;
    }
    /**
     *
     * @return v.size();
     */
    public int getRealSize(){
        return v.size();
    }
   
    /**
     *
     * @param timesAfterUserObject
     * @return v.get(timesAfterUserObject + childCounts + 2);
     */
    public Object getObject(int timesAfterUserObject){
        timesAfterUserObject+=2;
        timesAfterUserObject+=childCounts;
        return v.get(timesAfterUserObject);
    }
   
    /**
     * v.setElementAt(timesAfterUserObject + childCounts + 2);
     * @param newUserObject
     * @param timesAfterUserObject
     */
    public void setObject(Object newUserObject,int timesAfterUserObject){
        timesAfterUserObject+=2;
        timesAfterUserObject+=childCounts;
        v.setElementAt(newUserObject,timesAfterUserObject);
    }
    /**
     *
     * @return the required from overriders class type
     */
    public Dyn cr(){return new Dyn();}
   
   
    /**
     *
     * @return the UserObject v.get(childCounts+1);
     */
    public Object uo(){return v.get(childCounts+1);}
    /**
     * sets the UserObject <br>
     * v.setElementAt(newUserObject, childCounts+1);
     * @param newUserObject
     */
    public void uo(Object newUserObject){v.setElementAt(newUserObject, childCounts+1);}

    /**
     *
     * @return Parent at  (Dyn)v.get(childCounts);
     */
    public Dyn par(){return (Dyn)v.get(childCounts);}
    /**
     * sets the Parent at v.setElementAt(newPar, childCounts);
     * @param newPar
     */
    public void par(Dyn newPar){v.setElementAt(newPar, childCounts);}
   
    /**
     *
     * @return Last Child at  (Dyn)v.get(childCounts-1);
     */
    public Dyn last(){return (Dyn)v.get(childCounts-1);}
    /**
     * sets the Last at v.setElementAt(newPar, childCounts-1);
     * @param newLast
     */
    public void last(Dyn newLast){v.setElementAt(newLast, childCounts-1);}
   
   
    /**
     *
     * @return number of Children Nodes
     */
    public int chc(){return childCounts;}
    /**
     *
     * @param i
     * @return children Node on i
     */
    public Dyn chi(int i){return (Dyn)v.get(i);}
    /**
     * replaces child Node on index<br>
     * set null the parent of old one
     * @param newChild
     * @param index
     */
    public void chi(Dyn newChild,int index){
        Dyn old=(Dyn)v.get(index);
        old.par(null);
        v.setElementAt(newChild, index);
    }
   
    /**
     *
     * @param newChild
     */
    public void addChild(Dyn newChild){
        v.insertElementAt(newChild, childCounts);
        ++childCounts;
        newChild.par(this);
    }
    /**
     *
     * @param newChild
     * @param index
     */
    public void insertChild(Dyn newChild,int index){
        v.insertElementAt(newChild, index);
        ++childCounts;
        newChild.par(this);
    }
    /**
     *
     * @param index
     * @return the removed and without parent node
     */
    public Dyn removeChild(int index){
        Dyn out=(Dyn)v.remove(index);
        --childCounts;
        out.par(null);//???
        return out;
    }
    /**
     * if(v.get(i) == node)
     * @param node
     * @return index of the removed if founded or -1
     */
    public int removeChild(TreeNode node) {
        int i=0;
        while(i<childCounts){
            if(v.get(i) == node){
                removeChild(i);
                return i;
            }
            ++i;
        }
        return -1;
    }
    /**
     * Would be better if we could use directlly the Vector array<br>
     * v.removeRange(int,int) not allowed here to use..<br>
     * removing one by one.(io overloads)
     */
    public void removeAllChildren(){
        while(childCounts>0){
            ((Dyn)v.remove(0)).par(null);
            --childCounts;
        }
    }
   
   
    @Override
    public TreeNode getChildAt(int childIndex) {return chi(childIndex);}

    @Override
    public int getChildCount() {return childCounts;}

    @Override
    public TreeNode getParent() {return (Dyn)v.get(childCounts);}

    @Override
    public int getIndex(TreeNode node) {
        int i=0;
        while(i<childCounts){
            if(v.get(i) == node){return i;}
            ++i;
        }
        return -1;
    }

    @Override
    public boolean getAllowsChildren() {return true;}

    @Override
    public boolean isLeaf() {return childCounts==0;}

    @Override
    public Enumeration children() {
        return null;
    }
   
   
   
   
   
   
   
   
   
   
   
   
    public Dyn crad(Object uo){Dyn out=cr();out.uo(uo);addChild(out);return out;}
    public Dyn cradr(Object uo){crad(uo);return this;}
   
    public int cradChildren(Object[] it){
        int out=0,i=0;
        while(i<it.length){
            crad(it[i]);
            ++i;
            ++out;
        }
        return out;
    }
    public int cradChildren(Vector it){
        int out=0,i=0;int l=it.size();
        while(i<l){
            crad(it.get(i));
            ++i;
            ++out;
        }
        return out;
    }
    public int cradChildren(DefaultMutableTreeNode it){
        int out=0,i=0;int l=it.getChildCount();
        while(i<l){
            crad(((DefaultMutableTreeNode)it.getChildAt(i)).getUserObject());
            ++i;
            ++out;
        }
        return out;
    }
    public int cradChildren(Iterator it){
        int out=0;
        while(it.hasNext()){
            crad(it.next());
            ++out;
        }
        return out;
    }
    public int cradChildren(StringTokenizer it){
        int out=0;
        while(it.hasMoreTokens()){
            crad(it.nextToken());
            ++out;
        }
        return out;
    }
   
   
   
   
   
   
   
   
    public Dyn cradDeep(Object[] it){
        int i=0;Dyn itnode=this;
        while(i<it.length){
            itnode=itnode.crad(it[i]);
            ++i;
        }
        return itnode;
    }
    public Dyn cradDeep(Vector it){
        int i=0;Dyn itnode=this;int l=it.size();
        while(i<l){
            itnode=itnode.crad(it.get(i));
            ++i;
        }
        return itnode;
    }
    public Dyn cradDeep(DefaultMutableTreeNode it){
        int i=0;Dyn itnode=this;int l=it.getChildCount();
        while(i<l){
            itnode=itnode.crad(((DefaultMutableTreeNode)it.getChildAt(i)).getUserObject());
            ++i;
        }
        return itnode;
    }

    public Dyn cradDeep(Iterator it){
        Dyn itnode=this;
        while(it.hasNext()){
            itnode=itnode.crad(it.next());
        }
        return itnode;
    }
    public Dyn cradDeep(StringTokenizer it){
        Dyn itnode=this;
        while(it.hasMoreTokens()){
            itnode=itnode.crad(it.nextToken());
        }
        return itnode;
    }
   
    public static final String classOpen="{";
    public static final String classClose="}";
    public static final String space=" ";
   
    public void oln(String str){System.out.println(""+str);}
    public void olntr(){
        olntr(new StringBuffer());
    }
    public void olntr(StringBuffer carryingReference){
        oln(carryingReference+""+uo()+classOpen);
        int l=getChildCount();
        if(l>0){
            int i=0;
           
            carryingReference.append(' ');
            while(i<l){chi(i).olntr(carryingReference);++i;}
            l=carryingReference.length();
            i=l-1;
            carryingReference.delete(i, l);
        }
        oln(classClose);
    }















    // BINARY SERACH
    public int sbdecode(int index){++index;index=-index;return index;}
    public int sbencode(int index){index=-index;--index;return index;}
    public int sbi(Comparable toCompare){
        int lo = 0,hi = getChildCount() - 1,mid; int d;

        while (lo <= hi) {mid = lo + (hi - lo) / 2;
            d=toCompare.compareTo(chi(mid).uo());
            if(d<0){ hi = mid - 1;}
            else if (d>0){lo = mid + 1;}
            else {return mid;}
        }
        return sbencode(lo);
    }
   
    public Dyn sb(Comparable findOrAdd){
        int ioi=sbi(findOrAdd);
        if(ioi>-1){return chi(ioi);}
        return null;
    }

    public Dyn sbin(Comparable findOrAdd){
        int ioi=sbi(findOrAdd);
        if(ioi>-1){
            return chi(ioi);
        }
        else{
            Dyn out=cr();
            out.uo(findOrAdd);
            insertChild(out,sbdecode(ioi));
            return out;
        }
    }
   
    public Dyn sbinr(Comparable findOrAdd){sbin(findOrAdd);return this;}
   
   
   
   
   
   
    public int sbinChildren(Iterator it){
        int out=0;
        while(it.hasNext()){sbin((Comparable)it.next());++out;}
        return out;
    }
    public int sbinChildren(StringTokenizer it){
        int out=0;
        while(it.hasMoreTokens()){sbin(it.nextToken());++out;}
        return out;
    }
    public int sbinChildren(Object[] it){
        int out=0;
        while(out<it.length){sbin((Comparable)it[out]);++out;}
        return out;
    }
    public Dyn sbinDeep(Iterator it){
        Dyn itnode=this;
        while(it.hasNext()){itnode=itnode.sbin((Comparable)it.next());}
        return itnode;
    }
    public Dyn sbinDeep(StringTokenizer it){
        Dyn itnode=this;
        while(it.hasMoreTokens()){itnode=itnode.sbin(it.nextToken());}
        return itnode;
    }

    public Dyn sbinDeep(Object[] it){
        int i=0;
        Dyn itnode=this;
        while(i<it.length){
            itnode=itnode.sbin((Comparable)it[i]);
            ++i;
        }
        return itnode;
    }
    public Dyn sbinDeep(Vector it){
        int i=0;
        int l=it.size();
        Dyn itnode=this;
        while(i<l){
            itnode=itnode.sbin((Comparable)it.get(i));
            ++i;
        }
        return itnode;
    }
    public JTree jtr(){
        return new JTree((TreeNode)this);
    }
    public JList jl(){
        return new JList(v);
    }
   
    public JFrame jfr(){
        JFrame jfr=new JFrame();
        jfr.setTitle(toShortDebugString());
        JMenuBar jmb=new JMenuBar();
        jfr.setJMenuBar(jmb);
        jmb.add(new JMenu("File"));
        jfr.setBounds(123,123,323,323);
        jfr.getContentPane().add(new JScrollPane(jtr()));
        jfr.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        jfr.setVisible(true);
        return jfr;
    }
    public JFrame jfrDebug(){
        JFrame jfr=new JFrame();
        jfr.setTitle(toShortDebugString());
        JMenuBar jmb=new JMenuBar();
        jfr.setJMenuBar(jmb);
        jmb.add(new JMenu("File"));
        jfr.setBounds(123,123,323,323);
        JSplitPane jspl=new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,new JScrollPane(jl()),new JScrollPane(jtr()));
        jspl.setResizeWeight(0.3);
        jfr.getContentPane().add(jspl);
        jfr.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        jfr.setVisible(true);
        jspl.setDividerLocation(0.3);
        return jfr;
    }
    public String toString(){
        return uo().toString();
    }
    public void debugln(){
        System.out.println(""+toDebugString());
    }
    public String toShortDebugString(){
        Object uo=uo();
        String out=uo+" - "+uo.getClass().getSimpleName()+"["+getSize()+"{"+chc();
        return out;
    }
    public String toDebugString(){
        Object uo=uo();
        String out="---------------";
        out+="\n"+uo+" - "+uo.getClass();
        out+="\nObjects:  "+getSize();
        out+="\nChildren: "+chc();
        out+="\nReal Size: "+getRealSize();
       
       
        out+="\n";
        return out;
    }
    public String toSuperString(){return super.toString();}
       
   
}




//////////////////////////////////////////////////////


/*
 * 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 jcore;

import java.awt.*;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.StringTokenizer;
import java.util.Vector;
import javax.swing.*;
import javax.swing.tree.DefaultMutableTreeNode;

/**
 *
 * @author jimakoskx
 */
public class Dmtn extends DefaultMutableTreeNode{
    public static void main(String[] args) {
        Dmtn t=new Dmtn("root");
        t.loadClassPathAndClass(t.getClass());
        int i=0;
        while(i<0){
            t.jfr().setTitle(i+"");
            ++i;
        }
        t.jfr().setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
    public static final long jimClassId=0;

    static int counter=0;
    public Dmtn() {
        System.out.println(counter+getClass().getName()+"()");
        ++counter;
    }

    public Dmtn(int y) {System.out.println("testing temp public Dmtn(int y)");}
    public Dmtn(Object userObject) {
        super(userObject);
        System.out.println(counter+getClass().getName()+"() "+userObject);
        ++counter;
       
    }
    public static final String tag_StringHierarchyAssuptionCancelling="*";
    public Dmtn store(String varName,Object varValue){
        return this.sbin(varName).sbin(tag_StringHierarchyAssuptionCancelling).crad(varValue);
    }
   
    //CASTOR
    public String [] args(){return (String[])userObject;}
    public int nint(){return ((Integer)userObject).intValue();}
        public int nintss(){int out=((Integer)userObject).intValue();userObject=out+1;return out;}
        public int nssint(){int out=((Integer)userObject).intValue()+1;userObject=out;return out;}
    public Dmtn link(){return (Dmtn)userObject;}
    public Comparable comp(){return (Comparable)userObject;}
    public Class klass(){return (Class)userObject;}
    public Constructor cons(){return (Constructor)userObject;}
    public Field fild(){return (Field)userObject;}
    public Method meth(){return (Method)userObject;}
    public Vector vect(){return (Vector)userObject;}
    public StringBuffer sbuf(){return (StringBuffer)userObject;}

    //
   
    //general creation as STATIC
    public Dmtn cr(){return new Dmtn();}
    public BufferedReader criobr(){return new BufferedReader(new InputStreamReader(System.in));}
    public Constructor[]crCons(Class cl){return cl.getDeclaredConstructors();}
    public Field[]crFilds(Class cl){return cl.getDeclaredFields();}
    public Method[]crMeths(Class cl){return cl.getDeclaredMethods();}
   
    //TREE FUNCTIONS
    public Dmtn dmtn(int index){return (Dmtn)getChildAt(index);}
    public Dmtn crad(Object uo){Dmtn out=cr();out.setUserObject(uo);add(out);return out;}
    public Dmtn cradr(Object uo){crad(uo);return this;}
    public void oln(String str){System.out.println(""+str);}
    public void olntr(){
        oln(userObject+"{");
        int l=getChildCount();
        if(l>0){
            int i=0;
            while(i<l){dmtn(i).olntr();++i;}
        }
        oln("}");
    }
   
    // BINARY SERACH
    public int sbdecode(int index){++index;index=-index;return index;}
    public int sbencode(int index){index=-index;--index;return index;}
    public int sbi(Comparable toCompare){
        int lo = 0,hi = getChildCount() - 1,mid; int d;
        while (lo <= hi) {mid = lo + (hi - lo) / 2;
            d=toCompare.compareTo(dmtn(mid).comp());
            if(d<0){ hi = mid - 1;}
            else if (d>0){lo = mid + 1;}
            else {return mid;}
        }return sbencode(lo);
    }   
   
    public Dmtn sb(Comparable findOrAdd){
        int ioi=sbi(findOrAdd);
        if(ioi>-1){return (Dmtn)dmtn(ioi);}
        return null;
    }
    public Dmtn sbin(Comparable findOrAdd){
        int ioi=sbi(findOrAdd);
        if(ioi>-1){
            return (Dmtn)dmtn(ioi);
        }
        else{
            Dmtn out=cr();
            out.setUserObject(findOrAdd);
            insert(out,sbdecode(ioi));
            return out;
        }
    }
    public Dmtn sbinr(Comparable findOrAdd){sbin(findOrAdd);return this;}
   
   
   
   
   
    public JTree jtr(){JTree out=new JTree(this);return out;}
    public JScrollPane jscr(){return new JScrollPane(jtr());}
    public JPanel jp(){JPanel out=new JPanel();out.setLayout(new BorderLayout());out.add(BorderLayout.CENTER,jscr());return out;}
    private static int jfrxloc=0,jfryloc=0;
    public JFrame jfr(){
        JFrame out=new JFrame();out.setTitle("def Viewer of : "+this.getClass().getSimpleName()+" "+this);
        out.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        Dimension dim=Toolkit.getDefaultToolkit().getScreenSize();
        out.setBounds(jfrxloc,jfryloc,dim.width/2,dim.height/2);
        out.getContentPane().add(jp());
        jfrxloc+=33;if(jfrxloc>dim.width/2){jfrxloc=0;}
        jfryloc+=2;if(jfryloc>dim.height/2){jfryloc=0;}
       
       
        out.setVisible(true);
        return out;
    }
   
   
    public Dmtn cll(boolean fixIfNotFound){
        if(fixIfNotFound){return sbin("cll");}
        else{return sb("cll");}
    }
    public Dmtn cll(){return sbin("cll");}
    public Dmtn loadClassPathAndClass(Class cl){
        String cln=cl.getName();
        StringTokenizer stok=new StringTokenizer(cln,".");
        String tok;
        Dmtn it=cll();
        while(stok.hasMoreElements()){
            tok=stok.nextToken();
            it=it.sbin(tok);
        }
        if(it.getChildCount()>0){
            if(it.dmtn(0).userObject instanceof Class){
                System.out.println("Already loaded or same exactly package name class ");
                return it;
            }
        }
       
        it.loadClass(cl);
        return it;
    }
    public Dmtn loadClass(Class cl){
        Dmtn it=crad(cl);
        it.sbin("[assinges]");
        it.sbin("cons");
        it.sbin("fild");
        it.sbin("meth");
        it.loadConstructors();
        it.loadFilds();
        it.loadMethods();
        return it;
    }
    public Dmtn loadedClass(Class cl){
        Dmtn it=cll(false);
        if(it!=null){
            String cln=cl.getName();
            StringTokenizer stok=new StringTokenizer(cln,".");
            String tok;
            while(stok.hasMoreElements()&& it!=null){
                tok=stok.nextToken();
                it=it.sb(tok);
            }
            if(it.getChildCount()>0){
                if(it.dmtn(0).userObject instanceof Class){
                    return it;
                }
            }
        }
        return null;
    }
   
  
    //refering to as if userobject instance pf class
    public Dmtn loadConstructors(){
        Constructor ar[]=crCons(klass());
        Dmtn quick=sbin("cons");
        if(ar.length>0 && quick.getChildCount()==0){
            int i=0;
            while(i<ar.length){
                Class ps[]=ar[i].getParameterTypes();
                quick.sbin(ps.length).crad(ar[i]);
                ++i;
            }
            quick.pullUpFirstLevel();
        }
        else{
            System.out.println("0 or Already loaded constructors "+klass());
        }
        return quick;
    } 
    public Dmtn loadFilds(){
        Field ar[]=crFilds(klass());
        Dmtn quick=sbin("fild");
        if(ar.length>0 && quick.getChildCount()==0){
            int i=0;
            while(i<ar.length){
                quick.sbin(ar[i].getName()).crad(ar[i]);
                ++i;
            }
        }
        else{
            System.out.println("0 or Already loaded fields "+klass());
        }
        return quick;
    }
    public Dmtn loadMethods(Integer temp){
        return null;
    }
    public Dmtn loadMethods(){
        Method ar[]=crMeths(klass());
        Dmtn quick=sbin("meth");
        if(ar.length>0 && quick.getChildCount()==0){
            int i=0;
            while(i<ar.length){
                Class ps[]=ar[i].getParameterTypes();
                quick.sbin(ar[i].getName()).sbin(ps.length).crad(ar[i]);
                ++i;
            }
            i=0;
            int l=quick.getChildCount();
            Dmtn ch;
            while(i<l){
                ch=quick.dmtn(i);
                ch.pullUpFirstLevel();
                ++i;
            }
        }
        else{
            System.out.println("0 or Already loaded methods "+klass());
        }
        return quick;
    } 

   
    void pullUpFirstLevel(){
        int l=getChildCount();
        if(l>0){
            Dmtn quickGotheringEggonia=cr();
            int i=0;
            int j,jl;
            Dmtn ch;
            while(i<l){
                ch=dmtn(i);
                jl=ch.getChildCount();
                j=0;
                while(j<jl){
                    quickGotheringEggonia.add(ch.dmtn(0));
                    ++j;
                }
                ++i;
            }
            removeAllChildren();
            l=quickGotheringEggonia.getChildCount();
            i=0;
            while(i<l){
                add(quickGotheringEggonia.dmtn(0));
                ++i;
            }
            //System.out.println("Eggonia being children:"+i);
        }
       
    }

}