List of usage examples for java.util Collections addAll
@SafeVarargs public static <T> boolean addAll(Collection<? super T> c, T... elements)
From source file:org.elasticsearch.client.RestClientMultipleHostsTests.java
public void testRoundRobinOkStatusCodes() throws IOException { int numIters = RandomNumbers.randomIntBetween(getRandom(), 1, 5); for (int i = 0; i < numIters; i++) { Set<HttpHost> hostsSet = new HashSet<>(); Collections.addAll(hostsSet, httpHosts); for (int j = 0; j < httpHosts.length; j++) { int statusCode = randomOkStatusCode(getRandom()); Response response = restClient.performRequest(randomHttpMethod(getRandom()), "/" + statusCode); assertEquals(statusCode, response.getStatusLine().getStatusCode()); assertTrue("host not found: " + response.getHost(), hostsSet.remove(response.getHost())); }//from www. j a v a2 s . c o m assertEquals("every host should have been used but some weren't: " + hostsSet, 0, hostsSet.size()); } failureListener.assertNotCalled(); }
From source file:com.autentia.wuija.security.impl.hibernate.HibernateSecurityUser.java
/** * En funcin de los {@link #userAuthorities} y de los {@link #groups}, prepara el array {@link #authorities} donde * se almacenan todos los roles del usuario. * <p>/*from w ww. j av a 2s. c om*/ * Este mtodo se ejecuta en el postload (despues de cargar la clase de la capa de persistencia), y cada vez que se * modifican los roles o los grupos del usuario. * <p> * XXX [wuija] qu pasa si se modifican los roles de un grupo?? cmo se entera el usuario?? */ @PostLoad void calculateAuthorities() { log.trace("Entering"); // Usamos un set porque no permite duplicados, as si el mismo rol le viene asignado directamente y en un // grupo, en el array final slo estar una vez. final Set<GrantedAuthority> allAuthorities = new HashSet<GrantedAuthority>(); allAuthorities.addAll(userAuthorities); for (SecurityGroup group : getGroups()) { Collections.addAll(allAuthorities, group.getAuthorities()); } authorities = allAuthorities.isEmpty() ? EMPTY_GRANTED_AUTHORITY_ARRAY : allAuthorities.toArray(new GrantedAuthority[allAuthorities.size()]); log.trace("Exiting"); }
From source file:com.expressui.core.util.BeanPropertyType.java
private boolean initFieldAnnotations(Class containerType) { boolean foundProperty = false; Field field;/*from w w w. j a v a 2s . c o m*/ try { field = containerType.getDeclaredField(id); foundProperty = true; Annotation[] fieldAnnotations = field.getAnnotations(); Collections.addAll(annotations, fieldAnnotations); } catch (NoSuchFieldException e) { // no need to get annotations if field doesn't exist } return foundProperty; }
From source file:co.cask.cdap.gateway.handlers.metrics.MetricsSuiteTestBase.java
public static void stop() { collectionService.stopAndWait();/*w ww . j a v a 2s . c o m*/ Deque<File> files = Lists.newLinkedList(); files.add(dataDir); File file = files.peekLast(); while (file != null) { File[] children = file.listFiles(); if (children == null || children.length == 0) { files.pollLast().delete(); } else { Collections.addAll(files, children); } file = files.peekLast(); } }
From source file:org.osiam.resources.helper.AttributesRemovalHelper.java
private ObjectWriter getObjectWriter(ObjectMapper mapper, String[] fieldsToReturn) { if (fieldsToReturn.length != 0) { mapper.addMixInAnnotations(Object.class, PropertyFilterMixIn.class); HashSet<String> givenFields = new HashSet<>(); givenFields.add("schemas"); Collections.addAll(givenFields, fieldsToReturn); String[] finalFieldsToReturn = givenFields.toArray(new String[givenFields.size()]); FilterProvider filters = new SimpleFilterProvider().addFilter("filter properties by name", SimpleBeanPropertyFilter.filterOutAllExcept(finalFieldsToReturn)); return mapper.writer(filters); }//from w w w.ja va 2 s.c om return mapper.writer(); }
From source file:org.gvsig.framework.web.controllers.OGCInfoController.java
/** * Get bounding box for a layers specified. * The result can be null if the service haven't defined the values * of bounding box./*from ww w . ja v a 2 s .com*/ * * @param request the {@code HttpServletRequest}. * @return ResponseEntity with wmtsInfo */ @RequestMapping(value = "/getLayerBoundingBox", headers = "Accept=application/json", produces = { "application/json; charset=UTF-8" }) @ResponseBody public ResponseEntity<List<String>> getLayersBoundingBoxByAjax(WebRequest request) { List<String> boundingBox = null; String urlServer = request.getParameter("url"); String typeLayer = request.getParameter("type"); String crs = request.getParameter("crs"); String layers = request.getParameter("layers"); if (StringUtils.isNotEmpty(crs) && StringUtils.isNotEmpty(urlServer) && StringUtils.isNotEmpty(typeLayer) && StringUtils.isNotEmpty(layers)) { TreeSet<String> listLayers = new TreeSet<String>(); Collections.addAll(listLayers, layers.split(",")); boundingBox = ogcInfoServ.getLayersBoundingBox(urlServer, typeLayer, crs, listLayers); } return new ResponseEntity<List<String>>(boundingBox, HttpStatus.OK); }
From source file:com.duroty.application.mail.manager.SendManager.java
/** * DOCUMENT ME!/*from www. j a v a2 s . c o m*/ * * @param hsession DOCUMENT ME! * @param session DOCUMENT ME! * @param repositoryName DOCUMENT ME! * @param identity DOCUMENT ME! * @param to DOCUMENT ME! * @param cc DOCUMENT ME! * @param bcc DOCUMENT ME! * @param subject DOCUMENT ME! * @param body DOCUMENT ME! * @param attachments DOCUMENT ME! * @param isHtml DOCUMENT ME! * @param charset DOCUMENT ME! * @param headers DOCUMENT ME! * @param priority DOCUMENT ME! * * @throws MailException DOCUMENT ME! */ public void send(org.hibernate.Session hsession, Session session, String repositoryName, int ideIdint, String to, String cc, String bcc, String subject, String body, Vector attachments, boolean isHtml, String charset, InternetHeaders headers, String priority) throws MailException { try { if (charset == null) { charset = MimeUtility.javaCharset(Charset.defaultCharset().displayName()); } if ((body == null) || body.trim().equals("")) { body = " "; } Email email = null; if (isHtml) { email = new HtmlEmail(); } else { email = new MultiPartEmail(); } email.setCharset(charset); Users user = getUser(hsession, repositoryName); Identity identity = getIdentity(hsession, ideIdint, user); InternetAddress _returnPath = new InternetAddress(identity.getIdeEmail(), identity.getIdeName()); InternetAddress _from = new InternetAddress(identity.getIdeEmail(), identity.getIdeName()); InternetAddress _replyTo = new InternetAddress(identity.getIdeReplyTo(), identity.getIdeName()); InternetAddress[] _to = MessageUtilities.encodeAddresses(to, null); InternetAddress[] _cc = MessageUtilities.encodeAddresses(cc, null); InternetAddress[] _bcc = MessageUtilities.encodeAddresses(bcc, null); if (_from != null) { email.setFrom(_from.getAddress(), _from.getPersonal()); } if (_returnPath != null) { email.addHeader("Return-Path", _returnPath.getAddress()); email.addHeader("Errors-To", _returnPath.getAddress()); email.addHeader("X-Errors-To", _returnPath.getAddress()); } if (_replyTo != null) { email.addReplyTo(_replyTo.getAddress(), _replyTo.getPersonal()); } if ((_to != null) && (_to.length > 0)) { HashSet aux = new HashSet(_to.length); Collections.addAll(aux, _to); email.setTo(aux); } if ((_cc != null) && (_cc.length > 0)) { HashSet aux = new HashSet(_cc.length); Collections.addAll(aux, _cc); email.setCc(aux); } if ((_bcc != null) && (_bcc.length > 0)) { HashSet aux = new HashSet(_bcc.length); Collections.addAll(aux, _bcc); email.setBcc(aux); } email.setSubject(subject); Date now = new Date(); email.setSentDate(now); File dir = new File(System.getProperty("user.home") + File.separator + "tmp"); if (!dir.exists()) { dir.mkdir(); } if ((attachments != null) && (attachments.size() > 0)) { for (int i = 0; i < attachments.size(); i++) { ByteArrayInputStream bais = null; FileOutputStream fos = null; try { MailPartObj obj = (MailPartObj) attachments.get(i); File file = new File(dir, obj.getName()); bais = new ByteArrayInputStream(obj.getAttachent()); fos = new FileOutputStream(file); IOUtils.copy(bais, fos); EmailAttachment attachment = new EmailAttachment(); attachment.setPath(file.getPath()); attachment.setDisposition(EmailAttachment.ATTACHMENT); attachment.setDescription("File Attachment: " + file.getName()); attachment.setName(file.getName()); if (email instanceof MultiPartEmail) { ((MultiPartEmail) email).attach(attachment); } } catch (Exception ex) { } finally { IOUtils.closeQuietly(bais); IOUtils.closeQuietly(fos); } } } String mid = getId(); if (headers != null) { Header xheader; Enumeration xe = headers.getAllHeaders(); for (; xe.hasMoreElements();) { xheader = (Header) xe.nextElement(); if (xheader.getName().equals(RFC2822Headers.IN_REPLY_TO)) { email.addHeader(xheader.getName(), xheader.getValue()); } else if (xheader.getName().equals(RFC2822Headers.REFERENCES)) { email.addHeader(xheader.getName(), xheader.getValue()); } } } else { email.addHeader(RFC2822Headers.IN_REPLY_TO, "<" + mid + ".JavaMail.duroty@duroty" + ">"); email.addHeader(RFC2822Headers.REFERENCES, "<" + mid + ".JavaMail.duroty@duroty" + ">"); } if (priority != null) { if (priority.equals("high")) { email.addHeader("Importance", priority); email.addHeader("X-priority", "1"); } else if (priority.equals("low")) { email.addHeader("Importance", priority); email.addHeader("X-priority", "5"); } } if (email instanceof HtmlEmail) { ((HtmlEmail) email).setHtmlMsg(body); } else { email.setMsg(body); } email.setMailSession(session); email.buildMimeMessage(); MimeMessage mime = email.getMimeMessage(); int size = MessageUtilities.getMessageSize(mime); if (!controlQuota(hsession, user, size)) { throw new MailException("ErrorMessages.mail.quota.exceded"); } messageable.saveSentMessage(mid, mime, user); Thread thread = new Thread(new SendMessageThread(email)); thread.start(); } catch (MailException e) { throw e; } catch (Exception e) { throw new MailException(e); } catch (java.lang.OutOfMemoryError ex) { System.gc(); throw new MailException(ex); } catch (Throwable e) { throw new MailException(e); } finally { GeneralOperations.closeHibernateSession(hsession); } }
From source file:de.hybris.platform.acceleratorservices.cronjob.SiteMapMediaJob.java
protected List<List> splitUpTheListIfExceededLimit(final List models, final Integer maxSiteMapUrlLimit) { final int limit = maxSiteMapUrlLimit.intValue(); final int modelListSize = models.size() / limit; final List<List> modelsList = new ArrayList<>(modelListSize); for (int i = 0; i <= modelListSize; i++) { final int subListToLimit = (i == modelListSize) ? ((i * limit) + (models.size() - (i * limit))) : ((i + 1) * limit);/*from ww w . j a va2s . c o m*/ Collections.addAll(modelsList, models.subList((i * limit), subListToLimit)); } return modelsList; }
From source file:com.webarch.common.lang.StringSeriesTools.java
/** * ?n?/*from ww w . ja va 2 s .c om*/ * * @param n in< * @param type 1?23? * @return String */ public static String getRanDomStr(final int n, final int type) { String[] charset; String[] charsetAll = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"}; String[] charsetNum = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"}; String[] charsetChar = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"}; switch (type) { case 1: charset = charsetAll; break; case 2: charset = charsetNum; break; case 3: charset = charsetChar; break; default: charset = charsetAll; } Random random = new Random(); String[] nonces = new String[n]; // List<String> choose = new ArrayList<String>(charset.length); //?? Collections.addAll(choose, charset); int nl = n; while (nl-- > 0) { int k = random.nextInt(choose.size()); nonces[nl] = choose.get(k); choose.remove(k); } //?str String nonce = ""; for (String str : nonces) { nonce += str; } return nonce; }
From source file:it.unibz.instasearch.ui.InstaSearchPage.java
private Set<String> getSelectedExtensions() { TreeSet<String> extSet = new TreeSet<String>(); String exts = extensionEditor.getStringValue(); if (exts != null && !"".equals(exts) && !"*".equals(exts)) { exts = exts.replace(" ", ""); exts = exts.replace("*.", ""); Collections.addAll(extSet, exts.split(",")); }/* w w w .j av a2s . co m*/ return extSet; }