List of usage examples for java.util List remove
E remove(int index);
From source file:csns.web.controller.SectionJournalController.java
@RequestMapping("/section/journal/toggleEnrollment") @ResponseStatus(HttpStatus.OK)// w w w. ja va2 s . c om public void toggleEnrollment(@RequestParam Long journalId, @RequestParam Long enrollmentId) { User user = SecurityUtils.getUser(); CourseJournal courseJournal = courseJournalDao.getCourseJournal(journalId); Enrollment enrollment = enrollmentDao.getEnrollment(enrollmentId); List<Enrollment> samples = courseJournal.getStudentSamples(); if (samples.contains(enrollment)) { samples.remove(enrollment); logger.info(user.getUsername() + " removed enrollment " + enrollmentId + " from course jorunal " + journalId); } else { samples.add(enrollment); logger.info( user.getUsername() + " added enrollment " + enrollmentId + " to course jorunal " + journalId); } courseJournalDao.saveCourseJournal(courseJournal); }
From source file:org.atemsource.atem.impl.common.attribute.collection.ListAttributeImpl.java
@Override public void moveElement(Object entity, int fromIndex, int toIndex) { List value = getValue(entity); if (value == null || value.size() <= fromIndex || value.size() <= toIndex) { throw new IllegalArgumentException("list is too small"); }//from w ww. ja va 2 s .c o m Object element = value.remove(fromIndex); value.add(toIndex, element); }
From source file:com.espertech.esper.epl.expression.ExprStaticMethodNode.java
public void validate(StreamTypeService streamTypeService, MethodResolutionService methodResolutionService, ViewResourceDelegate viewResourceDelegate, TimeProvider timeProvider, VariableService variableService, ExprEvaluatorContext exprEvaluatorContext) throws ExprValidationException { ExprNodeUtility.validate(chainSpec, streamTypeService, methodResolutionService, viewResourceDelegate, timeProvider, variableService, exprEvaluatorContext); // get first chain item List<ExprChainedSpec> chainList = new ArrayList<ExprChainedSpec>(chainSpec); ExprChainedSpec firstItem = chainList.remove(0); // Get the types of the parameters for the first invocation Class[] paramTypes = new Class[firstItem.getParameters().size()]; ExprEvaluator[] childEvals = new ExprEvaluator[firstItem.getParameters().size()]; int count = 0; boolean allConstants = true; for (ExprNode childNode : firstItem.getParameters()) { ExprEvaluator eval = childNode.getExprEvaluator(); childEvals[count] = eval;/*from w w w.ja v a2 s . c o m*/ paramTypes[count] = eval.getType(); count++; if (!(childNode.isConstantResult())) { allConstants = false; } } boolean isConstantParameters = allConstants && isUseCache; isReturnsConstantResult = isConstantParameters && chainList.isEmpty(); // Try to resolve the method FastMethod staticMethod; try { Method method = methodResolutionService.resolveMethod(className, firstItem.getName(), paramTypes); FastClass declaringClass = FastClass.create(Thread.currentThread().getContextClassLoader(), method.getDeclaringClass()); staticMethod = declaringClass.getMethod(method); } catch (Exception e) { throw new ExprValidationException(e.getMessage()); } ExprDotEval[] eval = ExprDotNodeUtility.getChainEvaluators(staticMethod.getReturnType(), chainList, methodResolutionService, false); evaluator = new ExprStaticMethodEvalInvoke(className, staticMethod, childEvals, isConstantParameters, eval); }
From source file:org.fao.fenix.wds.web.rest.crowdprices.CrowdPricesCodingSystemRESTService.java
@GET @Produces(MediaType.APPLICATION_JSON)/*from www. j a v a 2 s . c om*/ @Path("{codingsystem}/{language}") public Response getCodes(@PathParam("codingsystem") String codingsystem, @PathParam("language") String language) { try { DATASOURCE ds = DATASOURCE.CROWDPRICES; DBBean db = new DBBean(ds); CrowdPricesCodesConstants c = null; SQLBean sql = null; try { c = CrowdPricesCodesConstants.valueOf(codingsystem.toUpperCase()); } catch (Exception e) { } // System.out.println("c: " +c); if (c != null) { switch (c) { case DATE: sql = SQLBeansRepository.getDates("data", new ArrayList<WhereBean>(), language); break; } } else { sql = SQLBeansRepository.getCodingSystem(codingsystem, new ArrayList<WhereBean>(), language); // sql = SQLBeansRepository.getCodingSystem(codingsystem, new ArrayList<WhereBean>(), language); } // System.out.println(Bean2SQL.convert(sql)); List<List<String>> table = JDBCConnector.query(db, sql, true); // to remove the headers (TODO: add it in the wrapper?) table.remove(0); String json = Wrapper.wrapAsJSON(table).toString(); // wrap result ResponseBuilder builder = Response.ok(json); builder.header("Access-Control-Allow-Origin", "*"); builder.header("Access-Control-Max-Age", "3600"); builder.header("Access-Control-Allow-Methods", "GET"); builder.header("Access-Control-Allow-Headers", "X-Requested-With,Host,User-Agent,Accept,Accept-Language,Accept-Encoding,Accept-Charset,Keep-Alive,Connection,Referer,Origin"); builder.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON + "; charset=utf-8"); // return response return builder.build(); } catch (WDSException e) { return Response.status(500).entity("Error in 'Crowdprices Coding System service: " + e.getMessage()) .build(); } catch (ClassNotFoundException e) { return Response.status(500).entity("Error in 'Crowdprices Coding System service: " + e.getMessage()) .build(); } catch (SQLException e) { return Response.status(500).entity("Error in 'Crowdprices Coding System service: " + e.getMessage()) .build(); } catch (InstantiationException e) { return Response.status(500).entity("Error in 'Crowdprices Coding System service: " + e.getMessage()) .build(); } catch (IllegalAccessException e) { return Response.status(500).entity("Error in 'Crowdprices Coding System service: " + e.getMessage()) .build(); } }
From source file:hello.service.GreetingServiceImpl.java
private void add(final Greeting greeting, final List<Greeting> list) { if (list.size() >= SIZE_LIMIT) { try {// w w w . j a v a 2 s. c o m list.remove(0); } catch (final IndexOutOfBoundsException e) { // ignore concurrent removal } } list.add(greeting); }
From source file:com.mac.holdempoker.app.impl.SimplePlayOrder.java
private void orderPlayers(List<Player> players) { Map<Card, Player> initDealOrder = new TreeMap(this); Deck d = new SimpleDeck(); d.buildDeck();// w ww. ja v a2 s . c o m d.shuffleDeck(); players.stream().forEach((p) -> { initDealOrder.put(d.drawNextCard(), p); }); List<Player> plyrs = new ArrayList(initDealOrder.values()); orderedPlayers = new ArrayList(plyrs.size()); orderedPlayers.add(plyrs.remove(plyrs.size() - 1)); Collections.reverse(plyrs); for (Player p : plyrs) { orderedPlayers.add(0, p); } isFirstOrder = false; }
From source file:csns.web.controller.SectionJournalController.java
@RequestMapping("/section/journal/toggleAssignment") @ResponseStatus(HttpStatus.OK)//from w w w . j av a2 s. co m public void toggleAssignment(@RequestParam Long journalId, @RequestParam Long assignmentId) { User user = SecurityUtils.getUser(); CourseJournal courseJournal = courseJournalDao.getCourseJournal(journalId); Assignment assignment = assignmentDao.getAssignment(assignmentId); List<Assignment> assignments = courseJournal.getAssignments(); if (assignments.contains(assignment)) { assignments.remove(assignment); logger.info(user.getUsername() + " removed assignment " + assignmentId + " from course jorunal " + journalId); } else { assignments.add(assignment); logger.info( user.getUsername() + " added assignment " + assignmentId + " to course jorunal " + journalId); } courseJournalDao.saveCourseJournal(courseJournal); }
From source file:amie.keys.CSAKey.java
private static List<List<String>> simplifyNonKeysSet(List<List<String>> nonKeySet) { List<List<String>> newnonKeySet = new ArrayList<List<String>>(); newnonKeySet.addAll(nonKeySet);/*from www .j a v a 2 s.co m*/ for (List<String> set : nonKeySet) { for (List<String> set2 : nonKeySet) { if (set2 != set && set2.containsAll(set)) { newnonKeySet.remove(set); break; } } } return newnonKeySet; }
From source file:com.gargoylesoftware.htmlunit.runners.TestCaseCorrector.java
private static void addNotYetImplementedMethod(final List<String> lines, int i, final String browserString, final String methodName, final String defaultExpectations) { String parent = methodName;//from ww w . j a v a 2s . c o m final String child = parent.substring(parent.lastIndexOf('_') + 1); parent = parent.substring(1, parent.indexOf('_', 1)); if (!lines.get(i).isEmpty()) { i++; } lines.add(i++, ""); lines.add(i++, " /**"); lines.add(i++, " * @throws Exception if the test fails"); lines.add(i++, " */"); lines.add(i++, " @Test"); lines.add(i++, " @Alerts(\"" + defaultExpectations + "\")"); lines.add(i++, " @NotYetImplemented(" + browserString + ")"); lines.add(i++, " public void _" + parent + "_" + child + "() throws Exception {"); lines.add(i++, " test(\"" + parent + "\", \"" + child + "\");"); lines.add(i++, " }"); lines.add(i++, "}"); while (lines.size() > i) { lines.remove(i); } }
From source file:edu.cmu.cs.lti.discoursedb.io.prosolo.blog.converter.BlogConverter.java
@Override public void run(String... args) throws Exception { if (args.length < 3) { logger.error(//from ww w .j a v a 2 s. c o m "USAGE: BlogConverterApplication <DiscourseName> <DataSetName> <blogDump> <userMapping (optional)> <dumpIsWrappedInJsonArray (optional, default=false)>"); throw new RuntimeException("Incorrect number of launch parameters."); } final String discourseName = args[0]; final String dataSetName = args[1]; if (dataSourceService.dataSourceExists(dataSetName)) { logger.warn("Dataset " + dataSetName + " has already been imported into DiscourseDB. Terminating..."); return; } final String forumDumpFileName = args[2]; File blogDumpFile = new File(forumDumpFileName); if (!blogDumpFile.exists() || !blogDumpFile.isFile() || !blogDumpFile.canRead()) { logger.error("Forum dump file does not exist or is not readable."); throw new RuntimeException("Can't read file " + forumDumpFileName); } //parse the optional fourth and fifth parameter String userMappingFileName = null; String jsonarray = null; if (args.length == 4) { if (args[3].equalsIgnoreCase("true") || args[3].equalsIgnoreCase("false")) { jsonarray = args[3]; } else { userMappingFileName = args[3]; } } else { if (args[3].equalsIgnoreCase("true") || args[3].equalsIgnoreCase("false")) { jsonarray = args[3]; userMappingFileName = args[4]; } else { jsonarray = args[4]; userMappingFileName = args[3]; } } //read the blog author to edX user mapping, if available if (userMappingFileName != null) { logger.trace("Reading user mapping from " + userMappingFileName); File userMappingFile = new File(userMappingFileName); if (!userMappingFile.exists() || !userMappingFile.isFile() || !userMappingFile.canRead()) { logger.error("User mappiong file does not exist or is not readable."); throw new RuntimeException("Can't read file " + userMappingFileName); } List<String> lines = FileUtils.readLines(userMappingFile); lines.remove(0); //remove header for (String line : lines) { String[] blogToedx = line.split(MAPPING_SEPARATOR); //if the current line contained a valid mapping, add it to the map if (blogToedx.length == 2 && blogToedx[0] != null && !blogToedx[0].isEmpty() && blogToedx[1] != null && !blogToedx[1].isEmpty()) { blogToedxMap.put(blogToedx[0], blogToedx[1]); } } } if (jsonarray != null && jsonarray.equalsIgnoreCase(("true"))) { logger.trace("Set reader to expect a json array rather than regular json input."); this.dumpWrappedInJsonArray = true; } /* * Map data to DiscourseDB */ logger.info("Mapping blog posts and comments to DiscourseDB"); try (InputStream in = new FileInputStream(blogDumpFile)) { if (dumpWrappedInJsonArray) { //if the json dump is wrapped in a top-level array @SuppressWarnings("unchecked") List<ProsoloBlogPost> posts = (List<ProsoloBlogPost>) new ObjectMapper() .readValues(new JsonFactory().createParser(in), new TypeReference<List<ProsoloBlogPost>>() { }).next(); posts.stream().forEach(p -> converterService.mapPost(p, discourseName, dataSetName, blogToedxMap)); } else { //if the json dump is NOT wrapped in a top-level array Iterator<ProsoloBlogPost> pit = new ObjectMapper().readValues(new JsonFactory().createParser(in), ProsoloBlogPost.class); Iterable<ProsoloBlogPost> iterable = () -> pit; StreamSupport.stream(iterable.spliterator(), false) .forEach(p -> converterService.mapPost(p, discourseName, dataSetName, blogToedxMap)); } } logger.info("All done."); }