List of usage examples for java.util Collection toArray
default <T> T[] toArray(IntFunction<T[]> generator)
From source file:edu.cornell.mannlib.vitro.webapp.search.controller.AutocompleteController.java
@Override protected void doRequest(VitroRequest vreq, HttpServletResponse response) throws IOException, ServletException { try {/* ww w .j a v a 2s . c om*/ String qtxt = vreq.getParameter(PARAM_QUERY); String typeParam = vreq.getParameter(PARAM_RDFTYPE); if (typeParam != null) { String[] parts = typeParam.split(","); if (parts.length > 1) { hasMultipleTypes = true; } else if (parts.length == 1) { String askQuery = "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> \n" + "ASK { ?something rdfs:subClassOf <" + typeParam.replace(",", "") + "> }"; if (getRdfService(vreq).sparqlAskQuery(askQuery)) { hasMultipleTypes = true; } } } else { //if the type parameter is null, no range is specified and individuals of any class might be returned //in this case, it would be useful to show the most specific type of the individual hasMultipleTypes = true; } SearchQuery query = getQuery(qtxt, vreq); if (query == null) { log.debug("query for '" + qtxt + "' is null."); doNoQuery(response); return; } log.debug("query for '" + qtxt + "' is " + query.toString()); SearchEngine search = ApplicationUtils.instance().getSearchEngine(); SearchResponse queryResponse = search.query(query); if (queryResponse == null) { log.error("Query response for a search was null"); doNoSearchResults(response); return; } SearchResultDocumentList docs = queryResponse.getResults(); if (docs == null) { log.error("Docs for a search was null"); doNoSearchResults(response); return; } long hitCount = docs.getNumFound(); log.debug("Total number of hits = " + hitCount); if (hitCount < 1) { doNoSearchResults(response); return; } List<SearchResult> results = new ArrayList<SearchResult>(); for (SearchResultDocument doc : docs) { try { String uri = doc.getStringValue(VitroSearchTermNames.URI); String name = doc.getStringValue(VitroSearchTermNames.NAME_RAW); //There may be multiple most specific types, sending them all back String mst = doc.getStringValue(VitroSearchTermNames.MOST_SPECIFIC_TYPE_URIS); //Assuming these will get me string values Collection<Object> mstObjValues = doc .getFieldValues(VitroSearchTermNames.MOST_SPECIFIC_TYPE_URIS); String[] mstStringValues = mstObjValues.toArray(new String[mstObjValues.size()]); List<String> mstValues = Arrays.asList(mstStringValues); SearchResult result = new SearchResult(name, uri, mst, mstValues, hasMultipleTypes, vreq); results.add(result); log.debug("results = " + results.toString()); } catch (Exception e) { log.error("problem getting usable individuals from search " + "hits" + e.getMessage()); } } // now that we have the search result, reset this boolean hasMultipleTypes = false; Collections.sort(results); JSONArray jsonArray = new JSONArray(); for (SearchResult result : results) { //jsonArray.put(result.toMap()); jsonArray.put(result.toJSONObject()); } response.getWriter().write(jsonArray.toString()); } catch (Throwable e) { log.error(e, e); doSearchError(response); } }
From source file:uk.ac.ebi.intact.editor.security.EditorAuthenticationProvider.java
public Authentication authenticate(Authentication authentication) throws AuthenticationException { log.debug("======================= AUTHENTICATE ======================"); if (log.isDebugEnabled()) { log.debug("Currently, there are " + userManagerController.getLoggedInUsers().size() + " users connected."); log.debug("Authenticating user: " + authentication.getPrincipal()); }/*from ww w . j a v a 2 s . c om*/ final User user = loadIntactUser(authentication); // get all the "user listener" beans and notify the login final Map<String, UserListener> userListeners = ApplicationContextProvider.getApplicationContext() .getBeansOfType(UserListener.class); for (UserListener userListener : userListeners.values()) { userListener.userLoggedIn(user); } Collection<GrantedAuthority> authorities = Lists.newArrayList(); log.info(user.getLogin() + " roles: " + user.getRoles()); for (Role role : user.getRoles()) { final String authorityName = "ROLE_" + role.getName(); log.info("Adding GrantedAuthority: '" + authorityName + "'"); authorities.add(new GrantedAuthorityImpl(authorityName)); } return new UsernamePasswordAuthenticationToken(authentication.getPrincipal(), authentication.getCredentials(), authorities.toArray(new GrantedAuthority[authorities.size()])); }
From source file:net.sourceforge.wurfl.core.GeneralWURFLEngine.java
/** * {@inheritDoc}/*from w w w . j a v a2 s . co m*/ */ public final void setCapabilityFilter(Collection<String> capabilityFilter) { if (capabilityFilter != null) { this.capabilityFilter = capabilityFilter.toArray(new String[0]); } }
From source file:jp.terasoluna.fw.util.StringUtil.java
/** * CSV???????/*from w w w. jav a2s. c o m*/ * * <p> * ??? * ????????????????? * ????????????????????? * ??</p> * <p>?????????????</p> * <p>csvString ? null ??????? * ?0????? * * @param csvString CSV?? * @return ???????? */ public static String[] parseCSV(String csvString) { if (csvString == null) { return new String[0]; } if ("".equals(csvString)) { return new String[] { csvString }; } Collection<String> result = new ArrayList<String>(); char[] chars = csvString.toCharArray(); int prevCommaIndex = -1; for (int i = 0; i < chars.length; i++) { if (chars[i] == ',') { if (i == prevCommaIndex + 1) { result.add(""); } else { result.add(new String(chars, prevCommaIndex + 1, i - (prevCommaIndex + 1))); } if (i == chars.length - 1) { result.add(""); } prevCommaIndex = i; } else if (i == chars.length - 1) { result.add(new String(chars, prevCommaIndex + 1, i - (prevCommaIndex + 1) + 1)); } } return result.toArray(new String[0]); }
From source file:com.silverpeas.gallery.process.GalleryProcessManagement.java
/** * Adds processes to delete all media from the given album * @param albumPk//www.j ava 2 s.com * @throws Exception */ private void addDeleteMediaAlbumProcesses(final NodePK albumPk) throws Exception { for (final Media media : getGalleryBm().getAllMedia(albumPk, MediaCriteria.VISIBILITY.FORCE_GET_ALL)) { Collection<String> albumIds = getGalleryBm().getAlbumIdsOf(media); if (albumIds.size() > 1) { // the image is in several albums // delete only the link between it and album to delete albumIds.remove(albumPk.getId()); media.setToAlbums(albumIds.toArray(new String[albumIds.size()])); } else { addDeleteMediaProcesses(media); } } }
From source file:org.yukung.daguerreo.domain.repository.BasicJooqRepository.java
@SuppressWarnings("SuspiciousToArrayCall") private Condition in(Field<?>[] pk, Collection<ID> ids) { if (pk.length == 1) { if (ids.size() == 1) { return equal(pk, ids.iterator().next()); } else {/*from w w w . j a v a 2s . c om*/ return pk[0].in(pk[0].getDataType().convert(ids)); } } else { return row(pk).in(ids.toArray(new Record[ids.size()])); } }
From source file:com.buaa.cfs.security.Groups.java
private void parseStaticMapping(Configuration conf) { String staticMapping = conf.get(CommonConfigurationKeys.HADOOP_USER_GROUP_STATIC_OVERRIDES, CommonConfigurationKeys.HADOOP_USER_GROUP_STATIC_OVERRIDES_DEFAULT); Collection<String> mappings = StringUtils.getStringCollection(staticMapping, ";"); for (String users : mappings) { Collection<String> userToGroups = StringUtils.getStringCollection(users, "="); if (userToGroups.size() < 1 || userToGroups.size() > 2) { throw new HadoopIllegalArgumentException("Configuration " + CommonConfigurationKeys.HADOOP_USER_GROUP_STATIC_OVERRIDES + " is invalid"); }// w w w .j a v a 2s .co m String[] userToGroupsArray = userToGroups.toArray(new String[userToGroups.size()]); String user = userToGroupsArray[0]; List<String> groups = Collections.emptyList(); if (userToGroupsArray.length == 2) { groups = (List<String>) StringUtils.getStringCollection(userToGroupsArray[1]); } staticUserToGroupsMap.put(user, groups); } }
From source file:com.liferay.portal.search.solr.internal.SolrIndexSearcher.java
protected Document processSolrDocument(SolrDocument solrDocument, QueryConfig queryConfig) { Document document = new DocumentImpl(); Collection<String> fieldNames = solrDocument.getFieldNames(); for (String fieldName : fieldNames) { Collection<Object> fieldValues = solrDocument.getFieldValues(fieldName); Field field = new Field(fieldName, ArrayUtil.toStringArray(fieldValues.toArray(new Object[fieldValues.size()]))); document.add(field);/* w ww. j a v a 2 s.c o m*/ } populateUID(document, queryConfig); return document; }
From source file:net.systran.platform.geographic.client.ApiClient.java
/** * Format the given parameter object into string. *//*from ww w . j a v a2s . c o m*/ public Object parameterToString(Object param) { if (param == null) { return ""; } else if (param instanceof Date) { return formatDate((Date) param); } else if (param instanceof Collection) { StringBuilder b = new StringBuilder(); for (Object o : (Collection) param) { if (o instanceof String) { Collection<String> pa = (Collection) param; return pa.toArray(new String[pa.size()]); } if (b.length() > 0) { b.append(","); } b.append(String.valueOf(o)); } return b.toString(); } else { return String.valueOf(param); } }
From source file:de.evaluationtool.gui.EvaluationFrameActionListener.java
private ReferenceFormat formatChooser(Collection<ReferenceFormat> formats) { ReferenceFormat[] formatsArray = formats.toArray(new ReferenceFormat[0]); String[] options = new String[formats.size()]; for (int i = 0; i < formats.size(); i++) { options[i] = formatsArray[i].getDescription(); }/*from www. ja va 2 s.c o m*/ int result = JOptionPane.showOptionDialog(frame, "Please choose a reference format.", "Choose a reference format", JOptionPane.OK_CANCEL_OPTION, JOptionPane.INFORMATION_MESSAGE, null, options, options[0]); if (result == JOptionPane.CLOSED_OPTION) return null; return formatsArray[result]; }