小编wou*_*non的帖子

如何从git的藏匿中挑选樱桃?

我想知道是否可以从藏匿处采摘樱桃.

git stash save "test cherry-pick from stash"

*git cherry-pick stash@{0}* --> Is this possible?
Run Code Online (Sandbox Code Playgroud)

我在exception上面尝试时得到以下内容command:

Error:

~/Documents$ git cherry-pick stash@{0}
error: Commit 4590085c1a0d90de897633990f00a14b04405350 is a merge but no -m option was given.
fatal: cherry-pick failed
Run Code Online (Sandbox Code Playgroud)

git cherry-pick

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

使用父pom中的pluginManagement在eclipse中生命周期配置错误未涵盖插件执行

我在pluginManagement标签中的父pom.xml中有jaxws-maven-plugin,我指的是这个插件在pom中.

mvn clean install运行正常.但是,eclipse抱怨"生命周期配置未涵盖插件执行:org.codehaus.mojo:jaxws-maven-plugin:1.12:wsimport(执行:FirstWsdl,阶段:生成源)".

你能建议如何在eclipse中避免这个错误吗?

父母pom

<pluginManagement>
    <plugins>
    ...
    <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>jaxws-maven-plugin</artifactId>
        <version>1.12</version>
        <executions>
            <execution>
                <id>FirstWsdl</id>
                <goals>
                    <goal>wsimport</goal>
                </goals>
                <phase>generate-sources</phase>
                <configuration>
                    <wsdlLocation>location/file.wsdl</wsdlLocation>
                    <wsdlFiles>
                        <wsdlFile>file.wsdl</wsdlFile>
                    </wsdlFiles>
                    <packageName>com.xxx.package</packageName>
                </configuration>
            </execution>

        </executions>
        <configuration>
            <sourceDestDir>${basedir}/generated</sourceDestDir>
            <verbose>true</verbose>
            <extension>true</extension>
            <keep>true</keep>
            <vmArgs>
                <vmArg .../>
            </vmArgs>
        </configuration>

    </plugin>
...
   </plugins>
</pluginManagement>   
Run Code Online (Sandbox Code Playgroud)

孩子pom

<plugins>
    <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>jaxws-maven-plugin</artifactId>
    </plugin>
</plugins>
Run Code Online (Sandbox Code Playgroud)

我查看了这个问题,并回答如何解决Spring Data Maven Builds的"生命周期配置未涵盖的插件执行",但是,我应该在父和子pom中使用pluginManagement来避免此错误吗?

java eclipse maven

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

lambda表达式中变量名的约定是什么?

例如,我看到很多例子

int sum = widgets.stream()
                  .filter(w -> w.getColor() == RED)
                  .mapToInt(w -> w.getWeight())
                  .sum();
Run Code Online (Sandbox Code Playgroud)

我们可以在这些lambda表达式中使用任何variableName吗?

我认为变量名称具有约定,并且可以使用专有名称来提高可读性.

例如,如果我在pre-java8中使用w作为Widget,则代码将被避免为不可读.随着java 8的出现发生了什么变化?

   for(Widget w : widgets)
   {
         if(w.getColor() == RED) {
            sum += w.getWeight();
         }
    }
Run Code Online (Sandbox Code Playgroud)

为什么不能像这样编写代码:

int sum = widgets.stream()
                  .filter(widget -> widget.getColor() == RED)
                  .mapToInt(widget -> widget.getWeight())
                  .sum();
Run Code Online (Sandbox Code Playgroud)

也许上面的代码是直接做的,而且只在小部件列表中的小部件上.那么,还有更多:

哪个更易读:

    return  requestHolder.getRequests()
                        .stream()
                        .map(request -> request.getErrorHolder())
                        .flatMap(errorData -> errorData.getErrors().stream())
                        .collect(toList());
Run Code Online (Sandbox Code Playgroud)

要么

    return  requestHolder.getRequests()
                        .stream()
                        .map(t -> t.getErrorHolder())
                        .flatMap(r -> r.getErrors().stream())
                        .collect(toList());
Run Code Online (Sandbox Code Playgroud)

也许我错过了什么.你能解释一下吗?

java lambda java-8

15
推荐指数
1
解决办法
5011
查看次数

java 8中的lambda特性如何工作?

我正在尝试使用java 8功能.在阅读官方教程时,我遇到了这段代码

static void invoke(Runnable r) {
    r.run();
}

static <T> T invoke(Callable<T> c) throws Exception {
    return c.call();
}
Run Code Online (Sandbox Code Playgroud)

并且有一个问题:

将在以下语句中调用哪种方法?"

String s = invoke(() -> "done");

并回答它

该方法invoke(Callable<T>)将被调用因为该方法返回的值; 方法invoke(Runnable)没有.在这种情况下,lambda表达式的类型() -> "done"Callable<T>.

据我所知,因为invoke预期返回a String,它会调用Callable的调用.但是,不确定它是如何工作的.

java java-8

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

我怎么知道准备好的语句是否被缓存了?

我将Hikari与SQL Server 2016和tomcat lib文件夹中的sqljdbc4-2.0.jar一起使用。

我对数据库资源的配置如下:

<Resource name="jdbc/SQLServerDS" auth="Container" type="javax.sql.DataSource"
              username="uname"
              password="pwd"
              driverClassName="com.microsoft.sqlserver.jdbc.SQLServerDriver"
              url="jdbc:sqlserver://server:port;DatabaseName=dbName"
              maxActive="20"
              maxIdle="10"
              validationQuery="select 1" />
Run Code Online (Sandbox Code Playgroud)

我的数据源配置如下:

@Bean(name = "dataSource")
    public DataSource getDataSource() throws NamingException {
        HikariConfig config = new HikariConfig();
        config.setMaximumPoolSize(20);
        config.setDataSourceJNDI("java:comp/env/jdbc/SQLServerDS");
        config.addDataSourceProperty("cachePrepStmts", "true");
        config.addDataSourceProperty("prepStmtCacheSize", "250");
        config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
        config.addDataSourceProperty("useServerPrepStmts", "true");
        config.addDataSourceProperty("cacheResultSetMetadata", "true");
        config.addDataSourceProperty("useLocalSessionState", "true");
        config.addDataSourceProperty("cacheServerConfiguration", "true");
        config.addDataSourceProperty("elideSetAutoCommits", "true");
        config.addDataSourceProperty("maintainTimeStats", "false");
        return new TransactionAwareDataSourceProxy(
                new LazyConnectionDataSourceProxy(new HikariDataSource(config)));
    }
Run Code Online (Sandbox Code Playgroud)

我如何知道preparestatement缓存是否适用于不同的连接?

我正在将Spring容器管理的事务与hibernate v4.3.10.Final一起使用。

另外,为了使缓存起作用,是否需要启用二级缓存?

java spring hibernate database-caching hikaricp

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

当我点击取消时,如何让extjs中的rowediting插件不添加行?

目前该rowediting插件提供了选项update/cancel.当我按下cancel按钮时,如果它是新添加的行,我希望它不添加新行.

我怎样才能做到这一点?

这是FIDDLE.

目前,有了rowediting,我只是添加和删除行.如果无法使用cancel,如何添加新按钮close并使其不添加行.

我也在查看sencha论坛,我找到了一个POST,其中说明如下:

  1. fireEvent canceledit

  2. 如果autoRecoverOnCancel是真的,如果记录是幻影然后删除它

但是,这也行不通.你能建议吗?

var rowEditing = Ext.create('Ext.grid.plugin.RowEditing', {
    clicksToMoveEditor: 1,
    autoCancel: false,

});

tbar: [{
    text: 'Add Employee',
    iconCls: 'employee-add',
    handler: function() {
        rowEditing.cancelEdit();

        // Create a model instance
        var r = Ext.create('Employee', {
            name: 'New Guy',
            email: 'new@sencha-test.com',
            start: new Date(),
            salary: 50000,
            active: true
        });

        store.insert(0, r);
        rowEditing.startEdit(0, 0);
    }
}, {
    itemId: 'removeEmployee', …
Run Code Online (Sandbox Code Playgroud)

javascript extjs extjs4.2 extjs-grid roweditor

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

箭头操作符如何在java 8中内部工作?

我知道箭头的左侧有参数,箭头的右侧是参数所在的函数.但是,我想知道java 8如何映射左侧和右侧并转换为函数.那里发生了什么,我在哪里可以找到这些信息?

java java-8

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

java 8中可选的null可执行流程

我注意到如果我使用Optional可以通过以下方式:

Object returnValue = Optional.ofNullable(nullableValue)
         .map(nonNullValue -> firstMethod(arg1, nonNullValue))
         .orElse(secondMethod)
Run Code Online (Sandbox Code Playgroud)

当nullableValue不为null时,它正在执行第一个方法和第二个方法.难道我做错了什么?当nullableValue不为null时,我希望它只执行firstMethod.

map和flatMap似乎有preCondition(if(!isPresent()).但是,orElse没有.如何在不使用if not null条件的情况下使用java8编写代码?

根据评论,示例代码:

public static String firstMethod(String someString) {
        System.out.println("In first method");
        return someString;
    }

    public static String secondMethod() {
        System.out.println("In second method");
        return "secondMethod";
    }

    public static void main(String a[]) {
        String nullableString = "nonNullString";
        String result = Optional.ofNullable(nullableString)
                .map(nonNullString -> firstMethod(nonNullString))
                .orElse(secondMethod());
        System.out.println("Result: "+result);
    }
Run Code Online (Sandbox Code Playgroud)

输出:

In first method
In second method
Result: nonNullString
Run Code Online (Sandbox Code Playgroud)

java java-8

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

snipmate在vim中不起作用

以下文件是我的vimrc文件.我尝试采购snipmate.vim文件,我的vimrc文件中没有设置粘贴.刚刚在我的.vim目录中执行了snipmate的git clone,并将该位置添加到了runtimepath.

我正在使用MAC OSX

$ cat .vimrc 
source ~/.vim/snipmate.vim/plugin/snipMate.vim
nnoremap <Space> za
vnoremap <Space> za
nnoremap zO zCzO
set smartindent
set hlsearch
set ignorecase
set foldenable
set foldmethod=syntax
syn region foldBraces start=/{/ end=/}/ transparent fold
syn region foldJavadoc start=,/\*\*, end=,\*/, transparent fold keepend
set ai
set sm
set incsearch
set runtimepath^=~/.vim/bundle/ctrlp.vim,~/.vim/nerdtree,~/.vim/snipmate.vim
set nocompatible            " Because filetype detection doesn't work well in compatible mode
filetype plugin indent on   " Turns on filetype detection, filetype plugins, and filetype indenting all of which …
Run Code Online (Sandbox Code Playgroud)

vim vim-plugin snipmate

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

Orika - 仅当第三个字段与字符串匹配时才映射两个字段

我有两个要用Orika映射的字段

 @Override
    public void configure(MapperFactory factory) {
        factory.classMap(ClazzA.class, ClazzB.class)
                .byDefault()
                .field("name", "sname")
                .register();
Run Code Online (Sandbox Code Playgroud)

只有当ClazzB中的第三个字段"type"与字符串"stk"匹配时,我才想将该字段名称映射到sname中的值.

是否可以使用Orika?

java mapping orika

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

关于使用HashMap的方式的设计实现

在GUI中显示帐户时,我需要显示主帐户(对于辅助帐户)每个主帐户可以有多个辅助帐户.

我试图在HashMap中保存主要帐户信息.因为,需要稍后检索.

保存时,我还需要保存二级帐户指令.因此,我需要使用key作为主帐户保存两个对象.

1) Secondary Account
2) Secondary Instruction.
Run Code Online (Sandbox Code Playgroud)

我为帐户和指令对象重写了equals和hashcode.

我试图使用主帐户哈希码作为键和值作为对象列表[2]

- 初始化

private static final Map<Integer, ArrayList<Object[]>> primaryToSecondaryAcct = new ConcurrentHashMap<Integer, ArrayList<Object[]>>();
Run Code Online (Sandbox Code Playgroud)

- 投入价值

final Object[] acctInstr = new Object[2];
acctInstr[0] = acct;
acctInstr[1] = instr;
if(primaryToSecondaryAcct.get(getExistingAccount().hashCode()) != null) {
    primaryToSecondaryAcct.get(getExistingAccount().hashCode()).add(acctInstr);
} else {
    final ArrayList<Object[]> acctInstrList = new ArrayList<Object[]>();
    acctInstrList.add(acctInstr);
    primaryToSecondaryAcct.put(getExistingAccount().hashCode(), acctInstrList);
}
Run Code Online (Sandbox Code Playgroud)

我想知道这是否正确,是否有更好的方法.你能建议吗?

java hashmap concurrenthashmap

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

两种类型的方式之间的区别铸造List to List <T>

public static <T> List<T> templatizeList(final List list, final Class<T> clazz) {
        return (List<T>) list;
    }

    public static <T> List<T> typeSafeAdd(List<?> from, Class<T> clazz) {
        List<T> to = new ArrayList<>();
        from.forEach(item -> to.add(clazz.cast(item)));
        return to;
    }
Run Code Online (Sandbox Code Playgroud)

这两种方法有什么区别?一种方式比另一种方式更安全或更快还是无关紧要?

java java-8

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

grep无法识别[AZ] +

$ grep 'tableName="' db.changelog.xml
    <createTable tableName="MY_TABLE" schemaName="public">

$ grep 'tableName="[A-Z_]+"' db.changelog.xml
Run Code Online (Sandbox Code Playgroud)

第二个grep不返回任何内容。这是为什么?

这是默认配置的语言。

$ echo $LANG
en_US.UTF-8
$ grep --version
grep (GNU grep) 2.24
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Mike Haertel and others, see <http://git.sv.gnu.org/cgit/grep.git/tree/AUTHORS>.
Run Code Online (Sandbox Code Playgroud)

regex grep

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