小编ken*_*nji的帖子

用动态规划实现文本对齐

我想了解动态规划的概念,通过对MIT OCW课程在这里.关于OCW视频的解释很棒,但我觉得在我将解释实现到代码之前我并不理解它.在实施时,我会参考这里的讲义中的一些注释,特别是注释的第3页.

问题是,我不知道如何将一些数学符号转换为代码.这是我实施的解决方案的一部分(并认为它是正确实现的):

import math

paragraph = "Some long lorem ipsum text."
words = paragraph.split(" ")

# Count total length for all strings in a list of strings.
# This function will be used by the badness function below.
def total_length(str_arr):
    total = 0

    for string in str_arr:
        total = total + len(string)

    total = total + len(str_arr) # spaces
    return total

# Calculate the badness score for a word.
# str_arr is assumed be send …
Run Code Online (Sandbox Code Playgroud)

algorithm dynamic-programming python-3.x

20
推荐指数
2
解决办法
2万
查看次数

如何用spring-rabbit配置RabbitMQ连接?

我正在按照本指南学习如何使用spring-rabbitRabbitMQ.但是在本指南中,RabbitMQ配置是默认配置(localhost服务器,凭证为guest/guest).如果我想用ip地址和凭证连接到远程RabbitMQ,我该怎么办?我不知道在我的应用程序中将这些信息设置在何处.

rabbitmq spring-rabbit spring-amqp spring-boot spring-rabbitmq

19
推荐指数
1
解决办法
2万
查看次数

Mockito抛出异常

@Test(expectedExceptions=DataAccessException.class)
public void testUpdateSubModuleOrderDateExceptionCheck() {
    //some code to initialize//
    UserSubModuleDao userSubModuleDao = mock(UserSubModuleDao.class);
    userModuleServiceImpl.setUserSubModuleDao(userSubModuleDao);
    UserSubModule userSubModule=new UserSubModule();
    UserSubModuleId userSubModuleId=new UserSubModuleId();
      when(userSubModuleDao.findById(any(UserSubModuleId.class),eq(false))).thenThrow(DataAccessException.class);

    userModuleServiceImpl.updateSubModuleOrder(data, moduleSysId, userId);
Run Code Online (Sandbox Code Playgroud)

我想为代码覆盖抛出Db异常.它的工作如果我给出预期的例外:Exception.class但不是DataAccessException.class

原始类中的方法如下:

public void updateSubModuleOrder(Long[] data, Long moduleSysId, Long userId) {
    try {

        for (int i = 0; i < data.length; i++) {
            SubModule subModule=new SubModule();
            subModule.setSubModuleId(data[i]);
            UserSubModuleId userSubModuleId = new UserSubModuleId();
            userSubModuleId.setSubModuleId(subModule);
            userSubModuleId.setUserId(userId);
            userSubModuleId.setUserModuleId(moduleSysId);
            UserSubModule userSubmodule = new UserSubModule();
            userSubmodule = userSubModuleDao.findById(userSubModuleId,
                    false);
catch (DataAccessException ewmsDataExp) {
        LOGGER.error(
                "Database Exception while updateSubModuleOrder …
Run Code Online (Sandbox Code Playgroud)

java testng exception spring-mvc mockito

18
推荐指数
3
解决办法
5万
查看次数

如何在Spring Boot应用程序中使用spring-rabbit处理JSON消息?

这是我的代码段。

但是,运行应用程序时出现以下错误消息。

2017-02-28 17:16:35.931  WARN 11828 --- [cTaskExecutor-1] s.a.r.l.ConditionalRejectingErrorHandler : Execution of Rabbit message listener failed.

org.springframework.amqp.rabbit.listener.exception.ListenerExecutionFailedException: Listener threw exception
    at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.wrapToListenerExecutionFailedExceptionIfNeeded(AbstractMessageListenerContainer.java:872) ~[spring-rabbit-1.7.0.RELEASE.jar:na]
    at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.doInvokeListener(AbstractMessageListenerContainer.java:782) ~[spring-rabbit-1.7.0.RELEASE.jar:na]
    at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.invokeListener(AbstractMessageListenerContainer.java:702) ~[spring-rabbit-1.7.0.RELEASE.jar:na]
    at …
Run Code Online (Sandbox Code Playgroud)

java spring spring-rabbit spring-amqp spring-boot

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

由于OSGi包依赖性问题,无法启动RCP应用程序

我们同时使用spring-web,并spring-websocket在我们的RCP应用程序,它们都通过转换成捆P2-Maven的插件.下面是我们的应用程序的MANIFEST.MF文件.

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Todo
Bundle-SymbolicName: com.example.e4.rcp.todo;singleton:=true
Bundle-Version: 1.0.0.qualifier
Bundle-Vendor: EXAMPLE
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Require-Bundle: org.apache.commons.logging;bundle-version="1.2.0",
 org.springframework.spring-aop;bundle-version="4.3.3",
 org.springframework.spring-beans;bundle-version="4.3.3",
 org.springframework.spring-context;bundle-version="4.3.3",
 org.springframework.spring-core;bundle-version="4.3.3",
 org.springframework.spring-expression;bundle-version="4.3.3",
 org.springframework.spring-web;bundle-version="4.3.3",
 org.eclipse.e4.ui.css.swt;bundle-version="0.12.0",
 org.eclipse.e4.ui.css.swt.theme;bundle-version="0.10.0",
 org.eclipse.e4.ui.workbench.addons.swt;bundle-version="1.2.0",
 org.eclipse.e4.ui.workbench.renderers.swt;bundle-version="0.13.0",
 org.eclipse.e4.ui.workbench.swt;bundle-version="0.13.0",
 org.eclipse.swt;bundle-version="3.104.1",
 org.eclipse.e4.ui.di;bundle-version="1.1.0",
 org.eclipse.e4.core.services;bundle-version="2.0.100",
 org.eclipse.osgi.services;bundle-version="3.5.100",
 org.eclipse.e4.core.di.annotations;bundle-version="1.5.0",
 org.springframework.spring-websocket;bundle-version="4.3.2",
 org.springframework.spring-messaging;bundle-version="4.3.2",
 javax.inject;bundle-version="1.0.0",
 javax.annotation;bundle-version="1.2.0",
 org.apache.tomcat.embed.tomcat-embed-core;bundle-version="8.5.4",
 org.apache.tomcat.embed.tomcat-embed-websocket;bundle-version="8.5.4"
Run Code Online (Sandbox Code Playgroud)

当我启动应用程序时,它会弹出以下错误:

 !SESSION 2016-11-10 09:48:03.750 -----------------------------------------------
 eclipse.buildId=unknown
 java.version=1.8.0_101
 java.vendor=Oracle Corporation
 BootLoader constants: OS=win32, ARCH=x86_64, WS=win32, NL=en_US
 Framework arguments:  -product com.example.e4.rcp.todo.product clearPersistedState
 Command-line arguments:  -product com.example.e4.rcp.todo.product -data > :\Users\wangzen\Console_prototype/../runtime-todo.product -dev > ile:C:/Users/wangzen/Console_prototype/.metadata/.plugins/org.eclipse.pde.core/to> o.product/dev.properties -os win32 …
Run Code Online (Sandbox Code Playgroud)

java rcp osgi osgi-bundle

6
推荐指数
1
解决办法
505
查看次数

如何通过maven-failsafe-plugin运行基于Spring Boot的应用程序的集成测试?

我有一个基于spring-boot的应用程序,并且pom.xml文件配置如下。

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.example</groupId>
    <artifactId>demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>demo</name>
    <description>Demo project for Spring Boot</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.7.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <classifier>exec</classifier>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-failsafe-plugin</artifactId>
                <version>2.20.1</version>
                <configuration>
                    <includes>
                        <include>**/IT*.java</include>
                        <include>**/*IT.java</include>
                        <include>**/*ITCase.java</include>
                    </includes>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>integration-test</goal>
                            <goal>verify</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins> …
Run Code Online (Sandbox Code Playgroud)

java integration-testing maven-failsafe-plugin spring-boot spring-boot-maven-plugin

6
推荐指数
2
解决办法
7234
查看次数

java.nio.file.Files.isWriteable与java.io.File.canWrite()不一致

我有Java代码执行以下操作:

  1. 使用ZIP扩展创建临时空文件 File.createTempFile()
  2. 删除它File.delete()(我们真的只想生成一个临时文件名)
  3. com.google.commons.io.ByteStreams.copy()使用OutputSupplier给定相同文件名的新文件将"模板"ZIP文件复制到同一路径
  4. 使用TrueZIP 7.4.3修改ZIP存档(删除目录)

在特定系统上,第4步一致失败FsReadOnlyArchiveFileSystemException - "This is a read-only archive file system!"(参见http://java.net/projects/truezip/lists/users/archive/2011-05/message/9)

调试TrueZIP代码,我注意到以下内容:

  • 在上述任何步骤之间,此文件上没有打开的文件句柄,特别是在步骤4之前
  • 使用File.canWrite()检查同一文件而不是NIO以完全相同的时间(使用调试器)返回,它表明它是可写的

以下是您在调试器表达式列表中看到的内容:

fn => "C:/myworkdir/temp/myfile4088293380313057223tmp.zip"
java.nio.file.Files.isWritable(java.nio.file.Paths.get(fn)) => false
new java.io.File(fn).canWrite() => true
Run Code Online (Sandbox Code Playgroud)

使用JDK 1.7.04

有任何想法吗?

java nio temporary-files writable truezip

5
推荐指数
3
解决办法
3624
查看次数

SWT是Eclipse RCP应用程序中的依赖项是不可避免的吗?

比方说,我有一个基于e4平台的应用程序,使用纯JavaFX而不是SWT作为渲染技术,就像这个.它是否间接需要一些SWT库?毕竟,Eclipse平台基于SWT.我理解它是正确的吗?我看不到来自Dependencies选项卡的任何直接依赖关系.

在此输入图像描述

java eclipse swt javafx eclipse-rcp

5
推荐指数
1
解决办法
76
查看次数

如何通过快捷方式在IdeaVim中打开类文件?

我正在使用IntelliJ IDEA和IdeaVim.通常我可以通过快捷方式Ctrl+ 打开任何类文件N而不使用IdeaVim,这非常方便.但是当我切换到IdeaVim时,快捷方式在Normal Mode和中都不起作用Insert Mode.我也无法在以下对话框中找到设置选项. 在此输入图像描述

如果有人能说清楚这个问题,我真的很感激.:)

intellij-idea ideavim

4
推荐指数
1
解决办法
1830
查看次数

即使我没有明确使用React,为什么还需要导入React语句?

我有一个React应用程序,以下是JavaScript代码

import React from 'react';
import ReactDOM from 'react-dom';

const App = function(){
  return <div>Hi</div>
}

ReactDOM.render(<App />, document.querySelector('.container'));
Run Code Online (Sandbox Code Playgroud)

HTML文件如下.

<!DOCTYPE html>
<html>
  <head>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="/style/style.css">
    <link rel="stylesheet" href="https://cdn.rawgit.com/twbs/bootstrap/48938155eb24b4ccdde09426066869504c6dab3c/dist/css/bootstrap.min.css">
    <script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyAq06l5RUVfib62IYRQacLc-KAy0XIWAVs"></script>
  </head>
  <body>
    <div class="container"></div>
  </body>
  <script src="/bundle.js"></script>
</html>
Run Code Online (Sandbox Code Playgroud)

我不明白的问题是,如果我删除import React from 'react',它将显示如下的错误消息.

未捕获的ReferenceError:未定义React

但我没有在任何地方明确地在我的代码中使用React,为什么它会显示这样的消息.谁能告诉我引擎盖下发生了什么?

更新:这个问题不完全相同的问题,因为我在我的代码中只有一个单独的组件,不涉及任何父组件.

javascript reactjs

4
推荐指数
1
解决办法
625
查看次数