0

Good Day, I have a project to do where I have to create a database with Redis bit arrays data type and write a Java code to access the database with a GUI drop down menu. I was able to implement the code with sorted set commands but the specification I was given was with bit arrays data type and commands. From my understanding bit arrays operate on strings. Please how would I go about this? Kindly find attached my project below and images of the gui.

/*
 * 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.
 */
//MAIN PROJECT
package cen414dat;
import java.util.HashMap;
import java.util.Map;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.event.ActionEvent;

import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
import javax.swing.Icon;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.Tuple;

/**
 *
 * @author ariel
 */
public class CEN414Dat {
    static HashMap<Double, String> redisData = new HashMap<Double, String>();
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        Jedis jedis = new Jedis("localhost");
        Info igr= new Info();
        
         if (jedis.zcard("igr") == null || jedis.zcard("igr") == 0) {
            jedis.zadd("igr", (Map) Info.map);}
         
         for(Tuple t: jedis.zrangeByScoreWithScores("igr", 0, 100)){
        System.out.println(t.getScore());
        redisData.put(t.getScore(),t.getElement());
        }
         
        ArrayList<String> states = new ArrayList<String>();
         for (Map.Entry m : redisData.entrySet()) {
             states.add((String)m.getValue());
         }
         
         String[] statesArray = new String[states.size()];
         states.toArray(statesArray);

        

        JComboBox<String> stateList = new JComboBox<>(statesArray);
        stateList.addItemListener(new Handler());
        
        // stateList.addItemListener(null);

// add to the parent container (e.g. a JFrame):
        JFrame jframe = new JFrame();
        JLabel item1 = new JLabel("IGR STATISTICS FOR H1 2020");
        item1.setToolTipText("Done by AJ");
        jframe.add(item1);
        jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        jframe.setLayout(new FlowLayout());
        jframe.setSize(275,180);
        jframe.setVisible(true);
        
        jframe.add(stateList);
        
        

// get the selected item:
       // String selectedBook = (String) stateList.getSelectedItem();
       

        // check whether the server is running or not
        System.out.println("Server is running: " + jedis.ping());
        //getting the percentage for each state
       
//        
        // storing the data into redis database
        System.out.println(jedis.zrange("igr", 0, 100));
        
        for (Map.Entry m : Info.map.entrySet()) {
            System.out.println(m.getKey() + " " + m.getValue());

            //jedis.zadd("outofschool", M)
        }
    }
    private static class Handler implements ItemListener{
//
//        @Override
//        public void actionPerformed(ActionEvent e) {
//           JOptionPane.showMessageDialog(null, String.format("%s", e.getActionCommand()));
//        }

        @Override
        public void itemStateChanged(ItemEvent e) {
             for (Map.Entry m : redisData.entrySet()) {
                 if(e.getItem().toString() == m.getValue()&& e.getStateChange() == 1){
                     
                     JOptionPane.showMessageDialog(null, m.getKey() , "Value in billions", 1);
                     System.out.println(m.getKey());
                     break;
                     
         
        }
   
        }
        
    }
        
        
        
    }
    
}
/*
 * 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 cen414dat;
import static com.sun.org.apache.xalan.internal.lib.ExsltDynamic.map;
import java.util.HashMap;

/**
 *
 * @author ariel
 */
//Info project
public class Info {
    public static HashMap<Double, String> map = new HashMap<Double, String>();
    public Info(){
    
    // IGR statistics in each state
    map.put(4.27,"Q1 Abia");
    map.put(1.92,"Q2 Abia");
    map.put(1.63,"Q1 Adamawa");
    map.put(2.12,"Q2 Adamawa");
    map.put(12.00,"Q1 Akwa-Ibom");
    map.put(4.26,"Q2 Akwa-Ibom");
    map.put(4.53,"Q1 Anambra");
    map.put(5.01,"Q2 Anambra");
    map.put(4.39,"Q1 Bauchi");
    map.put(1.37,"Q2 Bauchi");
    map.put(2.88,"Q1 Bayelsa");
    map.put(2.51,"Q2 Bayelsa");
    map.put(3.62,"Q1 Benue");
    map.put(1.73,"Q2 Benue");
    map.put(3.59,"Q1 Borno");
    map.put(1.79,"Q2 Borno");
    map.put(3.99,"Q1 CrossRiver");
    map.put(4.06,"Q2 CrossRiver");
    map.put(19.3,"Q1 Delta");
    map.put(11.5,"Q2 Delta");
    map.put(4.65,"Q1 Ebonyi");
    map.put(1.69,"Q2 Ebonyi");
    map.put(9.51,"Q1 Edo");
    map.put(4.50,"Q2 Edo");
    map.put(1.65,"Q1 Ekiti");
    map.put(1.55,"Q2 Ekiti");
    map.put(5.95,"Q1 Enugu");
    map.put(6.31,"Q2 Enugu");
    map.put(20.7,"Q1 FCT");
    map.put(14.5,"Q2 FCT");
    map.put(11.1,"Q1 Gombe");
    map.put(2.68,"Q2 Gombe");
    map.put(3.08,"Q1 Imo");
    map.put(4.65,"Q2 Imo");
    map.put(1.91,"Q1 Jigawa");
    map.put(1.10,"Q2 Jigawa");
    map.put(10.2,"Q1 Kaduna");
    map.put(4.36,"Q2 Kaduna");
    map.put(7.85,"Q1 Kano");
    map.put(9.66,"Q2 Kano");
    map.put(2.10,"Q1 Katsina");
    map.put(3.44,"Q2 Katsina");
    map.put(2.21,"Q1 Kebbi");
    map.put(2.18,"Q2 Kebbi");
    map.put(5.42,"Q1 Kogi");
    map.put(2.01,"Q2 Kogi");
    map.put(7.22,"Q1 Kwara");
    map.put(2.14,"Q2 Kwara");
    map.put(114.00,"Q1 Lagos");
    map.put(90.5,"Q2 Lagos");
    map.put(3.03,"Q1 Nasawara");
    map.put(2.87,"Q2 Nasawara");
    map.put(1.90,"Q1 Niger");
    map.put(2.12,"Q2 Niger");
    map.put(14.6,"Q1 Ogun");
    map.put(9.07,"Q2 Ogun");
    map.put(8.16,"Q1 Ondo");
    map.put(5.42,"Q2 Ondo ");
    map.put(7.02,"Q1 Osun");
    map.put(1.94,"Q2 Osun");
    map.put(7.35,"Q1 Oyo");
    map.put(10.4,"Q2 Oyo");
    map.put(7.20,"Q1 Plateau");
    map.put(2.20,"Q2 Plateau");
    map.put(36.6,"Q1 Rivers");
    map.put(27.9,"Q2 Rivers");
    map.put(1.58,"Q1 Sokoto");
    map.put(3.02,"Q2 Sokoto");
    map.put(2.35,"Q1 Taraba");
    map.put(1.71,"Q2 Taraba");
    map.put(1.96,"Q1 Yobe");
    map.put(1.96,"Q2 Yobe");
    map.put(3.57,"Q1 Zamfara");
    map.put(3.52,"Q2 Zamfara");
  
}
}

Image of the GUI

6
  • Hi Anjie, Do you mean Redis "bit arrays" or "bytearray"? When I look at Redis docs, I don't see anything about "bit arrays". Commented Feb 20, 2021 at 3:49
  • Hi again, Here's another idea. It might help to experiment with Redis with a simple Java client first. Learn to store and retrieve data. Do these experiments only with Java code and debugger or print to console. After you know how to do that, then you will be ready to build your GUI. Good luck! Commented Feb 20, 2021 at 3:50
  • Thank you @devdanke. Bit arrays is a redis data type. My main issue is how to store data in bit arrays Commented Feb 20, 2021 at 4:33
  • Do you mean bit maps? Perhaps you can link to a description of the data type you mean. Commented Feb 20, 2021 at 5:42
  • Yes @tgdavies I mean bitmaps Commented Feb 20, 2021 at 13:58

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.