@Test public void testQueryProblem() throws Exception { problemService.queryProblem(null); }
@Override public QuerryResult queryProblem(QuerryInfo querryInfo) throws ParserErrorException { List<Long> longs = parser.getAllProblemsByExpression(querryInfo); Boolean random = querryInfo.isRandom(); if (random != null && random) { Collections.shuffle(longs); } Pagination resPagin = new Pagination(); @Valid Pagination pagination = querryInfo.getPagination(); if (pagination != null) { int page = pagination.getPage().intValue(); int size = pagination.getSize().intValue(); resPagin.setPage(BigDecimal.valueOf(-1)); resPagin.setSize(BigDecimal.valueOf(size)); resPagin.setTotal(BigDecimal.valueOf(longs.size())); if (page * size < longs.size()) { int to = (page + 1) * size; if (to > (longs.size() - 1)) { to = longs.size() - 1; } longs = longs.subList(page * size, to+1); resPagin.setPage(BigDecimal.valueOf(page)); } else { longs = new ArrayList<>(); } } List<ProblemFullData> problemFullData = problemDataService.getFullDataByIds(longs); ArrayList<HashMap<String, Object>> res = new ArrayList<>(); QuerryResult querryResult = new QuerryResult(); querryResult.setStatus(StatusCode.OK); for (ProblemFullData e : problemFullData) { res.add(e.toMap()); } querryResult.setResults(res); querryResult.setPagination(resPagin); return querryResult; }
ProblemServiceImpl implements ProblemService { @Override public QuerryResult queryProblem(QuerryInfo querryInfo) throws ParserErrorException { List<Long> longs = parser.getAllProblemsByExpression(querryInfo); Boolean random = querryInfo.isRandom(); if (random != null && random) { Collections.shuffle(longs); } Pagination resPagin = new Pagination(); @Valid Pagination pagination = querryInfo.getPagination(); if (pagination != null) { int page = pagination.getPage().intValue(); int size = pagination.getSize().intValue(); resPagin.setPage(BigDecimal.valueOf(-1)); resPagin.setSize(BigDecimal.valueOf(size)); resPagin.setTotal(BigDecimal.valueOf(longs.size())); if (page * size < longs.size()) { int to = (page + 1) * size; if (to > (longs.size() - 1)) { to = longs.size() - 1; } longs = longs.subList(page * size, to+1); resPagin.setPage(BigDecimal.valueOf(page)); } else { longs = new ArrayList<>(); } } List<ProblemFullData> problemFullData = problemDataService.getFullDataByIds(longs); ArrayList<HashMap<String, Object>> res = new ArrayList<>(); QuerryResult querryResult = new QuerryResult(); querryResult.setStatus(StatusCode.OK); for (ProblemFullData e : problemFullData) { res.add(e.toMap()); } querryResult.setResults(res); querryResult.setPagination(resPagin); return querryResult; } }
ProblemServiceImpl implements ProblemService { @Override public QuerryResult queryProblem(QuerryInfo querryInfo) throws ParserErrorException { List<Long> longs = parser.getAllProblemsByExpression(querryInfo); Boolean random = querryInfo.isRandom(); if (random != null && random) { Collections.shuffle(longs); } Pagination resPagin = new Pagination(); @Valid Pagination pagination = querryInfo.getPagination(); if (pagination != null) { int page = pagination.getPage().intValue(); int size = pagination.getSize().intValue(); resPagin.setPage(BigDecimal.valueOf(-1)); resPagin.setSize(BigDecimal.valueOf(size)); resPagin.setTotal(BigDecimal.valueOf(longs.size())); if (page * size < longs.size()) { int to = (page + 1) * size; if (to > (longs.size() - 1)) { to = longs.size() - 1; } longs = longs.subList(page * size, to+1); resPagin.setPage(BigDecimal.valueOf(page)); } else { longs = new ArrayList<>(); } } List<ProblemFullData> problemFullData = problemDataService.getFullDataByIds(longs); ArrayList<HashMap<String, Object>> res = new ArrayList<>(); QuerryResult querryResult = new QuerryResult(); querryResult.setStatus(StatusCode.OK); for (ProblemFullData e : problemFullData) { res.add(e.toMap()); } querryResult.setResults(res); querryResult.setPagination(resPagin); return querryResult; }  }
ProblemServiceImpl implements ProblemService { @Override public QuerryResult queryProblem(QuerryInfo querryInfo) throws ParserErrorException { List<Long> longs = parser.getAllProblemsByExpression(querryInfo); Boolean random = querryInfo.isRandom(); if (random != null && random) { Collections.shuffle(longs); } Pagination resPagin = new Pagination(); @Valid Pagination pagination = querryInfo.getPagination(); if (pagination != null) { int page = pagination.getPage().intValue(); int size = pagination.getSize().intValue(); resPagin.setPage(BigDecimal.valueOf(-1)); resPagin.setSize(BigDecimal.valueOf(size)); resPagin.setTotal(BigDecimal.valueOf(longs.size())); if (page * size < longs.size()) { int to = (page + 1) * size; if (to > (longs.size() - 1)) { to = longs.size() - 1; } longs = longs.subList(page * size, to+1); resPagin.setPage(BigDecimal.valueOf(page)); } else { longs = new ArrayList<>(); } } List<ProblemFullData> problemFullData = problemDataService.getFullDataByIds(longs); ArrayList<HashMap<String, Object>> res = new ArrayList<>(); QuerryResult querryResult = new QuerryResult(); querryResult.setStatus(StatusCode.OK); for (ProblemFullData e : problemFullData) { res.add(e.toMap()); } querryResult.setResults(res); querryResult.setPagination(resPagin); return querryResult; }  @Override QuerryResult queryProblem(QuerryInfo querryInfo); List<ProblemFullData> problemInfoToProblemFullDatas(ProblemInfo problemInfo); @Override ArrayList<Long> addProblemByProblemInfo(ProblemInfo problemInfo); @Override void deleteById(String id); }
ProblemServiceImpl implements ProblemService { @Override public QuerryResult queryProblem(QuerryInfo querryInfo) throws ParserErrorException { List<Long> longs = parser.getAllProblemsByExpression(querryInfo); Boolean random = querryInfo.isRandom(); if (random != null && random) { Collections.shuffle(longs); } Pagination resPagin = new Pagination(); @Valid Pagination pagination = querryInfo.getPagination(); if (pagination != null) { int page = pagination.getPage().intValue(); int size = pagination.getSize().intValue(); resPagin.setPage(BigDecimal.valueOf(-1)); resPagin.setSize(BigDecimal.valueOf(size)); resPagin.setTotal(BigDecimal.valueOf(longs.size())); if (page * size < longs.size()) { int to = (page + 1) * size; if (to > (longs.size() - 1)) { to = longs.size() - 1; } longs = longs.subList(page * size, to+1); resPagin.setPage(BigDecimal.valueOf(page)); } else { longs = new ArrayList<>(); } } List<ProblemFullData> problemFullData = problemDataService.getFullDataByIds(longs); ArrayList<HashMap<String, Object>> res = new ArrayList<>(); QuerryResult querryResult = new QuerryResult(); querryResult.setStatus(StatusCode.OK); for (ProblemFullData e : problemFullData) { res.add(e.toMap()); } querryResult.setResults(res); querryResult.setPagination(resPagin); return querryResult; }  @Override QuerryResult queryProblem(QuerryInfo querryInfo); List<ProblemFullData> problemInfoToProblemFullDatas(ProblemInfo problemInfo); @Override ArrayList<Long> addProblemByProblemInfo(ProblemInfo problemInfo); @Override void deleteById(String id);  }