我们应该assert()具体使用这个功能的地方有哪些?如果确定整数值是否大于零或指针是否为空,我们可以简单地使用私有函数来检查它.在这种情况下,我们应该在哪里使用assert()自定义书面支票?
我正在java中开发一个基于语义的搜索应用程序.为了使应用程序模块化,我想使用osgi架构.但由于我是osgi的新手,我不知道使用它的优点和缺点.任何人都可以解释使用osgi的优点/缺点,使用osgi /应用程序将通过这样做获得什么样的应用程序将受益?
谢谢!!
是否可以将非osgi库与OSGi应用程序一起使用?
举个例子,我正在开发一个基于语义的搜索引擎,我正在使用第三方自然语言处理库(http://wiki.opencog.org/w/RelEx_Dependency_Relationship_Extractor).
是否有可能将这样一个不支持OSGi的库作为几个jar文件与我的OSGi应用程序接口?
我正在使用JGit访问远程Git仓库,我需要使用SSH.JGit使用JSch提供安全访问.但是,我不确定如何为JGit设置密钥文件和已知的hosts文件.我试过的内容如下.
使用子类化JSchConfigSessionFactory创建SshSessionFactory的自定义配置:
public class CustomJschConfigSessionFactory extends JschConfigSessionFactory {
    @Override
    protected void configure(OpenSshConfig.Host host, Session session) {
        session.setConfig("StrictHostKeyChecking", "yes");
    }
}
Run Code Online (Sandbox Code Playgroud)
在我访问远程Git仓库的类中,执行以下操作:
CustomJschConfigSessionFactory jschConfigSessionFactory = new CustomJschConfigSessionFactory();
JSch jsch = new JSch();
try {
    jsch.addIdentity(".ssh/id_rsa");
    jsch.setKnownHosts(".ssh/known_hosts");
} catch (JSchException e) {
    e.printStackTrace();  
}
    SshSessionFactory.setInstance(jschConfigSessionFactory);
Run Code Online (Sandbox Code Playgroud)
我无法弄清楚如何将此JSch对象与JGit关联,以便它可以成功连接到远程存储库.当我尝试使用JGit克隆它时,我得到以下异常:
org.eclipse.jgit.api.errors.TransportException: git@git.test.com:abc.org/test_repo.git: reject HostKey: git.test.com
at org.eclipse.jgit.api.FetchCommand.call(FetchCommand.java:137)
at org.eclipse.jgit.api.CloneCommand.fetch(CloneCommand.java:178)
at org.eclipse.jgit.api.CloneCommand.call(CloneCommand.java:125)
at GitTest.cloneRepo(GitTest.java:109)
at GitTest.main(GitTest.java:223)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120) …Run Code Online (Sandbox Code Playgroud) 我有一个用c ++实现的红黑树.它支持STL映射的功能.树节点包含键和映射的值.我想为此编写一个迭代器类,但我仍然坚持如何做到这一点.我应该将它作为Tree类的内部类吗?任何人都可以给我一些指导如何写它+一些资源?
谢谢!!
我正在使用jgit安全地访问GitHub中的存储库.我做了以下操作来生成GitHub和我的客户端代码之间的安全通信密钥.
生成密钥对:
ssh-keygen -t rsa
Run Code Online (Sandbox Code Playgroud)使用帐户设置 - > SSH密钥 - >添加SSH密钥,将公钥添加到GitHub帐户
将步骤1中生成的私钥添加到本地主机:
ssh-add id_rsa
Run Code Online (Sandbox Code Playgroud)执行此操作后,当我尝试访问GitHub并进行克隆时,我仍然会收到以下错误:
org.eclipse.jgit.api.errors.TransportException: git@github.com:test/test_repo.git: UnknownHostKey: github.com. RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48
at org.eclipse.jgit.api.FetchCommand.call(FetchCommand.java:137)
at org.eclipse.jgit.api.CloneCommand.fetch(CloneCommand.java:178)
at org.eclipse.jgit.api.CloneCommand.call(CloneCommand.java:125)
Run Code Online (Sandbox Code Playgroud)
这是我使用的代码:
    String localPath, remotePath;
    Repository localRepo;
    Git git;
    localPath = <path_to_local_repository>;
    remotePath = "git@github.com:test/test_repo.git";
    try {
        localRepo = new FileRepository(localPath + "/.git");
    } catch (IOException e) {
        e.printStackTrace();
    }
    git = new Git(localRepo);
    CloneCommand cloneCmd =  git.cloneRepository().
                setURI(remotePath).
                setDirectory(new File(localPath));
        try {
            cloneCmd.call();
        } catch (GitAPIException e) {
            log.error("git clone …Run Code Online (Sandbox Code Playgroud) 我是git的新用户,我正在使用JGit与远程git存储库进行交互.在JGit中,我过去常常CloneCommand克隆一个repo,它没有问题.但是,当我尝试使用时PullCommand,相当于SVN更新AFAIK,本地存储库内容不会更新.
这是我使用的代码:
private String localPath;
private Repository localRepo;
private Git git;
localPath = "/home/test/git_repo_test";
remotePath = "https://github.com/test/repo_1.git";
try {
    localRepo = new FileRepository(localPath + "/.git");
} catch (IOException e) {
    e.printStackTrace();  
}
git = new Git(localRepo);
PullCommand pullCmd = git.pull();
try {
    pullCmd.call();
} catch (GitAPIException e) {
    e.printStackTrace();  
}
Run Code Online (Sandbox Code Playgroud)
这不会更新我使用命令行推送到远程存储库的新文件的本地存储库.但是,如果我删除本地存储库并再次获取克隆,则会反映所有更改.
请告诉我PullCommand在JGit 中使用的正确方法是什么.
编辑:
远程存储库的结构:
root ____ file_1
  |______ directory_1
              |__________ file_2 
              |__________ file_3
Run Code Online (Sandbox Code Playgroud)
在初始克隆之后,从命令行推送了directory_1和两个文件,我尝试了这个代码,这样它就会反映在本地存储库中,而这种情况并没有发生.
用于克隆存储库的代码:
File file = new File(localPath);
CloneCommand …Run Code Online (Sandbox Code Playgroud) 当我为我的头文件添加一个包含Guard的Visual C++项目时,它给了我以下警告和错误:
警告C4603:'_ MAPTEST_H':未定义宏或预编译头使用后定义不同
将宏添加到预编译头,而不是在此处定义
.\ MapTest.cpp(6):使用预编译头**//预编译头stdafx.h包含在此行中
.\ MapTest.cpp(186):致命错误C1020:意外#endif
但是当我在include guard之前添加预编译头时,不会发出警告或错误.这是什么原因?
在阅读并发编程时,我在比较和交换以及比较和设置操作中遇到了共识数这个术语.我无法理解这个术语的含义,任何人都可以解释一下吗?
谢谢!!
concurrency multithreading concurrent-programming compare-and-swap
在java程序中,我生成了除主线程之外的一个线程,然后从我创建的原始线程(两个子线程)中生成了另外两个线程.在所有情况下,我使用Runnable接口来创建线程.我的问题是,有更好的方法吗?递归生成线程时性能是否会降低?