package abc;
class DependencyDataCollection
{
private int sNo;
private String sessionID;
private int noOfDependency;
private int noOfRejection;
private int totalValue;
/** Creates a new instance of DependencyDataCollection */
public DependencyDataCollection(int sNo, String sessionID, int noOfDependency, int noOfRejection, int totalValue)
{
this.sNo = sNo;
this.sessionID = sessionID;
this.noOfDependency = noOfDependency;
this.noOfRejection = noOfRejection;
this.totalValue = totalValue;
}
public int getSNo()
{
return sNo;
}
public String getSessionID()
{
return sessionID;
}
public int getNoOfDependency()
{
return noOfDependency;
}
public int getNoOfRejection()
{
return noOfRejection;
}
public int getTotalValue()
{
return totalValue;
}
}
public class DependencyStack {
LinkedList lList;
/** Creates a new instance of DependencyStack */
public DependencyStack()
{
lList = new LinkedList();
}
public void add(int sNo, String sessionID, int noOfDependency, int noOfRejection, int totalValue)
{
lList.add(new DependencyDataCollection(sNo,sessionID,noOfDependency,noOfRejection,totalValue));
}
public int size()
{
return lList.size();
}
public void show()
{
for(int i=0;i<lList.size();i++)
{
DependencyDataCollection ddc = (DependencyDataCollection)lList.get(i);
System.out.println(ddc.getSNo()+" "+ddc.getSessionID()+" "+ddc.getNoOfDependency()+" "+ddc.getNoOfRejection()+" "+ddc.getTotalValue());
}
}
public int returnIndexOfSession(String sessionID)
{
DependencyDataCollection ddc = null;
for(int i=0;i<lList.size();i++)
{
ddc = (DependencyDataCollection)lList.get(i);
if(ddc.getSessionID().equals(sessionID))
break;
}
return ddc.getSNo();
}
public static void main(String args[])
{
DependencyStack ds = new DependencyStack();
ds.add(1,"a",0,0,0);
ds.add(2,"b",0,0,0);
ds.show();
//System.out.println(ds.returnIndexOfSession("a"));
// DependencyDataCollection ddc = new DependencyDataCollection(1,"a",0,0,0);
// System.out.println(ds.indexOf(ddc));
}
}
This is a simple Linked List program in java which is using inbuilt linkedlist class from java.util package. The linked list is used to store different amount of data using DependencyDataCollection Class..
Now my question is
1) Please evaluate this program, and temme am i respecting all java concepts like private member access,which i have done, etc..
2) I am facing problem to find the indexOf a particular session.
For e.g. Node 1 contains 1,"a",0,0,0...............Node 2 contains 2,"b",0,0,0
Now i wanted to find the indexOf the node which is containing one of the data as "b" or "a". What could be the shortest inbuilt method which can do so, as i have made a function named "public int returnIndexOfSession(String sessionID)" which makes use of for loop, i find this very time consuming.. Is there any other way out..
Please evaluate and guide as i am a newbie in java.