小编Vit*_*lyT的帖子

如何排序N个文件

以下是这个答案 - >

如何排序非常大的文件

我只需要Merge在磁盘上已经排序的N个文件上的函数,我想将它们排序成一个大文件我的限制是内存不多于K lines in the memory (K < N)我无法获取所有它们然后排序,首选java

到目前为止,我尝试下面的代码,但我需要一个很好的方法来逐行迭代所有N个文件(不超过内存中的K LINES)+存储到磁盘的已排序的最终文件

       public void run() {
            try {
                System.out.println(file1 + " Started Merging " + file2 );
                FileReader fileReader1 = new FileReader(file1);
                FileReader fileReader2 = new FileReader(file2);

                //......TODO with N ?? ......

                FileWriter writer = new FileWriter(file3);
                BufferedReader bufferedReader1 = new BufferedReader(fileReader1);
                BufferedReader bufferedReader2 = new BufferedReader(fileReader2);
                String line1 = bufferedReader1.readLine();
                String line2 = bufferedReader2.readLine();
                //Merge 2 files based on which string is greater. …
Run Code Online (Sandbox Code Playgroud)

java algorithm

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

如何使用谓词文本在Titan 1.0/TP3 3.01中的顶点索引之间进行逻辑OR

在我从TP2 0.54 - > TP3 titan 1.0/Tinkerpop 3.01迁移期间

我正在尝试构建gremlin查询,该查询使用谓词文本在不同顶点索引的属性之间进行"逻辑或运算"

就像是:

-------------------预先定义的ES指数:------------------

tg = TitanFactory.open('../conf/titan-cassandra-es.properties')
tm = tg.openManagement();
g=tg.traversal();

      PropertyKey pNodeType = createPropertyKey(tm, "nodeType", String.class, Cardinality.SINGLE);
      PropertyKey userContent = createPropertyKey(tm, "storyContent", String.class, Cardinality.SINGLE);
      PropertyKey storyContent = createPropertyKey(tm, "userContent", String.class, Cardinality.SINGLE);

            //"storyContent" : is elasticsearch backend index - mixed
            tm.buildIndex(indexName, Vertex.class).addKey(storyContent, Mapping.TEXTSTRING.asParameter()).ib.addKey(pNodeType, Mapping.TEXTSTRING.asParameter()).buildMixedIndex("search");

            //"userContent" : is elasticsearch backend index - mixed
            tm.buildIndex(indexName, Vertex.class).addKey(userContent, Mapping.TEXTSTRING.asParameter()).ib.addKey(pNodeType, Mapping.TEXTSTRING.asParameter()).buildMixedIndex("search");


            v1= g.addVertex()
            v1.property("nodeType","USER")
            v1.property("userContent" , "dccsdsadas")

            v2= g.addVertex()
            v2.property("nodeType","STORY")
            v2.property("storyContent" , "abdsds")

            v3= g.addVertex()
            v3.property("nodeType","STORY")
            v3.property("storyContent" , …
Run Code Online (Sandbox Code Playgroud)

gremlin titan tinkerpop tinkerpop3

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

5-10M条目的最佳hashmap容量/负载因子是多少?

我在a中有大约5-10M条目HashMap,我无法更改代码结构.我正在java-Xms=512m -Xmx=1024m.HashMap要避免的构造函数中的最佳容量/负载因子值是java.lang.OutOfMemoryError: GC overhead limit exceeded多少?

private final Map<String, ReportResultView> aggregatedMap = new HashMap<>(????, ????);
Run Code Online (Sandbox Code Playgroud)

java optimization dictionary hashmap java-8

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

如何使用Mockito Java使用applicationType Json模拟http POST

我想用json数据模拟http POST.

对于GET方法,我使用以下代码成功:

import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

when(request.getMethod()).thenReturn("GET");
when(request.getPathInfo()).thenReturn("/getUserApps");
when(request.getParameter("userGAID")).thenReturn("test");
when(request.getHeader("userId")).thenReturn("xxx@aaa-app.com");
Run Code Online (Sandbox Code Playgroud)

我的问题是http POST请求正文.我希望它包含application/json类型内容.

像这样的东西,但是应答paras应该回答json的反应是什么?

HttpServletRequest request = mock(HttpServletRequest.class);
HttpServletResponse response = mock(HttpServletResponse.class);

when(request.getMethod()).thenReturn("POST");
when(request.getPathInfo()).thenReturn("/insertPaymentRequest");
when( ????  ).then( ???? maybe ?? // new Answer<Object>() {
    @Override
    public Object answer(InvocationOnMock invocation) throws Throwable {
        new Gson().toJson("{id:213213213 , amount:222}", PaymentRequest.class);
        }
    });
Run Code Online (Sandbox Code Playgroud)

或者"公共对象回答..."可能不是用于Json返回的正确方法.

usersServlet.service(request, response);
Run Code Online (Sandbox Code Playgroud)

java servlets mocking mockito

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