Implementing association classes in Java

Hi. I'm having trouble in implementing an association class.
I have two classes, Customer and Address.
A customer might have different billing address and shipping address.
I found from a book that In this kind of situations, Customer class and Address class should be linked with an association class "Type" that has the attribute "addresstype". My problem is that I dont know how to inplement this kind of association classes in Java. Could anyone please show me some example of implementing an association class.
thanks.

example of implementing an association class.It could look like this,
public class AddressAssociation {
   public enum Type = {BILLING, SHIPPING};
   public void put(Type t, Address a);
   public Address get(Type t);
}The idea is that the Customer class holds a reference to one AddressAssociation object. Basically the Customer class can be kept ignorant (but doesn't have to of course) of what types of addresses there are. In that case when a new type of address is added Customer wouldn't have to be modified, only AddressAssociation.
Note that AddressAssociation probably should be an interface. In the implementation of AddressAssociation to avoid switches in put and get a Map (sometimes called an associate array) could be used.

Similar Messages

  • Please help me...how to implement a class DateAndTime.java

    I have a class named DateAndTime.java How should I implement a method which allows me to check if the date entered by user is valid or not?. Also when the hour continues to a next day, how should I implement a method for a nextDay()? Thank you
    class DateAndTime
         private int hour, minute, second, month, day, year;
         Constructor to initialize DateAndTime.
         Default DateAndTime 0:0:0 1/1/1
         public DateAndTime()
         {     month = 1;
              day =1;
              year =1;
         Constructor to set DateAndTime to specific values.
         Calls member function setDate and setTime to set variables.
         @param h hour of the DateAndTime
         @param m minute of the DateAndTime
         @param s second of the DateAndTime
         @param mo month of the DateAndTime
         @param d day of the DateAndTime
         @param y year of the DateAndTime
         public DateAndTime(int h, int m, int s, int mo, int d, int y)// CONSTRUCTOR
         {     if (isValidDate(mo, d, y))    //if date entered is valid, the date and time will be set
                   setDate(mo, d, y);
                   setTime(h, m, s);
              else
                   System.out.println("Invalid Date :" + mo + "/" + d + "/" + y);
                   setDate(1,1,1);
         Set the values of hour, minute, and second.
         @param h hour of the DateAndTime
         @param m minute of the DateAndTime
         @param s second of the DateAndTime
         public void setTime( int h, int m, int s ) //DEFINING SETTERS, SETTING time,hour,minute,and second,
         setHour( h );
         setMinute( m );
         setSecond( s );
         Set the hour if valid or to default 0.********************SET HOUR
         public void setHour( int h )
         {     hour = ( h >= 0 && h < 24 ) ? h : 0;     }
         Set the minute if valid or to default 0.******************SET MINUTE
         public void setMinute( int m )
         {     minute = ( m >= 0 && m < 60 ) ? m : 0;     }
         Set the hour if valid or to default 0. ******************SET SECOND
         public void setSecond( int s )
         {     second = ( s >= 0 && s < 60 ) ? s : 0;     }
         Set the values of month, day, and year.
         @param mo month of the DateAndTime
         @param d day of the DateAndTime
         @param y year of the DateAndTime
         public void setDate(int mo, int d, int y)//DEFINING SETTERS, SETTING DATE FOR month,day,and Year
              setMonth(mo);
              setDay(d,mo,y);
              setYear(y);
         Set the month if valid or to default 1. ****************SET MONTH
         public void setMonth(int mo)
         {     month = (mo >= 1 && mo <= 12)? mo : 1;  }
         Set the day if valid or to default 1. ****************SET DAY
         public void setDay(int d, int mo, int y) // ?????
         {     day = (isValidDate(mo,d,y))? d : 1;  }
         Set the year if valid or to default 1. ****************SET YEAR
         public void setYear(int y)
         {     year = (y >=1)? y : 1;     }
         Get the hour value.
         @return int
         public int getHour() {   return hour;  } //DEFINING GETTERS get hour, minute, second
         Get the minute value.
         @return int
         public int getMinute() {   return minute;  }
         Get the second value.
         @return int
         public int getSecond() {   return second;  }
         Get the month value.
         @return int
         public int getMonth() {   return month;  } //DEFINING GETTERS get month, day, and year
         Get the day value.
         @return int
         public int getDay() {   return day;  }
         Get the year value.
         @return int
         public int getYear() {   return year;  }
         Finds whether a given date is a valid date in A.D..
         @param mo month of the DateAndTime.
         @param d day of the DateAndTime.
         @param y year of the DateAndTime.
         @return boolean valid or not
         public static boolean isValidDate(int mo, int d, int y)
         //your code goes here
              return true;
         Print time DateAndTime in military format.
         public void printMilitary()
         System.out.println( month + "/" + day + "/" + year + "\t"
                   + ( hour < 10 ? "0" : "" ) + hour + ":"
         + ( minute < 10 ? "0" : "" ) + minute);
         Formats DateAndTime for printing.
         @return String
         public String toString()
         return ( month + "/" + day + "/" + year + "\t"
                   + (( hour == 0 || hour == 12 ) ? 12 : hour % 12)
         + ":" + ( minute < 10 ? "0" : "" ) + minute
         + ":" + ( second < 10 ? "0" : "" ) + second
         + ( hour < 12 ? " AM" : " PM" ));
         Increments DateAndTime by one second.
         Hint: calls nextDay() if tick() results in going in to next day.
         public void tick()
              //Your code goes here
    second++;
    if (second >59)
         second = 0;
         minute++;
    if (minute > 59)
         minute = 0;
              hour++;
              if(hour >23)
         //      hour = 0;
         nextDay();
         Increments DateAndTime by one day.
         public void nextDay()
              day++;
              //your code goes here
    }//end class

    See java.util.Calendar
    and java.util.GregorianCalendar
    You can do all types of date validation with those classes.

  • Using ExecutorService class from java.util.concurrent package

    Dear java programmers,
    I have a question regarding the ExecutorService class from java.util.concurrent package.
    I want to parse hundreds of files and for this purpose I'm implementing a thread pool. The way I use the ExecutorService class is summarized below:
    ExecutorService executor = Executors.newFixedThreadPool(10);
            for (int i = 0; i < 1000; i++){
                System.out.println("Parsing file No "+i);
                executor.submit(new Dock(i));
            executor.shutdown();
            try {
                executor.awaitTermination(30, TimeUnit.SECONDS);
            } catch (InterruptedException ex) {
                ex.printStackTrace();
            executor.shutdownNow();However, the code snippet above creates all the 1000 threads (Dock objects) at once and loads them to the executor, and thus I'm worrying about memory leak. I haven't tested it on 1000 files yet but just on 50 small ones, and even if the program prints out "Parsing file No "+i 50 times at once, it executes normally the threads in the background.
    I guess the write way would be to keep the number of active/idle threads in the executor constant (lets say 20 if the thread pool's size is 10) and submit a new one whenever a thread has been finished or terminated. But for this to happen the program should be notified someway whenever a thread is done. Can anybody help me do that?
    thanks in advance,
    Tom

    Ok I found a feasible solution myself although I'm not sure if this is the optimum.
    Here's what I did:
            ExecutorService executor = Executors.newFixedThreadPool(10);
            Future<String> future0, future1, future2, future3, future4, future5, future6, future7, future8, future9;
            Future[] futureArray = {future0 = null, future1 = null, future2 = null, future3 = null, future4 = null, future5 = null,
            future6 = null, future7 = null, future8 = null, future9 = null};
            for (int i = 0; i < 10; i++){
                futureArray[i] = executor.submit(new Dock(i));
            }I created the ExecutorService object which encapsulates the thread pool and then created 10 Future objects (java.util.concurrent.Future) and added them into an Array.
    For java.util.concurrent.Future and Callable Interface usage refer to:
    [http://www.swingwiki.org/best:use_worker_thread_for_long_operations]
    [http://www.particle.kth.se/~lindsey/JavaCourse/Book/Part1/Java/Chapter10/concurrencyTools.html]
    I used a Future[] Array to make the code neater. So after that I submitted -and in this way filled up- the first 10 threads to the thread pool.
            int i = 9;
            while (i < 1000){
                for (int j = 0; j < 10; j++){
                    if (futureArray[j].isDone() && i < 999){
                        try{
                            i++;
                            futureArray[j] = executor.submit(new Dock(i));
                        } catch (ExecutionException ex) {
                            ex.printStackTrace();
                        } catch (InterruptedException ex) {
                            ex.printStackTrace();
                try {
                    Thread.sleep(100); // wait a while
                } catch(InterruptedException iex) { /* ignore */ }
            executor.shutdown();
            try {
                executor.awaitTermination(60, TimeUnit.SECONDS);
            } catch (InterruptedException ex) {
                ex.printStackTrace();
            executor.shutdownNow();
        }Each of the future[0-9] objects represents a thread in the thread pool. So essentially I'm check which of these 10 threads has been finished (using the java.util.concurrent.Future.isDone() method) and if yes I replenish that empty future[0-9] object with a new one.

  • Exception "not implemented for class oracle.jdbc.driver.T4CNumberAccessor"

    Hello I'm having some troubles dealing with 'java.sql.Date' I'm working with express edition database and I have three classes(different packages)
    1.Mapper
    2.Objects Class
    3.ConsoleTest
    I need to get an arraylist of objects, some of which contain dates, but when try to do it I get this exception
    "java.sql.SQLException: Invalid column type: getDate not implemented for class oracle.jdbc.driver.T4CNumberAccessor"
    Do you have any idea how I can implement the getDate method for this T4CNumberAccessor
    Here are the methods that I'm using
    1.Mapper
    public ArrayList<Object> getAllTaskAuctions(Connection con)
              ArrayList<Object> l1 = new ArrayList<Object>();
              String SQLString1 = "select * from taskauction natural join tasks";
    PreparedStatement statement=null;
    try
    //=== get taskauctions natural join tasks
    statement = con.prepareStatement(SQLString1);
    ResultSet rs = statement.executeQuery();
    while(rs.next())
    l1.add(new TaskAuction(rs.getInt(1), rs.getInt(2), rs.getInt(3),
    rs.getDate(4), rs.getDate(5), rs.getInt(6)));
    l1.add(new Task(rs.getInt(1), rs.getInt(2), rs.getString(3),
    rs.getString(4), rs.getString(5), rs.getString(6), rs.getInt(7)));
    catch (Exception exc)
    System.out.println("Fail in TaskAuctionMapper - getAllTaskAuctions");
    System.out.println(exc);
    return l1;
    2.ConsoleTest class
    Connection con;
         public Connection getConnection(){
              try{ 
         Class.forName("oracle.jdbc.driver.OracleDriver");
         con = DriverManager.getConnection(
         "jdbc:oracle:thin:@localhost:1521:XE", "Project", "123" );
         //username/password@[/]host[:port][service_name]
         catch (Exception e)
         {   System.out.println("fail in getConnection()");
         System.out.println(e); }
              return con;
         public static void main(String[] args) {
              ConsoleTest ct = new ConsoleTest();
              TaskAuctionMapper tam1 = new TaskAuctionMapper();
    ArrayList<Object> alt1 = tam1.getAllTaskAuctions(ct.getConnection());
    Iterator<Object> itr1 = alt1.iterator();
    while (itr1.hasNext())
    TaskAuction taskauct = (TaskAuction) itr1.next();
    //Problem, exception traced to TaskAuctionMapper
    System.out.println(
              "Task ID: " + taskauct.getTaskid()+ ", "+
              "StartDate: "+ taskauct.getStartdate()+", "+
              "User ID: " + taskauct.getUserid());
         }

    Found the answer, I shouldn't use integers as parameters of column index in the result set, but instead use String to mark the fields :)

  • Problems implementing abstract classes

    hello.
    this is james mcfadden. I am developing a multiplayer BlackJack card game in Java. the game consists of three programs: BlackJack.java, BlackJackServer.java and BlackJackClient.java (three 3 programs are shown below). i don't know how to implement abstract classes. i am trying to get the BlackJack.java program working with the BlackJackServer.java program. there should be "extends BlackJackServer" somewhere in the BlackJack.java program, but i don't know where.
    import javax.swing.*;
    public class BlackJack extends JPanel{
       public BlackJack(){
          //FlowLayout is default layout manager for a JPanel
          add(new JButton("Hit"));
          add(new JButton("Stay"));
          add(new JButton("New Game"));
       public static void main(String[] args){
          JFrame frame=new JFrame("BlackJack");
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.setSize(500,500);
          frame.setLocation(200,200);
          BlackJack bj=new BlackJack();
          frame.setContentPane(bj);
          frame.setVisible(true);
    import java.io.*;//Provides for system input and output through data streams, serialization and the file system
    import java.net.*;//Provides the classes for implementing networking applications
    import java.util.*;//Contains the collections framework, legacy collection classes, event model, date and time facilities, internationalization, and miscellaneous utility classes
    import java.awt.*;//Contains all of the classes for creating user interfaces and for painting graphics and images
    import javax.swing.*;//Provides a set of lightweight components that, to the maximum degree possible, work the same on all platforms
    public class BlackJackServer extends JFrame{
       private JTextArea jta=new JTextArea();//a text area for displaying text
       public static void main(String[] args){  
              new BlackJackServer();//invokes the constructor BlackJackServer()
       }//end main
       public BlackJackServer(){
          setLayout(new BorderLayout());//places the text area on the frame
          add(new JScrollPane(jta),BorderLayout.CENTER);//lays out a text area, arranging and resizing its components to fit in the centre region;and provides a scrollable view of a lightweight component
          setTitle("BlackJack Server");//Sets the title for this frame to the specified string
          setSize(500,300);//Resizes this component so that it has a width and a height
          setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//Sets the operation that will happen by default when the user closes this frame
          setVisible(true);//shows the frame
          try{
             ServerSocket serverSocket=new ServerSocket(8000);//creates a server socket
             jta.append("Server started at "+new Date()+'\n');//displays the current date in the text area
             Socket socket=serverSocket.accept();//listens for a connection request
             DataInputStream inputFromClient=new DataInputStream(socket.getInputStream());//creates a data input stream
             DataOutputStream outputToClient=new DataOutputStream(socket.getOutputStream());//creates a data output stream
             while(true){
                float bet=inputFromClient.readFloat();//receives bet from the client
                float doublebet=bet+bet;//computes double the bet
                outputToClient.writeFloat(doublebet);//sends double the bet back to the client
                jta.append("Bet received from client: "+bet+'\n');//displays the bet in the text area
                jta.append("Double the bet found: "+doublebet+'\n');//displays double the bet in the text area
             }//end while
          }//end try
          catch(IOException ex){
             System.err.println(ex);//displays an error message
          }//end catch
       }//end constructor
    }//end class BlackJackServer
    import java.io.*;//Provides for system input and output through data streams, serialization and the file system
    import java.net.*;//Provides the classes for implementing networking applications
    import java.awt.*;//Contains all of the classes for creating user interfaces and for painting graphics and images
    import java.awt.event.*;//Provides interfaces and classes for dealing with different types of events fired by AWT components
    import javax.swing.*;//Provides a set of lightweight components that, to the maximum degree possible, work the same on all platforms
    public class BlackJackClient extends JFrame{
       private JTextField jtf=new JTextField();//a text field for receiving text
       private JTextArea jta=new JTextArea();//a text area for displaying text
       private DataOutputStream toServer;//output stream
       private DataInputStream fromServer;//input stream
       public static void main(String[] args){
          new BlackJackClient();//invokes the constructor BlackJackClient()
       public BlackJackClient(){
          JPanel p=new JPanel();//holds the label and text field
          p.setLayout(new BorderLayout());//sets the layout of the content pane of this component by default
          p.add(new JLabel("Enter bet"),BorderLayout.WEST);//displays the bet and lays out a JLabel, arranging and resizing its components to fit in the western region
          p.add(jtf,BorderLayout.CENTER);//lays out the text field, arranging and resizing its components to fit in the centre region
          jtf.setHorizontalAlignment(JTextField.RIGHT);//Sets the horizontal alignment of the text to the right
          setLayout(new BorderLayout());//places the text area on the frame
          add(p,BorderLayout.NORTH);//lays out the text field, arranging and resizing its components to fit in the northern region
          add(new JScrollPane(jta),BorderLayout.CENTER);//lays out a text area, arranging and resizing its components to fit in the centre region;and provides a scrollable view of a lightweight component
          jtf.addActionListener(new ButtonListener());//invokes the ButtonListener class
          setTitle("BlackJack Client");//Sets the title for this frame to the specified string
          setSize(500,300);//Resizes this component so that it has a width and a height
          setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//Sets the operation that will happen by default when the user closes this frame
          setVisible(true);//shows the frame
          try{
             Socket socket=new Socket("localhost",8000);//creates a socket to connect to the server
             fromServer=new DataInputStream(socket.getInputStream());//creates an input stream to receive data from the server
             toServer=new DataOutputStream(socket.getOutputStream());//creates an output stream to send data to the server
          }//end try
          catch(IOException ex){
             jta.append(ex.toString()+'\n');//displays an error message
          }//end catch
       private class ButtonListener implements ActionListener{
          public void actionPerformed(ActionEvent e){
             try{
                float bet=Float.parseFloat(jtf.getText().trim());//gets the bet from the text field
                toServer.writeFloat(bet);//Converts the float argument to an int using the floatToIntBits method in class Float, and then writes that int value to the underlying output stream
                toServer.flush();//Flushes this output stream and forces any buffered output bytes to be written out
                float doublebet=fromServer.readFloat();//gets double the bet from the server
                jta.append("Bet is "+bet+"\n");//displays the bet in the text area
                jta.append("Double the bet received from the server is "+doublebet+'\n');//displays double the bet in the text area
             }//end try
             catch(IOException ex){
                System.err.println(ex);//displays an error message
             }//end catch
          }//end method
       }//end class
    }//end class BlackJackClient

    there should be "extends BlackJackServer" somewhere in the BlackJack.java programI very much doubt that.
    It's possible you might need to create a BlackJackServer object or something like that. But I don't see the point in subclassing it.

  • Where can I find the original code for class in Java API

    I am learning Java programming and wanted to see how professionals handel all cases. Can anyone tell me where I can find the original implementation code for classes in Java API? It would be a great help for me.

    the basic source is where you installed java in a file called java.src, its either in the main dir of one of the sub dirs ( mmm ), contains all the source code for all the classes in the api.

  • Super class for java Language

    which is the super class for java Language...
    this is an interview question .
    I SAY Object is the super class for java Language ...
    then he asked whether object class will extend ??
    i say Yes it will implectly extend ...
    then he whether each and every class will extend object
    i say yes ...
    then he asked multiple inheritance is possible in java ...
    i say no ...
    then how will say object class will extend in each and every class....
    hai friends if there is any solution tell mem
    by
    dhana

    which is the super class for java Language...
    this is an interview question .
    I SAY Object is the super class for java Language
    ge ...If you mean the ultimate parent of all classes, yes.
    (Although it's not the parent of interfaces.)
    then he asked whether object class will extend ??
    i say Yes it will implectly extend ...Not sure what is meant by "will object extend."
    then he whether each and every class will extend
    object
    i say yes ...Correct.
    then he asked multiple inheritance is possible in
    java ...
    i say no ...Correct. At least in the usual sense. When people talk about multiple inheritance, the usually mean multiple inheritance of implementation, such as C++ supports. The ability to implement more than one interface in Java is sometimes referred to as multiple inheritance of interface. I don't know if that term is in common use outside of Java.
    then how will say object class will extend in each
    and every class....
    hai friends if there is any solution tell memMultiple inheritance means that a class' ancestors are not all in a straight line to the ultimate parent. That is, not all ancestors are parents or children of each other.
    You are you father's son, and he is his father's son, and so on. So your grandfather is your ancestor, and so is your father. This is not MI.
    You also have a mother. She's neither an ancestor nor a descendant of your father. That's MI.

  • UML: Rel. with association class having attrib. Are they equivalent?

    Hi All, (and 1M Thanks.)
    Notation:
    _______________ : Bidirection
    1 : cardinality One
    *     : cardinality many
    ................: I draw it to graphically shown the association class AB
    Question 1: Is point 1 and 2 equivalent from the implementation perspective?
    Question 2: Likewise, Is point 3 and 4 equivalent from the implementation perspective?
    1.
    A (1) _______________ (1) B
    ............|
    ............|
    ............AB (association class with an attribute)
    2.
    A (1) _______________ (1) AB (1) _______________ (1) B
    3.
    A (*) _______________ (*) B
    ............|
    ............|
    ............AB (association class with an attribute)
    4.
    A (1) _______________ (*) AB (*) _______________ (1) B

    Association classes imposes that there should only be one connection between two instances, while there is no such limitation in the other case (your comparison between 3 and 4). But there probably won't be any difference between 1 and 2.

  • I'm trying to implement a class called Letter...

    Long story short, here's my Letter class:
    // Implements a class that holds the sender's name, the letter's body, and the recipient's name.
    public class Letter
    * Constructs a letter with a sender name and recipient and the letters first line of text.
    * @param from The letter's sender.
    * @param to The letter's recipient.
    public Letter(String from, String to)
    sender = from;
    recipient = to;
    body.concat("Dear ").concat(recipient).concat(":").concat("\n").concat("\n");
    * Adds a line to the body of the letter and skips a line.
    * @param line The line you want to add.
    public void addLine(String line)
    body.concat(line).concat("\n");
    // Closes the letter and returns the text of the entire letter.
    public String getText()
    body.concat("Sincerely, ").concat("\n").concat("\n").concat(sender);
    return body;
    private String sender;
    private String body;
    private String recipient;
    }with an output message of:
    java.lang.NoSuchMethodError: main
    Exception in thread "main"
    Process completed.
    And here's my tester class:
    public class LetterTester
    public static void main(String[] args)
    Letter departure = new Letter("John", "Mary");
    departure.addLine("I am sorry we must part.");
    departure.addLine("I wish you all the best.");
    String departureLetter = departure.getText();
    System.out.println(departureLetter);
    }with an output message of:
    Exception in thread "main" java.lang.NullPointerException
    at Letter.<init>(Letter.java:13)
    at LetterTester.main(LetterTester.java:5)
    Process completed.
    I'm not too sure what it means since I'm a beginner... This is part of my homework and I'm supposed to get this tester class to ultimately print out:
    Dear John:
    I am sorry we must part.
    I wish you all the best.
    Sincerely,
    Mary.
    And it obviously hasn't worked... What am I doing wrong?
    Edited by: TheAlliedCentralAxis on Mar 7, 2008 7:40 PM

    Exception in thread "main" java.lang.NullPointerExceptionThis means you are trying to dereference some variable or expression whose value is null. To find out which variable or expression look down the stack trace until you come to the first line that refers to your code.
    at Letter.<init>(Letter.java:13)
    at LetterTester.main(LetterTester.java:5)So the problem occurs on line 13 of Letter.java. By "dereferencing" I mean using the "dot" operator or array access square brackets. So in foo.bar() and baz[i] both foo and baz will cause an NPE if they are null. You can check for this (if you are in doubt) by printing their values:
    System.out.println("About to call bar() foo=" + foo);
    foo.bar();By the way note how the println() argument is built up using + for String concatenation. I could have written this as:
    String msg = "Checking to see if foo causes the NPE: " + "About to call bar() foo=" + foo + "!";
    System.out.println(msg);
    foo.bar();This is a common way to perform String concatenation.
    Edited by: pbrockway2 on Mar 8, 2008 4:58 PM
    Too slow...

  • Association Rules - dmardemo.java - DisplayAssociationRules method

    Hi, friends!
    I'm making some changes in the sample Java demo for the Association Rules - dmardemo.java. I've created another method which contains the name of the model just created before and in this same method, I call the method to display the association rules detected:
    public static void restoreRules(String modelNome) throws JDMException {
    m_modelName = modelNome;
    model = (AssociationModel)m_dmeConn.retrieveObject(
    m_modelName, NamedObject.model);
    displayAssociationRules(model);
    In another class, which is a GUI, I'm trying to call that method to restore all the rules found in the mining process and display them in a jTable Swing component. For this, I've tried to adapt the main method (displayAssocationRules) to do this, as follows:
    public static Object displayAssociationRules(AssociationModel model)
    throws JDMException {
    // DISPLAY TOP-10 ASSOCIATION RULES
    Object[] obj = new Object[5];
    int contador = 0;
    // 1. Set order by confidence DESC, support DESC
    OraRulesFilter filter = (OraRulesFilter) m_filterFactory.create();
    filter.setOrderingCondition(
    new RuleProperty[] { RuleProperty.confidence, RuleProperty.support},
    new SortOrder[] { SortOrder.descending, SortOrder.descending }
    // 2. Set to return the first 10 rules only
    filter.setMaxNumberOfRules(10);
    // 3. Retrieve rules
    Collection rules = model.getRules(filter);
    Iterator iRules = rules.iterator();
    while( iRules.hasNext() )
    OraAssociationRule rule = (OraAssociationRule) iRules.next();
    obj[0] = rule.getRuleIdentifier();
    //System.out.print( "Rule " + rule.getRuleIdentifier() + ": " );
    Itemset antecedent = rule.getAntecedent();
    //obj[1] = antecedent.getItems();
    Object[] ante_items = antecedent.getItems();
    // sort the items in antecedent to produce deterministic order of items
    TreeSet sortedSet = new TreeSet();
    for(int i = 0; i < obj.length; i++)
    sortedSet.add(ante_items);
    obj[1] = ante_items;
    Iterator sortedI = sortedSet.iterator();
    /*while(sortedI.hasNext())
    System.out.print(sortedI.next() + " ");*/
    Itemset consequent = rule.getConsequent();
    Object[] cons_items = consequent.getItems();
    obj[2] = cons_items;
    obj[3] = m_df.format(rule.getSupport());
    obj[4] = m_df.format(rule.getConfidence());
    /*System.out.println("==> " + cons_items[0] + " (support=" +
    m_df.format(rule.getSupport()) + ", confidence=" + m_df.format(rule.getConfidence()) + ")" );*/
    return obj;
    Some parts of the old code are present in that for you to compare what I've done. However, it's not working. What should I do to see the rules generated in the process in a jTable?
    Regards
    Luis

    As you can see in the code above, I've split the code into two parts. However, a problem is happening when I try to restore the rules to the GUI.
    "Exception in thread "AWT-EventQueue-0" javax.datamining.JDMIllegalArgumentException: The required argument objectName is null. Supply a non-null value."
    It says that I'm not passing any parameters to the method. But, as you can see, in the first method I've created, I took the name of the model and transfers it for the method displayAssociationRules as a AssociationModel objet.
    In the GUI, in an event for the button "Restore Rules", I've put this code below:
    String modelo = Principal.getModelName(); // where Principal is the main GUI class for the execution of the process.
    dmardemo.restoreRules(modelo);// I call the method in the dmardemo class to restore the rules having a String (modelo) as its parameter. That's when the problem happens. Is the argument really null, as the error message says?
    Regards
    Luis

  • What is the alternative of Transfer Support class in java 1.5

    I have Drag And Drop Application built in java 1.6.
    My application supports Drag-Drop between Swing Components (Tree,Table) and Native file system to Swing Component.
    I have requirement to implement Drag And Drop  in java 1.5.
    May i know the alternative of Transfer support class?
    Implementing Drag And Drop using java 1.6 was easy. Will It require to put additional efforts to implement Drag And Drop in java 1.5. ?

    There is no Transfer class in Java 6. There are a number of classes with 'transfer' in the name, but none of them is 'Transfer'. So what class are you referring to?
    One thing you might do while you mull that over, is check the since tag for the class. If it does not have one listed, try the since tag for the package. Yes, that requires RTFM.

  • Is there any method which reflects the names of classes of java?

    is there any method with which dynamically we can get all the packages's name along with their classes of java(specially core classes of java)?if not how can we do that?

    The resource from which the Java VM loads the classes is considered to be implementation dependent. It may be class files or jar files contained in a file system hierarchy, or some kind of remote database. The now defunct Microsoft VM used a database repository that was able to reside on a remote class server within a network domain.
    Unfortunately, Sun did not design a class resource service interface with a "list resources" function, only a "get resource" function. You can get the class resource for any named class, but you cannot list packages or classes within a package or at the root level.
    This is further complicated by the fact that there is no such thing as an "installed package" as Java does not define any package installation system. The packages available to any runtime instance of the JVM is defined by the classpath properties passed from the OS. Different JVM instances can have completely different sets of available packages because they were passed different classpath values by the OS.
    If you know the class resource of the runtime environment, then you could create a subclass of the sun.misc.URLClassPath class and add to it methods that will list packages and classes found within a package using the interface of that known class resource.
    Most runtime environments use a standard hierarchical file system to hold jar and class files. A subclass of sun.misc.URLClassPath could use the java.io.File class to traverse the file system classpath paths in search of package directories and class files (Watch out for recursive directory links).
    The root packages can be obtained from the three levels of classpath paths in the System properties used by the JVM:     "sun.boot.class.path"
         "java.ext.dirs"
         "java.class.path"The collection of file system paths obtained from these properties would be searched for the names of the root level package directory names. Just remember that this will only work in a runtime environment that only uses this kind of class resource. If you run this where some other resource is also used, you will not see all of the packages available to that JVM.
    One note of caution: A single directory can hold package directories, jar files, and class files that belong to a specific package, but the package may include other package directories, jar files, and class files that are contained in other directories. Pieces of a single package may be strewn throughout the file system. The only way to find them all is to scan all of the classpath paths for that same package name. The directory does not define the package, it only provides more content for that package.
    I hope you find this of some use.

  • How to implement route cipher using java?

    Hi guys,,,
    I really got a headache solving how to implement route cipher using java lang,,i already got the concept but i really dont get how to implement it using java actually i want to make a presentation of how route cipher works using "adobe flash" but first i will implement it using java coz flash actionscripts are closer to java lang.
    Hope you could post some examples or ideas...i would really appreciate it!
    thank you so much...

    just add an action listener (either keypressed or keytyped) to the frame that you want to record. I did this in NetBeans in about 2 seconds. I can simplify it if you need. As for loging it just write the characters to a file output stream.
    public class test extends javax.swing.JFrame {
        /** Creates new form test */
        public test() {
            initComponents();
        /** This method is called from within the constructor to
         * initialize the form.
         * WARNING: Do NOT modify this code. The content of this method is
         * always regenerated by the Form Editor.
        // <editor-fold defaultstate="collapsed" desc=" Generated Code ">
        private void initComponents() {
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
            addKeyListener(new java.awt.event.KeyAdapter() {
                public void keyTyped(java.awt.event.KeyEvent evt) {
                    formKeyTyped(evt);
            pack();
        // </editor-fold>
        private void formKeyTyped(java.awt.event.KeyEvent evt) {
            System.out.println(evt.getKeyChar());
         * @param args the command line arguments
        public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new test().setVisible(true);
        // Variables declaration - do not modify
        // End of variables declaration
    }

  • Using List Class in java.awt / java.util ?

    have a program that:
    import java.util.*;
    List list = new LinkedList();
    list = new ArrayList();
    ... read a file and add elements to array
    use a static setter
    StaticGettersSetters.setArray(list);
    next program:
    import java.awt.*;
    public static java.util.List queryArray =
    StaticGettersSetters.getArray();
    If I don't define queryArray with the package and class, the compiler
    gives an error that the List class in java.awt is invalid for queryArray.
    If I import the util package, import java.util.*; , the compiler
    gives an error that the list class is ambiguous.
    Question:
    If you using a class that exists in multiple packages, is the above declaration of queryArray the only way to declare it ?
    Just curious...
    Thanks for your help,
    YAM-SSM

    So what you have to do is explicitly tell the compiler which one you really want by spelling out the fully-resolved class name:
    import java.awt.*;
    import java.sql.*;
    import java.util.*;
    public class ClashTest
        public static void main(String [] args)
            java.util.Date today    = new java.util.Date();
            java.util.List argsList = Arrays.asList(args);
            System.out.println(today);
            System.out.println(argsList);
    }No problems here. - MOD

  • I have been getting java.lang.ClassNotFoundException: ZeroApplet.class and java.lang.ClassNotFoundException: JavaToJS.class crashes with JRE version 1.6.0_26-b03-384-10M3425 VM executing a Java Applet. Is Apple aware of this problem? No longer supported?

    My web page uses a Java Applet to allow my visitors to replay chess games; the Chess Viewer Deluxe applet was written by Nikolai Pilafov some time ago and has been working properly for some time (until recently). I don't monitor this part of my site regularly so I am not sure when it began to fail. On his web site [http://chesstuff.blogspot.com/2008/11/chess-viewer-deluxe.html] he has a link to check LiveConnect object functionality (which fails for OBJECT tags). His recommendation is to "seek platform specific support which might be available from the JRE developers for your platform".
    I have been getting java.lang.ClassNotFoundException: ZeroApplet.class and java.lang.ClassNotFoundException: JavaToJS.class crashes with JRE version 1.6.0_26-b03-384-10M3425 VM executing a Java Applet. Until I checked the LiveConnect object functionality, I was unable to identify the source of the console error messages. This does seem to be the smoking gun.
    Is Apple aware of this problem? Are these classes no longer supported? Has anyone else had this problem? You can attempt to recreate the problem locally by going to my web page: http://donsmallidge.com/DonSmallidgeChess.html
    Thanks in advance for any help you can provide!
    Abbreviated Java Console output:
    Java Plug-in 1.6.0_26
    Using JRE version 1.6.0_26-b03-384-10M3425 Java HotSpot(TM) 64-Bit Server VM
    load: class ZeroApplet.class not found.
    java.lang.ClassNotFoundException: ZeroApplet.class
        at sun.applet.AppletClassLoader.findClass(AppletClassLoader.java:211)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
        at sun.applet.AppletClassLoader.loadClass(AppletClassLoader.java:144)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
        at sun.applet.AppletClassLoader.loadCode(AppletClassLoader.java:662)
        at sun.applet.AppletPanel.createApplet(AppletPanel.java:807)
        at sun.plugin.AppletViewer.createApplet(AppletViewer.java:2389)
        at sun.applet.AppletPanel.runLoader(AppletPanel.java:714)
        at sun.applet.AppletPanel.run(AppletPanel.java:368)
        at java.lang.Thread.run(Thread.java:680)
    load: class JavaToJS.class not found.
    java.lang.ClassNotFoundException: JavaToJS.class
        at sun.applet.AppletClassLoader.findClass(AppletClassLoader.java:211)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
        at sun.applet.AppletClassLoader.loadClass(AppletClassLoader.java:144)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
        at sun.applet.AppletClassLoader.loadCode(AppletClassLoader.java:662)
        at sun.applet.AppletPanel.createApplet(AppletPanel.java:807)
        at sun.plugin.AppletViewer.createApplet(AppletViewer.java:2389)
        at sun.applet.AppletPanel.runLoader(AppletPanel.java:714)
        at sun.applet.AppletPanel.run(AppletPanel.java:368)
        at java.lang.Thread.run(Thread.java:680)

    I just went up to check the LiveConnect object functionality page AND IT WORKED THIS TIME! I must confess, this is very mysterious. I will do some more checking and reply here if I can determine why it is working now (and more importantly, why it didn't work before).

Maybe you are looking for

  • Particular data in a report, on the basis of the values (0, 1) of a dashboa

    hi User should be able to see the particular data in a report, on the basis of the values (0, 1) of a dashboard prompt. For e.g. if the user selects 0 then current years data should be filtered out and if the user selects 1 then rest all years data s

  • Error while pairing a resilient pair of Database Firewall

    Hello, I've downloaded and installed an Audit Vault Server and two Database Firewall 12.1.1 in three virtual machines using VMware workstation 9. I had no problem whatsoever with the installation of either of them and I was able to link both firewall

  • Deployment Problem in 9.0.2.0.1 in XP

    I have installed Oracle9ias(9.0.2.0.1) sucessfully on XP.After that when i try to deploy my application i am gettring followin error: Deployment failed: Nested exception Root Cause: null; nested exception is: java.lang.NullPointerException. null; nes

  • Debit note & debit memo

    what is the debit note & debit memo of customer. what is the difference between debit note and debit memo.  my client issuing debit note for royalty customer  how we will do in sap what configuration which t code using in sap. if issuing debit note c

  • Mercedes car ipod connector will not navigate itunes

    Hi, My ipod and iphone no longer work properly with any Mercedes ipod connector. I cannot navigate itunes on the phone or ipad - the screen says "Connected to an ipod accessory" I can navigate audible or other apps but not itunes. This is a new probl