I have made one program that work on hash map.
I want to do one thing.
All the tuples(row) with defined quasi identifier location having value >=k will be moved from map m1 to asMap and it also removed from m1.
So at last i am printinf the output of each map.but it doesn't give me correct output.
So please tell me where the mistake is done?
In new_dataset.csv file contains the following value
12,-8000,251,36,456
14,5000,215,22,741
2,16520,45,841,65
32,1200,361,32,45
My code is as follows
import java.io.*;
import java.util.*;
public class csv {
public static void main(String args[]) throws IOException
{
Map <Integer,String[]> m1 = new HashMap<Integer,String[]>();
Map<Integer,String[]> asMap = new HashMap<Integer,String[]>();
/*======================================================================*/
int q,i1,loc[],min[],max[],len[];
DataInputStream din = new DataInputStream(System.in);
System.out.println("Enter No. of Quasi Idenifier =");
q=Integer.parseInt(din.readLine());
loc= new int[q];
min=new int[q];
max=new int[q];
len=new int[q];
//flagp=new int[q];
for(i1=0;i1<q;i1++)
{
System.out.println("Enter "+i1+"th Quasi identifier location :");
loc[i1]=Integer.parseInt(din.readLine());
min[i1]=Integer.MAX_VALUE;
max[i1]=Integer.MIN_VALUE;
len[i1]=0;
}
System.out.println("Enter the value of K=");
String n = din.readLine();
int k = Integer.parseInt(n);
BufferedReader CSVFile = new BufferedReader(new FileReader("new_dataset.csv"));
String dataRow = CSVFile.readLine();
int count=1;
while(dataRow!=null)
{
String dataArray[] = dataRow.split(",");
m1.put(count, dataArray);
count++;
dataRow=CSVFile.readLine();
}
int a=m1.size();
//System.out.println(a);
for(int j = 1; j<=a; j++)
{
String[] aa1=m1.get(j);
for(int p=0;p<q;p++)
System.out.print(aa1[loc[p]]+"\t");
for(int p=0;p<q;p++)
{
if( min[p] > Integer.parseInt(aa1[loc[p]]))
{
min[p] = Integer.parseInt(aa1[loc[p]]);
}
if( max[p] < Integer.parseInt(aa1[loc[p]]))
{
max[p] = Integer.parseInt(aa1[loc[p]]);
}
}
System.out.println();
}
for(int p=0;p<q;p++)
{
if(min[p]<0)
{
len[p]=Integer.toString(min[p]).length()-1;
if(len[p]>Integer.toString(max[p]).length())
len[p]=Integer.toString(min[p]).length();
}
else
{
len[p]=Integer.toString(min[p]).length();
if(len[p]>Integer.toString(max[p]).length())
len[p]=Integer.toString(min[p]).length();
}
System.out.println(p+"min "+min[p]);
System.out.println(p+"max "+max[p]);
System.out.println(p+"len "+len[p]);
}
int am[]=new int[a];
int row[]=new int[a];
int remove[] = new int[a];
int flagp[] = new int[a];
int f1[] = new int[a];
for(int t=0;t<a;t++){am[t]=0; row[t]=0;remove[t]=0;flagp[t]=0;f1[t]=0;}
for(int j=1;j<=a;j++)
{
int cnt1=0;
if(am[j-1]==1)
{
break;
}
else
{
for(int p=j+1;p<=a;p++)
{
//System.out.println("hello");
String[] aa2 = m1.get(j);
String[] aa3 = m1.get(p);
//System.out.println("Hello "+aa2[loc[1]]+" and "+aa3[loc[1]]);
int h=0;
int cnt=0;
while(h<q)
{
//System.out.println("inside while "+h);
if(aa2[loc[h]].equals(aa3[loc[h]]))
{
cnt++;
}
h++;
}
if(cnt==q)
{
remove[j-1]=1;
remove[p-1]=1;
cnt1++;
am[p-1]=1;
//System.out.println("Both are equal at "+j+" "+p+" "+" count ="+cnt);
row[j-1]=cnt1+1;
//System.out.println("row "+row[j-1]+" ="+cnt1);
}
}
System.out.println("value of row "+j+" = "+row[j-1]);
if(row[j-1]>=k)
{
for(int p1 = 0;p1<a;p1++)
{
if(remove[p1]==1 && flagp[p1]==0)
{
flagp[p1]=1;
System.out.println("remove= "+(p1+1));
f1[p1]=p1+1;
asMap.put(p1+1,m1.get(p1+1));
//m1.remove(p1+1);
}
}
//m1.remove(2);
}
}
}
for(int jj=0;jj<f1.length;jj++)
{
if(f1[jj]!=0)
m1.remove(f1[jj]);
//System.out.println("The Value is = "+f1[jj]);
}
for(Map.Entry<Integer, String[]> mapEntry : m1.entrySet())
{
int key = mapEntry.getKey();
String[] aa1=mapEntry.getValue();
System.out.print("Key=> "+key);
for(int p=0;p<aa1.length;p++)
{
System.out.print("\t"+aa1[p]+"\t");
}
System.out.println();
}
System.out.println("==============================================================");
//=========================================================================================
for(Map.Entry<Integer, String[]> mapEntry : asMap.entrySet())
{
int key = mapEntry.getKey();
String[] aa1=mapEntry.getValue();
System.out.print("Key=> "+key);
for(int p=0;p<aa1.length;p++)
{
System.out.print("\t"+aa1[p]+"\t");
}
System.out.println();
}
}
}
Now i have printed bot the map.but it doesn't give correct output.
I want all the rows who satisfies condition >=k into asMap, but it is not working properly.Also i am checking the row with same Quasi identifie.
thank you.