简体   繁体   English

创建用户ID(0001,0002等)CORBA / Java

[英]Creating user id (0001, 0002, etc) CORBA/Java

I have created an app in CORBA which allows users to register and stores the information only while it is running. 我在CORBA中创建了一个应用程序,允许用户仅在运行时注册和存储信息。 I have to assign a unique ID to each user who registers. 我必须为每个注册用户分配一个唯一的ID。 The unique ID has to be in the format 0001 for the first user, 0002 for the second user, etc. Having looked online I cannot find much on figuring out how to assign these numbers in this format. 唯一ID必须是第一个用户的格式0001,第二个用户的0002,等等。看过网络后,我找不到很多关于如何以这种格式分配这些数字的方法。

Unique ID is assigned to each customer. 为每个客户分配唯一ID。 The unique ID is based on a counter which is maintained by the server. 唯一ID基于由服务器维护的计数器。 The first registration will be assigned the ID 0001, but represented as a string. 第一次注册将被分配ID 0001,但表示为字符串。

My servant code is as follows: 我的仆人代码如下:

public class AccountServant implements AccountManagerOperations{ 公共类AccountServant实现AccountManagerOperations {

double topupBalance = 0;
int credit = 0;
int uid = 0;

public void topup(double amount){
        topupBalance = topupBalance+amount;
        credit = credit +1;
    }

    public double getBalance(){
        return topupBalance;
    }

    public int getUniqueID(){
        DecimalFormat decimalFormat = new DecimalFormat("0000");
        uid = uid +1;
        return uid;
}

public static Hashtable hashtable = new Hashtable();

public static ORB orb;

public AccountServant (org.omg.CORBA.ORB orb){

    this.orb=orb;
}

public void storeAccountDetails (AnyTopUpAccount.KamaradAccountDetails myKamaradAccountDetails){
    hashtable.put(myKamaradAccountDetails.name, myKamaradAccountDetails);

}

public Any getAccountDetails (String name, AnyHolder myKamaradAccountDetails){

Any anyDD = orb.create_any();

KamaradAccountDetails tempKamaradAccDetails = (KamaradAccountDetails)hashtable.get(name);
KamaradAccountDetailsHelper.insert(anyDD, tempKamaradAccDetails);
myKamaradAccountDetails.value = anyDD;

return anyDD ;
}

} }

int is a 32-bit integral type that doesn't allow leading zeros. int是32位整数类型,不允许前导零。 You could use the integer type for the unique ID and then format to display the id 您可以使用整数类型作为唯一ID,然后格式化以显示ID

private static final DecimalFormat decimalFormat = new DecimalFormat("0000");
...

public String getUniqueIDText(){
    return decimalFormat.format(uid);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM