小编Mat*_*one的帖子

currying和多个参数列表之间有什么区别?

无论我到哪里,我都会看到多个参数列表和currying用于互换的术语.我在几十个stackoverflow问题中看到它,甚至在scala-lang.org上. 例如,该页面的标题为"Currying".而第一句话?"方法可以定义多个参数列表."

然而,当一些知识渊博的人看到多个参数列表并且等同于curry时,他们会感到恼火.我发布了这个问题的答案,但后来当我看到Randall Schulz的评论时将其删除,因为我担心我可能会无意中传播错误的信息.我的理解是,具有多个参数列表的函数必然是一个curried函数,但是函数currying也可以通过其他方式实现(这个问题的最佳答案列出了四种方式),但我不确定这是整个故事.我想真正理解这种区别.

我知道在stackoverflow 上有很多非常相似的问题,但是我没有找到一个能够准确地说出差异的问题.关于多个参数列表和currying,我需要了解什么才能准确地说出它们?

scala currying

17
推荐指数
1
解决办法
1041
查看次数

如何对使用SimpleJdbcCall的类进行单元测试

我有一个看起来像这样的课程:

public class MyClass {

    private final SimpleJdbcCall simpleJdbcCall;

    public MyClass(final DataSource dataSource) {
        this(new JdbcTemplate(dataSource));
    }

    public MyClass(final JdbcTemplate template) {
        simpleJdbcCall = new SimpleJdbcCall(template)
            .withoutProcedureColumnMetaDataAccess()
            .withCatalogName("MY_ORACLE_PACKAGE")
            .withFunctionName("GET_VALUE")
            .withReturnValue()
            .declareParameters(
                new SqlOutParameter("RESULT", Types.VARCHAR))
            .declareParameters(
                new SqlParameter("P_VAR1_NAME", Types.VARCHAR))
            .declareParameters(
                new SqlParameter("P_VAR2_NAME", Types.VARCHAR))
            .useInParameterNames("P_VAR1_NAME", "P_VAR2_NAME");
    }

    private String getValue(final String input) {
        final SqlParameterSource params = new MapSqlParameterSource()
            .addValue("P_VAR1_NAME", input, Types.VARCHAR)
            .addValue("P_VAR2_NAME", null, Types.VARCHAR);
        return simpleJdbcCall.executeFunction(String.class, params);
    }
}
Run Code Online (Sandbox Code Playgroud)

它按预期工作,但我想为它编写单元测试,这让我发疯.我已经尝试过模拟JdbcTemplate(Mockito),但这会导致模拟连接,元数据等,并且我对可调用语句工厂发挥作用的时间感到迷茫.

我想我可以编写它,以便将SimpleJdbcCall作为参数传递给新的构造函数,然后模拟它,但这感觉很乱.我希望测试不会影响课程,除非是为了改进它.

我想继续使用这个SimpleJdbcCall API.它为我编写SQL,所以我不必混合SQL和Java,但我也非常想测试这个东西,而不必编写1000行代码.任何人都可以看到测试这个的好方法吗?

java unit-testing mocking spring-jdbc mockito

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

如何仅在某些行上获得多个Java正则表达式匹配

我正在调用一个我无法更改的API.也就是说,我不能将它作为两个连续的正则表达式或类似的东西.API是这样编写的(当然简化):

void apiMethod(final String regex) {
    final String input = 
        "bad:    thing01, thing02, thing03 \n" +
        "good:   thing04, thing05, thing06 \n" +
        "better: thing07, thing08, thing09 \n" +
        "worse:  thing10, thing11, thing12 \n";

    final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE);

    final Matcher matcher = pattern.matcher(input);

    while (matcher.find()) {
        System.out.println(matcher.group(1));
    }
}
Run Code Online (Sandbox Code Playgroud)

我调用它是这样的:

apiMethod("(thing[0-9]+)");
Run Code Online (Sandbox Code Playgroud)

我希望看到打印出六行,每行04到09,包括一行.到目前为止我还没有成功.我试过的一些东西不起作用:

  • "(事[0-9] +)" - 这匹配所有12件事,这不是我想要的.
  • "^(?:good | better):( thing [0-9] +)" - 这只匹配第4和第7项.
  • "^(?:( ?: good | better):.*)(thing [0-9] +)" - 这只匹配第6和第9项.
  • "(?:(?:^ good:| ^ better:|,)*)(thing [0-9] +)" …

java regex multiple-matches regex-group regex-lookarounds

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