小编Dun*_*nes的帖子

双原语类型数据的意外行为

我想了解Java double类型如何在Java 中将其值存储在内存中.当我运行以下代码时,我得到意外的输出:

public static void main(String[] args)  {

    float a = 1.5f;
    float b= 0.5f;
    double c= 1.5;
    double d = 0.5;

    float a1 = 1.4f;
    float b1= 0.5f;
    double c1= 1.4;
    double d1 = 0.5;

    System.out.println(" a- b is " + (a-b));
    System.out.println(" c- d is " + (c-d));
    System.out.println("a1-b1 is " + (a1-b1));
    System.out.println("c1-d1 is " + (c1-d1));
Run Code Online (Sandbox Code Playgroud)

}

输出:

 a- b is 1.0
 c- d is 1.0
a1-b1 is 0.9
c1-d1 is 0.8999999999999999

为什么c1-d1 …

java floating-point

7
推荐指数
1
解决办法
859
查看次数

无法使用Sigma.js显示任何图形

我想在Web界面上可视化大型网络图.经过几天的搜索,我决定使用Sigma.js,因为它看起来很简单并且与HTML5兼容.

问题是我无法在Sigma.js网页上显示任何图形示例,即使我使用作者在Sigma.js主页上的最小代码.我甚至用右键单击视图代码复制粘贴整个网页,但是徒劳(如此).我已将所有必需的文件粘贴到简单的.html文件所在的文件夹中(css文件,js文件,甚至是示例所需的.gexf文件),但我只得到一个带有黑色矩形的页面,仅此而已.图表不会显示.我究竟做错了什么?

我是否需要首先构建sigma.js文件,正如作者在GitHub中的库的代码库中提到的那样?我需要这个工具来显示图形(我将动态地提供数据)但我甚至无法尝试一些简单的代码!我甚至按照那个"指南"做了每一步,但我什么也做不了.

Webstudio:Microsoft Expression Web 4和操作系统:Windows 8 Pro(我尝试在IE10,FF17和Chrome 23中打开网页).

javascript graph sigma.js

7
推荐指数
2
解决办法
6241
查看次数

使用Java启用PDF快速Web视图?

如何使用Java代码或任何开源Java库启用PDF的快速Web视图属性?

注意:这也称为"线性化PDF".

java pdf itext

7
推荐指数
1
解决办法
2330
查看次数

是否可以在Eclipse中定义自己的错误?

有没有办法为Eclipse定义自己的编译错误?如果没有实例化某些对象,我想抛出编译错误.

准确地告诉你我想要做的事情:

我有一个Assets类,它包含所有资源(图像,声音等)的空变量和LoadingScreen初始化所有这些资源对象的类.如果我将一个资源添加到Assets类但不添加到LoadingScreen类,它将搞乱整个应用程序.如果Assets类中的变量也没有初始化,我想在eclipse中看到错误LoadingScreen.

这可能吗?

java eclipse

7
推荐指数
1
解决办法
176
查看次数

在@Rule中并行化测试执行

我想重用一些集成测试来进行负载测试.我实现了一个由注释参数化的规则:

@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface Parallel {

    int invocations() default 1;

    int rampUpTime() default 0;
}
Run Code Online (Sandbox Code Playgroud)

在我的规则实现中,评估注释并设置一个语句,该语句具有如下的evaluate方法:

@Override
public void evaluate() throws Throwable {
    ScheduledExecutorService exe = Executors.newScheduledThreadPool(invocations);

    for (int i = 0; i < invocations; i++) {
        ScheduledFuture<?> scheduledFuture = exe.schedule(new Runnable() {

            @Override
            public void run() {
                try {
                    invocated++;

                    // Request test = Request.method(description.getTestClass(), description.getMethodName());
                    // new JUnitCore().run(test);

                    statement.evaluate();
                } catch (Throwable e) {
                    e.printStackTrace();
                }
            }
        }, i * rampUpTime, this.timeUnit);
        futures.add(scheduledFuture);
    }
}
Run Code Online (Sandbox Code Playgroud)

因此,evaluate …

java junit junit-rule

7
推荐指数
1
解决办法
452
查看次数

为什么我可以使用一个DES密钥加密数据并成功解密另一个DES密钥?

我尝试使用pyDes和Crypto.Cipher.DES模块实现DES算法.我发现了一个问题,当我用82514145密钥加密然后解密密码93505044我可以检索解密的文本.我发现256个键表现得像这样.这违反了密码学.我的代码如下:

    from Crypto.Cipher import DES
    plain_text = 'asdfghij'
    print 'plain Text: ', plain_text

    des = DES.new('82514145', DES.MODE_ECB)
    cipher_text = des.encrypt(plain_text)
    print 'the cipher text is ', cipher_text

    des = DES.new('93505044', DES.MODE_ECB)
    print 'the decrypted text is: ', des.decrypt(cipher_text)
Run Code Online (Sandbox Code Playgroud)

输出是:

plain Text:  asdfghij

the cipher text is  @?Z????

the decrypted text is:  asdfghij
Run Code Online (Sandbox Code Playgroud)

我的工作有什么不对吗?我也用pyDes得到了相同的结果.

python cryptography des encryption-symmetric pycrypto

7
推荐指数
1
解决办法
1378
查看次数

通用方法触发类型安全错误 - 为什么?

在讨论这个问题的解决方案时,我想出了以下代码,它有一些编译器警告.一个警告是:

Type safety: The expression of type Test.EntityCollection needs unchecked conversion to conform to Test.EntityCollection<Test.Entity>

我不完全理解为什么出现这个警告.通过传入一个Class<M>类型并声明方法返回EntityCollection<M>,为什么我没有做足以说服(Java 7)编译器返回正确的类型?

static class Entity {
}

static class EntityCollection<E extends Entity> {

    private EntityCollection(HashMap<?, E> map) {
    }

    public static <T extends HashMap<?, M>, M extends Entity> EntityCollection<M> getInstance(
            Class<T> mapType, Class<M> entityType)
            throws ReflectiveOperationException {

        T map = mapType.getConstructor().newInstance();
        return new EntityCollection<M>(map);
    }
}

public static void main(String[] args) throws Exception {
    // both compiler warnings are …
Run Code Online (Sandbox Code Playgroud)

java generics

7
推荐指数
1
解决办法
126
查看次数

如何用空格填充整数?

如何格式化整数值而不导致零?我尝试使用十进制格式,但我无法达到确切的结果:

DecimalFormat dFormat=new DecimalFormat("000");

mTotalNoCallsLbl.setText(""+dFormat.format(mTotalNoOfCallsCount));
mTotalNoOfSmsLbl.setText(""+dFormat.format(mTotalNoOfSmsCount));
mSelectedNoOfCallsLbl.setText(""+dFormat.format(mSelectedNoOfCallLogsCount));
mSelectedNoOfSmsLbl.setText(""+dFormat.format(mSelectedNoOfSmsCount));
Run Code Online (Sandbox Code Playgroud)

我得到这些输出:

500
004
011
234
Run Code Online (Sandbox Code Playgroud)

但我想要这些:

500
  4
 11
234
Run Code Online (Sandbox Code Playgroud)

我的问题是如何用空格替换零?

java int formatting

7
推荐指数
1
解决办法
6726
查看次数

Firestore事务失败,并显示"Transaction failed all retries"

我正在运行一个非常简单的Firestore事务,它会在写入之前检查文档是否存在,如果没有.

(用例是注册用户名 - 如果尚未注册,则当前用户可以获取用户名)

这是相关Flutter代码的片段:

DocumentReference usernameDocRef =
    Firestore.instance.collection(_USERNAMES).document(username);

await Firestore.instance.runTransaction((transaction) async {
  var snapshot = await transaction.get(usernameDocRef);
  if (!snapshot.exists) {
    transaction.set(usernameDocRef, {
      _UsernamesKey.userid: _user.id,
    });
  }
});
Run Code Online (Sandbox Code Playgroud)

这是因为"事务失败所有重试"异常而失败.

根据Firestore文档,可能会出现故障,原因有两个:

  • 该事务包含写操作后的读操作.在任何写操作之前必须始终进行读操作.
  • 该事务读取在事务之外修改的文档.在这种情况下,事务会自动再次运行.该事务重试次数有限.

我不认为我会触发其中任何一个.有什么建议?

transactions firebase flutter google-cloud-firestore

7
推荐指数
1
解决办法
1091
查看次数

如何在从网络加载图像时修复Listview滚动jank

我使用Image.network为列表中的每个项目加载图像,使用以下代码:

Image getEventImageWidget(AustinFeedsMeEvent event) {
return event.photoUrl.isNotEmpty ?
          Image.network(
            event.photoUrl,
            width: 77.0,
            height: 77.0,
          ) : Image.asset(
            'assets/ic_logo.png',
            width: 77.0,
            height: 77.0,
          );
}
Run Code Online (Sandbox Code Playgroud)

当我向上和向下滚动时,列表有时会在加载图像时挂起.有没有办法在背景线程上加载图像?我该怎么做才能帮助修复滚动性能?

flutter

7
推荐指数
2
解决办法
996
查看次数