📄 zipcodeserverimpl.java
字号:
import java.io.*;
// It is assumed that this object is directly called as follows:
//
// java yourRMI ZipCodeServerImpl registryhost resigstryport servicename
//
// Therefore, it does not contain main: new object creation, binding
// (with SimpleRegistryServer), etc., is done via yourRMI.
public class ZipCodeServerImpl
implements ZipCodeServer
{
ZipCodeList l;
// this is a constructor.
public ZipCodeServerImpl()
{
l=null;
}
// When the following method is called, marshalled data
// should be sent to this remote object, and reconstructed.
public void initialise(ZipCodeList newlist)
{
l=newlist;
}
// Basic function: look up a city name, and return its zipcode.
public String find(String request)
{
// Search the list.
ZipCodeList temp = l;
while (temp != null && !temp.city.equals(request))
temp = temp.next;
// The result is either null or we've found a match.
if (temp==null)
return null;
else
return temp.ZipCode;
}
// The following short method should send the marshalled
// whole list to the client site. The main challenge is coding
// the skeleton.
public ZipCodeList findAll()
{
return l;
}
// The following method prints at the server site.
public void printAll()
{
ZipCodeList temp=l;
while (temp !=null)
{
System.out.println
("city: "+temp.city+", "+
"code: "+temp.ZipCode+"\n");
temp = temp.next;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -