Visualizzazione dei risultati da 1 a 4 su 4
  1. #1
    Utente di HTML.it L'avatar di blueice
    Registrato dal
    Feb 2001
    Messaggi
    121

    [Java]Oggi mi sento buono e vi regalo un mio oggetto ...

    ... ci sono anche i commenti javadoc all'interno, spero vi sia di grande utilità.

    Da non utilizzare a scopo di lucro.

    Code :

    package *.*;

    import java.util.*;

    /**
    *

    Title: ResultHolder </p>
    *

    Description : Questo oggetto costruisce una tabella dinamica in base alle esigenze.
    * Per Costruire l'Oggetto ResultHolder basta settare i valori delle colonne.</p>
    * @author Flavio Rocchi
    * @e-mail: f.rocchi@inwind.it
    * @website: www.topdesk.it
    * @copyright: Da non utilizzare a scopo di lucro.
    * $Id: ResultHolder.java,v 1.3 2002/10/18 16:33:20 rocchi Exp $
    */

    public class ResultHolder {

    private Hashtable hs = new Hashtable();
    private final String TOKEN = new String("¿");


    public ResultHolder() {
    }
    /**
    * Questo metodo permette di avere l'indice della chiave (key) passata
    * come parametro.

    * Codice di esempio:

    * resultHolder rh = new resultHoder();

    * int value = rh.getIndexKey(x1);

    * In questo caso value avrà valore 0.

    * -------------------------------------------

    * | x1 | x2 | x3 | x4 | x5 | x6 |

    * -------------------------------------------

    * | y1 | y4 | y7 | y1 | y4 | y7 |

    * -------------------------------------------

    * | y2 | y5 | y8 | y2 | y5 | y8 |

    * -------------------------------------------

    * | y3 | y6 | y9 | y3 | y6 | y9 |

    * -------------------------------------------

    * x = key
    * y = value

    */




    public int getIndexKey(String key){
    int index = -1;

    Vector values = new Vector();
    String value = new String("");
    Enumeration ex = hs.keys();

    while(ex.hasMoreElements()){
    value = value.concat(ex.nextElement().toString()+TOKEN);
    }

    StringTokenizer kx = new StringTokenizer(value,TOKEN);

    while(kx.hasMoreElements()){
    values.add(kx.nextToken());
    }

    int k=0;
    while(k<values.size()){
    if(values.elementAt(k).equals(key))
    { index = k; }
    k++;
    }

    return index;
    }
    /**
    * Questo metodo permette di avere un oggetto Vector con tutte le
    * chiavi dell'oggetto resultHolder.

    * Codice di esempio:

    * resultHolder rh = new resultHoder();

    * Vector value = rh.getKeys();

    * In questo caso value avrà valore x1,x2,x3,x4,x5,x6.

    * -------------------------------------------

    * | x1 | x2 | x3 | x4 | x5 | x6 |

    * -------------------------------------------

    * | y1 | y4 | y7 | y1 | y4 | y7 |

    * -------------------------------------------

    * | y2 | y5 | y8 | y2 | y5 | y8 |

    * -------------------------------------------

    * | y3 | y6 | y9 | y3 | y6 | y9 |

    * -------------------------------------------

    * x = key

    * y = value

    */


    public Vector getKeys(){

    String value = new String("");
    Vector values = new Vector();
    Enumeration ex = hs.keys();

    while(ex.hasMoreElements()){
    value = value.concat(ex.nextElement().toString()+TOKEN);
    }


    StringTokenizer kx = new StringTokenizer(value,TOKEN);


    while(kx.hasMoreElements()){
    values.add(kx.nextToken());
    }

    return values;
    }
    /**
    * Questo metodo permette di ricevere il valore di una chiave (key) all'indice (indice)
    * passato come paramtero.

    * Codice di esempio:

    * resultHolder rh = new resultHoder();

    * String value = rh.getValue(x1, 0);

    * In questo caso value avrà valore y1.

    * -------------------------------------------

    * | x1 | x2 | x3 | x4 | x5 | x6 |

    * -------------------------------------------

    * | y1 | y4 | y7 | y1 | y4 | y7 |

    * -------------------------------------------

    * | y2 | y5 | y8 | y2 | y5 | y8 |

    * -------------------------------------------

    * | y3 | y6 | y9 | y3 | y6 | y9 |

    * -------------------------------------------

    * x = key

    * y = value

    */




    public String getValue(String key, int indice){
    String value = new String(hs.get(key).toString());
    StringTokenizer kx = new StringTokenizer(value,TOKEN);
    Vector values = new Vector(kx.countTokens());
    while(kx.hasMoreElements()){
    values.add(kx.nextElement().toString());
    }
    values.remove(0);
    value = new String(values.elementAt(indice).toString());

    return value;
    }
    /**
    * Questo metodo permette di avere il nome della chiave all'indice
    * (indice) passato come parametro.

    */



    public String getValueKey(int indice){
    Vector values = new Vector();
    String value = new String("");
    Enumeration ex = hs.keys();

    while(ex.hasMoreElements()){
    value = value.concat(ex.nextElement().toString()+TOKEN);
    }


    StringTokenizer kx = new StringTokenizer(value,TOKEN);


    while(kx.hasMoreElements()){
    values.add(kx.nextToken());
    }

    value = new String(values.elementAt(indice).toString());

    return value;
    }
    /**
    * Questo metodo permette di ricevere tutti i valori in un oggetto Vector
    * di una chiave (key).

    */




    public Vector getValues(String key){
    Vector values = new Vector();
    String value = new String(hs.get(key).toString());

    StringTokenizer kx = new StringTokenizer(value,TOKEN);
    while(kx.hasMoreElements()){
    values.add(kx.nextElement().toString());
    }
    values.remove(key);

    return values;
    }
    /**
    * Questo metodo permette di inserire le chiavi (columnNames) dell'oggetto resultHoder,
    * in modo tale che poi le possiamo utilizzare per richiamare i valori e
    * per inserirne di nuovi.

    */


    public void setNames(String[] columnNames){
    hs = new Hashtable();
    for(int i=0;i<columnNames.length;i++){
    hs.put(columnNames[i],columnNames[i]+TOKEN);
    }
    }
    /**
    * Questo metodo permette di inserire un valore (value) ad una chiave (key)
    * in modo tale che l'oggetto di tipo resultHolder aumenti di dimensione.

    */


    public void setValue(String key, String value){
    String valore = new String(hs.get(key).toString());
    valore = valore.concat(value+TOKEN);
    hs.remove(key);
    hs.put(key,valore);
    }
    /**
    * Questo metodo restituisce il numero degli elementi chiave contenuti
    * all'interno dell'oggetto resultHolder.
    Come da esempio sottostante,
    * mi restituisce la dimensione della riga x.

    * -------------------------------------

    * | x | x | x | x | x | x |

    * -------------------------------------

    * | y | y | y | y | y | y |

    * -------------------------------------

    * | y | y | y | y | y | y |

    * -------------------------------------

    * | y | y | y | y | y | y |

    * -------------------------------------

    * x = key

    * y = value

    */

    public int size(){
    Vector values = new Vector();
    String value = new String("");

    Enumeration z = hs.keys();
    while(z.hasMoreElements()){
    value = value.concat(z.nextElement().toString()+TOKEN);
    }

    StringTokenizer kx = new StringTokenizer(value,TOKEN);
    while(kx.hasMoreElements()){
    values.add(kx.nextToken(TOKEN).toString());
    }

    int size = values.size();

    return size;
    }
    /**
    * Questo metodo restituisce il numero degli elementi contenuti
    * all'interno della colonna che ha come chiave key.
    Come da esempio
    * sottostante che rappresenta l'oggetto resultHoder:

    * resultHolder rh = new resultHoder();

    * int size = rh.size(x1);

    * il valore di size è uguale a 3.

    * -------------------------------------------

    * | x1 | x2 | x3 | x4 | x5 | x6 |

    * -------------------------------------------

    * | y | y | y | y | y | y |

    * -------------------------------------------

    * | y | y | y | y | y | y |

    * -------------------------------------------

    * | y | y | y | y | y | y |

    * -------------------------------------------

    * x = key

    * y = value

    */

    public int size(String key){
    Vector values = new Vector();
    String value = new String(hs.get(key).toString());
    StringTokenizer kx = new StringTokenizer(value,TOKEN);

    while(kx.hasMoreElements()){
    values.add(kx.nextToken(TOKEN));
    }

    values.remove(key);

    int size = values.size();

    return size;
    }
    }

  2. #2
    Utente di HTML.it L'avatar di sebamix
    Registrato dal
    Aug 2000
    Messaggi
    1,028
    A cosa serve?

  3. #3
    Utente di HTML.it L'avatar di D4MI4NO
    Registrato dal
    Sep 2001
    Messaggi
    275
    costruisce una tabella dinamica
    ...anche se la strada è dura...se stiamo assieme...arriveremo su quella cosa chiamata luna...

  4. #4
    Utente di HTML.it L'avatar di blueice
    Registrato dal
    Feb 2001
    Messaggi
    121
    Originariamente inviato da D4MI4NO
    costruisce una tabella dinamica
    Lo utilizzo per fare le select negli ejb per poi settarli nei javabean.

    I javabean li implemento nelle pagine jsp e poi scorro i record senza fare l'interfaccia con il db in quest'ultime.

    Lo potresti utilizzare per passare molti valori da una pagina jsp ad un javabean e l'inverso, oppure per passare i valori di una form complessa ad una servlet o un javabean, ecc.

    Fatene un buon uso.

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.