Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/187.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Java领域中使用BigInteger?_Java_Android_Realm_Biginteger - Fatal编程技术网

在Java领域中使用BigInteger?

在Java领域中使用BigInteger?,java,android,realm,biginteger,Java,Android,Realm,Biginteger,Realm Java不支持BigInteger,因此以下类: public class Bonus extends RealmObject { String thebonus; BigInteger bonus; ... public BigInteger getBonus() { return bonus; } public void setBonus(BigInteger newBonus) { this.bonus = newBon

Realm Java不支持
BigInteger
,因此以下类:

public class Bonus extends RealmObject {
   String thebonus;
   BigInteger bonus;

   ...

   public BigInteger getBonus() {
    return bonus;
   }

   public void setBonus(BigInteger newBonus) {
    this.bonus = newBonus;
   }
}
不支持类型为“java.math.biginger”的字段“value”中的结果。

我使用的领域如下:
bnsInitial.setBonus(新的BigInteger(“0”)
或类似于
intx=bns.getBonus().compareTo(新的BigInteger(“0”))的东西例如

有没有一种方法可以使用Realm获得
biginger
?这些值有可能定期超过
Long
限制,这就是我使用
biginger
的原因。
谢谢

我的建议是:

  • 使用
    String
    byte[]
    作为大整数的领域表示,并在这些类型和
    biginger
    之间进行动态转换
  • 如果要在
    RealmObject
    中缓存
    biginger
    对象,请使用
    @Ignore
    注释告知领域基础结构不要尝试传递它
大概是这样的:

public class Bonus extends RealmObject {
   byte[] thebonus;

   @Ignore
   BigInteger bonus;

   public BigInteger getBonus() {
       if (bonus == null) {
           bonus = new BigInteger(thebonus);
       } 
       return bonus;
   }

   public void setBonus(BigInteger newBonus) {
       bonus = newBonus;
       thebonus = BigInteger.toByteArray();
   }
}
使用
byte[]
比使用
String
效率更高,因为转换速度更快。。。对于足够大的整数。(以10为基数和以2为基数^N之间的文本二进制转换将需要较长的乘法和除法。)


免责声明:这只是基于阅读。我从未使用过Realm。

我的建议是:

  • 使用
    String
    byte[]
    作为大整数的领域表示,并在这些类型和
    biginger
    之间进行动态转换
  • 如果要在
    RealmObject
    中缓存
    biginger
    对象,请使用
    @Ignore
    注释告知领域基础结构不要尝试传递它
大概是这样的:

public class Bonus extends RealmObject {
   byte[] thebonus;

   @Ignore
   BigInteger bonus;

   public BigInteger getBonus() {
       if (bonus == null) {
           bonus = new BigInteger(thebonus);
       } 
       return bonus;
   }

   public void setBonus(BigInteger newBonus) {
       bonus = newBonus;
       thebonus = BigInteger.toByteArray();
   }
}
使用
byte[]
比使用
String
效率更高,因为转换速度更快。。。对于足够大的整数。(以10为基数和以2为基数^N之间的文本二进制转换将需要较长的乘法和除法。)


免责声明:这只是基于阅读。我从未使用过Realm。

这仅仅是将
biginger
转换为
String
,然后将其传递给
setBonus()
方法(在重构方法和类以使用
String
而不是
biginger
之后),将其保存到Realm中,然后使用
getBonus()
字符串
转换为
大整数
并返回它?还是我遗漏了什么?谢谢。。。关键的
@Ignore
注释。。。如果将
biginger
缓存在
Bonus
对象中。这仅仅是将
biginger
转换为
String
的问题,例如将其传递给
setBonus()
方法(在重构方法和类以使用
String
而不是
biginger
之后),将其保存到域,然后让
getBonus()
String
转换为
biginger
并返回它?还是我遗漏了什么?谢谢。。。关键的
@Ignore
注释。。。如果在
Bonus
对象中缓存
biginger