私はユーザーとチャンネルを含むチャットプログラムを持っています。私の次のクエストは、1人のユーザーがいるチャンネルの一覧を取得することです。これはどのように行う必要がありますか?Hashtable、Arraylistを使用しています。彼らからの情報の取得
ChatFrontImpl:ここ
は今のようにコードされているprivate Hashtable<String, ArrayList<String>> channels = new Hashtable<String, ArrayList<String>>();
private ArrayList<Client> clients;
public synchronized boolean registerClient(Client client, String password) throws RemoteException {
if(!u.logIn(client.findName(), password)){
System.out.println("Wrong username or password!");
return false;
}
if (!clients.contains(client)) {
try {
clients.add(client);
updateJlist();
System.out.println(client.findName() + " registered.");
}
catch (Exception e){
System.out.println("error in method registerClient(): " + e);
}
return true;
}else
return false;
}
public void connectChannel(String username, String channel) throws RemoteException{
if(isUserRegistered(username)){
if (!channels.containsKey(channel)) {
String message = "User " + username + " entered the channel";
channels.put(channel, new ArrayList<String>());
channels.get(channel).add(username);
notifyChannelSystem(channel, "SYSTEM", message);
notifySelf(username, "Write /? for avaliable commands");
}
else{
if(channels.get(channel).contains(username)){
}
else {
channels.get(channel).add(username);
String message = "User " + username + " just entered the channel";
notifyChannelSystem(channel, "SYSTEM", message);
}
}
}
}
あなたは変数の定義が含まれるようにあなたの質問を展開することができます**カナル**してください。 ** kanal **を実際に** channel **にする必要がある場合、プログラムは意味があります。 –
ああ、コードは通常ノルウェー語ですが、私は翻訳しました(明らかにその一部です)。変数はkanal ofcと書かれているどこでもチャンネルでなければなりません:) – sindrem
変数を修正してメソッドをvoidに変更しました。本当に返す必要はありません。 – sindrem