import java.util.ArrayList;
import javax.swing.JOptionPane;
public class ClientList
{
private ArrayList<Client> clientData;
private final String NEW_LINE = "\n";
private int cursor;
//manager mode
public ClientList ( )
{
clientData = new ArrayList<Client> ( );
buildClientList ( );
if (clientData.size ( ) != 0)
cursor = 0; //not empty, place cursor at the start of the vector
else
cursor = -1; //empty
}
//manager mode
public void buildClientList ( )
{
String textStream = new FileOperations ( ).readFile ( );
JOptionPane.showMessageDialog (null, "client file loaded");
//build the client list
parseTextStream (textStream);
}
//build a vector from data read from a xml text file
public void parseTextStream (String textStream)
{
int len = textStream.length ( );
Client newClient = null;
while (len != 0)
{
//get a line that ends with "\n"
int pos = textStream.indexOf (NEW_LINE);
if (pos == -1)
break;
String aLine = textStream.substring (0,pos);
//the rest of the text stream
textStream = textStream.substring (pos+1);
len = textStream.length ( );
aLine = aLine.trim ( );
pos = aLine.indexOf ("<client>");
if (pos != -1)
{
newClient = new Client ( ); //start of a client
continue; //skip the rest of the loop
}
pos = aLine.indexOf ("</client>");
if (pos != -1) //end of a client
{
clientData.add(newClient); //append to the vector
continue;
}
pos = aLine.indexOf ("<name>");
if (pos != -1)
{
//extract what's between the start and end tags
String newName = extractData ("<name>",aLine,"</name>");
newClient.setName (newName);
continue;
}
pos = aLine.indexOf ("<id>");
if (pos != -1)
{
String newId = extractData ("<id>",aLine, "</id>");
newClient.setId (newId);
continue;
}
pos = aLine.indexOf ("<phone>");
if (pos != -1)
{
String newPhone = extractData ("<phone>",aLine, "</phone>");
newClient.setPhone (newPhone);
continue;
}
} //end while
} //end parseTextStream
public String extractData (String startTag, String aLine, String endTag)
{
//remove start tag
aLine = aLine.substring (startTag.length ( ));
//look for end tag
int pos = aLine.indexOf (endTag);
//found
if (pos != -1)
return (aLine.substring (0,pos)).trim ( );
else // end tag not found, return the rest of the line
return aLine.trim ( );
}
public int getSize ( )
{
return clientData.size ( );
}
public int getCursor ( )
{
return cursor;
}
public Client getCurrent ( )
{
return clientData.get (cursor);
}
public Client getNext ( )
{
if (cursor != -1)
{
cursor = (cursor + 1) % clientData.size ( ); //wrap from rear to front
return clientData.get (cursor);
}
else
return null;
}
public Client getBack ( )
{
if (cursor != -1)
{
if (cursor == 0)
cursor = clientData.size ( ) -1; //wrap from front to rear
else
cursor--;
return clientData.get (cursor);
}
else
return null;
}
public void setCurrent (Client aClient)
{
clientData.set(aClient,cursor); //overwrite the current client
}
public void resetCursor ( )
{
if (cursor != -1)
cursor = 0;
}
public String toString ( )
{
String outString = "<clients>" + NEW_LINE;
int count = clientData.size ( ); //count of clients
for (int i = 0; i < count; i++)
outString += clientData.get (i);
outString += ("</clients>" + NEW_LINE);
return outString;
}
}
getting following error
.\ClientList.java:164: error: no suitable method found for set(Client,int)
clientData.set(aClient,cursor); //overwrite the current client
^
method List.set(int,Client) is not applicable
(argument mismatch; Client cannot be converted to int)
method AbstractList.set(int,Client) is not applicable
(argument mismatch; Client cannot be converted to int)
method ArrayList.set(int,Client) is not applicable
(argument mismatch; Client cannot be converted to int)
1 error
Tool completed with exit code 1
ali11 -1 Light Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.