小编pep*_*uch的帖子

使用apache-poi自动调整excel评论

我们有很多由apache poi生成的excel报告.其中一些包含标题中的注释.由于许多报告,我们希望创建用于添加注释的通用解决方案.我们注意到可以通过以下代码将注释添加到单元格中:

public static void addComment(final Workbook workbook, final Sheet sheet, final Cell cell, final Row row,
        final String comment) {

    final CreationHelper factory = workbook.getCreationHelper();

    final Drawing drawing = sheet.createDrawingPatriarch();

    final ClientAnchor anchor = factory.createClientAnchor();
    anchor.setCol1(cell.getColumnIndex());
    anchor.setCol2(cell.getColumnIndex() + 3);
    anchor.setRow1(row.getRowNum());
    anchor.setRow2(row.getRowNum() + 5);

    final Comment cellComment = drawing.createCellComment(anchor);
    final RichTextString richText = factory.createRichTextString(comment);
    cellComment.setString(richText);
    cell.setCellComment(cellComment);
}
Run Code Online (Sandbox Code Playgroud)

我们还注意到注释框大小可以使用列/行索引设置 - 这是我们的主要问题,因为如果第一列有100px而第二列有1000px,那么注释宽度将是1000px.这是我们的问题 - 是否有可能使用apache poi设置带像素的注释大小而不是列/行索引?或者也许有一些方法可以自动计算apache poi的评论大小?

apache-poi

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

无法在JAX-RS服务中注入@ApplicationScoped bean

我已经创建了JAX-RS服务,我想在其中注入一个应用程序范围的bean.问题是没有注入豆子.这是怎么造成的,我该如何解决?

JAX-RS服务:

@Path("room")
public class RoomService {

    @Inject
    GameController gc;

    public RoomService() {}

    @Path("create")
    @GET
    @Produces("application/json")
    public String create() {
        Room r = new Room();
        gc.addRoom(r); // gc is null
        return r.toJson();
    }
}
Run Code Online (Sandbox Code Playgroud)

应用程序作用域bean

import java.util.ArrayList;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Named;
import pepuch.multuplayergameserver.entity.Game;
import pepuch.multuplayergameserver.entity.Room;

@Named
@ApplicationScoped
public class GameController {

    private Game game;

    public GameController() {
        this.game = new Game(new ArrayList<Room>());
    }

    public boolean addRoom(Room room) {
        if (!game.getRooms().contains(room)) {
            return game.getRooms().add(room);
        }

        return false;
    }

}
Run Code Online (Sandbox Code Playgroud)

jax-rs java-ee cdi

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

Junit/Mockito - 等待方法执行

在我的应用程序中,我使用观察者模式进行某些操作,我想在单元测试中测试它们.问题是我不知道如何使用junit/mockito /其他东西测试观察者.有帮助吗?

例如,这是我的单元测试:

@Before
public void setUp() throws IOException, Exception {
    observer = new GameInstanceObserver(); // observable (GameInstance) will call update() method after every change
    GameInstance.getInstance().addObserver(observer); // this is observable which is updated by serverService
}

@Test(expected = UserDataDoesntExistException.class)
public void getRoomUserData_usingNullKey_shouldThrowUserDataDoesntExist() throws InterruptedException, UserDataDoesntExistException {
    serverService.createRoom("exampleRoom"); // this operation is asynchronous and updates GameInstance data (as I wrote before GameInstance is Observable)
    Thread.sleep(400); // how to do it in better way?

    GameInstance gi = (GameInstance) observer.getObservable();
    assertTrue(gi.getRoom("exampleRoom").getRoomId().equals("exampleRoom"));
}
Run Code Online (Sandbox Code Playgroud)

我想不 …

java junit android unit-testing mockito

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

计算使用 GROUP BY 的 HQL 结果

我有一个 hql 查询,我需要以某种方式对它们进行分组。所以这个查询看起来几乎是这样的:

SELECT a1,a2,a3
FROM tablename
GROUP BY a1,a2,a3;
Run Code Online (Sandbox Code Playgroud)

我想计算这个查询的结果,但不使用子查询(据我所知,HQL 不能从子查询中选择):

/* I don't want to do it in this way because of HQL */
SELECT count(*) FROM (
    SELECT a1,a2,a3
    FROM tablename
    GROUP BY a1,a2,a3
);
Run Code Online (Sandbox Code Playgroud)

那么有没有办法在没有子查询的情况下计算分组结果?

hibernate hql

5
推荐指数
0
解决办法
2158
查看次数

"git checkout - *"返回"错误:pathspec与git已知的任何文件都不匹配"

如上所述,如果我想丢弃工作目录中的更改,我运行命令git checkout -- *但git返回信息error: pathspec 'databaseName.tmp' did not match any file(s) known to git..我不是git master,我不知道如何解决它.任何的想法?

git

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

在FacesConverter中使用ManagedBean

我想用ManagedBean在我的Converter.该ManagedBean负责从数据库中获取数据.在Converter我想字符串转换成对象必须是从数据库中获取.

这是我的转换器

@FacesConverter(forClass=Gallery.class, value="galleryConverter")
public class GalleryConverter implements Converter {

    // of course this one is null
    @ManagedProperty(value="#{galleryContainer}")
    private GalleryContainer galleryContainer;

    @Override
    public Object getAsObject(FacesContext context, UIComponent component, String galleryId) {
        return galleryContainer.findGallery(galleryId);
        ...
    }

    @Override
    public String getAsString(FacesContext context, UIComponent component, Object gallery) {
        ...
    }

}
Run Code Online (Sandbox Code Playgroud)

我知道这galleryContainer将是无效的,如果我要注入ManagedBeanConverter我可以将其标记为ManagedBean过.问题是我想以漂亮的方式做到这一点,我不想寻找一些"奇怪的解决方案".也许问题出在我的申请表中?也许有一些其他好的解决方案来创建必须从数据库获取数据并在转换器中使用的对象?我还想提一下,我宁愿使用DependencyInjection而不是使用new语句创建新对象(它更容易测试和维护).有什么建议?

facelets jsf-2

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

显示一个配置的依赖关系

如何仅为一个配置显示依赖项?命令gradle dependencies显示所有配置的依赖项.

gradle

3
推荐指数
1
解决办法
135
查看次数

Gradle - 如何在名称中使用" - "运行ant任务

我想在我的gradle构建中使用cobertura,所以我以这种方式创建任务:

ant.typedef(resource: 'tasks.properties', classpath:configurations.cobertura.asPath)
Run Code Online (Sandbox Code Playgroud)

现在我想跑cobertura-instrument.问题是我不知道如何运行这个任务因为ant.cobertura-instrument(...)不起作用.有没有其他方式来运行它?例如像这样的东西ant.tasks['cobertura-instrument'](...)

ant cobertura gradle

3
推荐指数
1
解决办法
1314
查看次数

INSERT语句中的"不是有效月份"

我有一个sql语句:

Insert into MYSCHEMA.TABLE1 (ID,MY_DATE) values (167600,to_timestamp('15-APR-14 01.36.58.803000000 PM','DD-MON-RR HH.MI.SS.FF AM'));
Run Code Online (Sandbox Code Playgroud)

当我读到这个格式是正确的(如描述在这里),但Oracle返回一个错误SQL Error: ORA-01843: not a valid month.知道如何解决这个问题吗?我使用的是Oracle Database 11b Express Edition.

sql database oracle oracle11g

3
推荐指数
1
解决办法
7480
查看次数

无法在eclipse中运行sonarqube插件

我想在eclipse中使用sonarqube插件.我把它与声纳服务器联系起来似乎没问题.分析期间出现问题.输出说Access to the secured property 'sonar.scm.user.secured' is not possible in preview mode. The SonarQube plugin which requires this property must be deactivated in preview mode..我试图设置属性sonar.scm.user.secured到值false,disabled,hudson通过Window->Preferences->SonarQube->Preview Analysis Properties但说实话,我不知道我应该设置什么样的价值.这是eclipse中声纳返回的整个输出:

Retrieve remote issues of project proj-gui...
Start SonarQube analysis on proj-gui...
INFO: SonarQube Server 4.2
08:07:02.474 INFO  - Incremental mode
08:07:02.476 INFO  - Load batch settings
08:07:02.802 INFO  - User cache: C:\Users\user\.sonar\cache
08:07:02.810 INFO  - Install plugins
08:07:02.875 INFO  - Exclude …
Run Code Online (Sandbox Code Playgroud)

java sonarqube

3
推荐指数
1
解决办法
2570
查看次数

在JUnit中验证具体的异常详细信息

要验证异常消息,我可以使用ExpectedMessage对象,但如果我想验证concreate异常及其详细信息,该怎么办?例如,我有异常类TerribleWindException,有一些额外的方法,如getWindSpeed()在和junit测试方法,我想检查getWindSpeed()结果.看看这个例子:

// pseudo implementation

public class TerribleWindException extends Exception {

    private Integer windSpeed = 0;

    public TerribleWindException(final Integer windSpeed) {
        this.windSpeed = windSpeed;
    }

}

public class WalkService {

    private Integer windSpeed = 0;

    public WalkService(final Integer windSpeed) {
        this.windSpeed = windSpeed;
    }

    public void goForAWalk() throws TerribleWindException {
        if  (windSpeed>10) {
            throw new TerribleWindException(windSpeed);
        }
    }

}

// test

public class WalkServiceTest {

    @Test
    public void testGoForAWalkWhenSpeedIsToPowerfulShouldThrowTerribleWindException throws TerribleWindException {
        WalkService …
Run Code Online (Sandbox Code Playgroud)

java junit unit-testing

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

分配操作Java

class string1 {
    static public void main(String[] ar) {
        String s1 = "test";
        String s2 = new String();
        if(s2=null) { // line 0
            System.out.println(s1);
            System.out.println(s2.length()); //Line 1
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

我预计会发生什么

a)s2将被设置为null,因为它是一个赋值操作,因为我没有使用==

b)我将在运行期间在第1行获得NPE

而我得到以下输出,如下所示.

输出是

if(s2=null)
     ^
  required: boolean
  found:    String
1 error
Run Code Online (Sandbox Code Playgroud)

有人可以解释为什么我收到编译错误?

java

0
推荐指数
1
解决办法
128
查看次数