package yanagishima.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Map;

import javax.inject.Inject;
import javax.inject.Singleton;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.http.client.fluent.Request;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import yanagishima.config.YanagishimaConfig;

@Singleton
public class QueryServlet extends HttpServlet {

	private static Logger LOGGER = LoggerFactory.getLogger(QueryServlet.class);

	private static final long serialVersionUID = 1L;

	private YanagishimaConfig yanagishimaConfig;

	@Inject
	public QueryServlet(YanagishimaConfig yanagishimaConfig) {
		this.yanagishimaConfig = yanagishimaConfig;
	}

	@Override
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {

		String prestoCoordinatorServer = yanagishimaConfig
				.getPrestoCoordinatorServer();
		response.setContentType("application/json");
		PrintWriter writer = response.getWriter();
		String originalJson = Request.Get(prestoCoordinatorServer + "/v1/query")
				.execute().returnContent().asString(StandardCharsets.UTF_8);
		ObjectMapper mapper = new ObjectMapper();
		List<Map> list = mapper.readValue(originalJson, List.class);
		list.sort((a,b)-> String.class.cast(b.get("queryId")).compareTo(String.class.cast(a.get("queryId"))));
		String json = mapper.writeValueAsString(list.subList(0, 100));
		writer.println(json);

	}

}

@@ -836,16 +836,56 @@
 onfig;%0A%0A
+%09private static final int LIMIT = 100;%0A%0A
 %09@Inject
@@ -1556,16 +1556,45 @@
 class);%0A
+%09%09if(list.size() %3E LIMIT) %7B%0A%09
 %09%09list.s
@@ -1688,24 +1688,25 @@
 yId%22))));%0A%09%09
+%09
 String json 
@@ -1753,15 +1753,18 @@
 (0, 
-100
+LIMIT
 ));%0A
+%09
 %09%09wr
@@ -1783,15 +1783,62 @@
 (json);%0A
+%09%09%7D else %7B%0A%09%09%09writer.println(originalJson);%0A%09%09%7D
 %0A%09%7D%0A%0A%7D%0A

Add limit check