Search code examples
javavectorcosine-similarity

How to pass vector to different class?


How can a vector pass to another class? I want to compare vector 1, which is in User.java and vector 2, in Case.java by using cosine similarity.

User.java

    JButton btnNewButton = new JButton("Process");
        btnNewButton.setBounds(360, 296, 89, 23);
        contentPane.add(btnNewButton);
        btnNewButton.addActionListener(new ActionListener(){
        public void actionPerformed(ActionEvent e){
        String a=Integer.toString(comboBox.getSelectedIndex()+1);
        String b=Integer.toString(comboBox_1.getSelectedIndex()+1);
        String day=Integer.toString(comboBox_2.getSelectedIndex()+1);                         
        Vector<String> myVector=new Vector <String> (3,2);
        myVector.add(a);
        myVector.add(b);
        myVector.add(day);
        myVector.add(valuesOfCheckBox);
        String holder;
        holder=myVector.toString();

        Case ca= new Case();
        try {
            ca.addPlace(holder);
            LoginGUI um= new LoginGUI();
            um.setVisible(true);

        } catch (Exception e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }

Case.java

    public void addPlace( int[] h) { 

        int vec1[] =  h;
        int vec2[] = [2,1,3,2]; 

        double cos_sim = cosine_similarity(vec1,vec2); 
    }

Solution

  • I solved it by using this way:-

    User.java

     ArrayList<Integer> myVector=new ArrayList<Integer>(); 
                            myVector.add(a);
                            myVector.add(b);
                            myVector.add(day);
                            if(chckbxLei.isSelected())
                            {
                                myVector.add(lei);
                            }
                            if(chckbxAdv.isSelected())
                            {
                                myVector.add(adv);
                            }
    
                            Case ca= new Case();
                            try {
                                ca.addPlace(myVector);
                                LoginGUI um= new LoginGUI();
                                um.setVisible(true);
    
                            } catch (Exception e1) {
                                // TODO Auto-generated catch block
                                e1.printStackTrace();
                            }
    

    Case.java

     public void addPlace( ArrayList<Integer> h) throws Exception { 
                int[] vec1 =  h.stream().mapToInt(t -> t).toArray();
                int vec2[] = [2,1,3,2];
                double cos_sim = cosine_similarity(vec1,vec2); 
        }