List of usage examples for java.util Collection toArray
default <T> T[] toArray(IntFunction<T[]> generator)
From source file:com.espertech.esper.core.context.util.StatementAgentInstanceUtil.java
public static void stopSafe(Collection<StopCallback> terminationCallbacks, StopCallback[] stopCallbacks, StatementContext statementContext) { StopCallback[] terminationArr = terminationCallbacks.toArray(new StopCallback[terminationCallbacks.size()]); stopSafe(terminationArr, statementContext); stopSafe(stopCallbacks, statementContext); }
From source file:com.gc.iotools.fmt.base.TestUtils.java
public static String[] listFilesExcludingExtension(final String[] forbidden) throws IOException { final URL fileURL = TestUtils.class.getResource("/testFiles"); String filePath = URLDecoder.decode(fileURL.getPath(), "UTF-8"); final File dir = new File(filePath); final String[] files = dir.list(); final Collection<String> goodFiles = new Vector<String>(); if (!filePath.endsWith(File.separator)) { filePath = filePath + File.separator; }//w ww .ja v a 2 s . co m for (final String file : files) { boolean insert = true; for (final String extForbidden : forbidden) { insert &= !(file.endsWith(extForbidden)); } if (insert) { goodFiles.add(filePath + file); } } return goodFiles.toArray(new String[goodFiles.size()]); }
From source file:com.symbian.driver.remoting.packaging.build.PackageBuilder.java
/** * @param directory/* w w w . ja v a 2s . c o m*/ * @param filter * @param recurse * @return */ public static File[] listFilesAsArray(File directory, FilenameFilter filter, boolean recurse) { Collection<File> lFiles = listFiles(directory, filter, recurse); File[] lArrayFiles = new File[lFiles.size()]; return lFiles.toArray(lArrayFiles); }
From source file:com.abiquo.abiserver.pojo.user.User.java
@SuppressWarnings("unchecked") public static User create(final UserDto dto, final Enterprise enterprise, final Role role) { User user = new User(); user.setId(dto.getId());//from w ww. j a v a2 s .com user.setEnterprise(enterprise); user.setRole(role); user.setUser(dto.getNick()); user.setName(dto.getName()); user.setSurname(dto.getSurname()); user.setDescription(dto.getDescription()); user.setEmail(dto.getEmail()); user.setLocale(dto.getLocale()); user.setPass(dto.getPassword()); user.setActive(dto.isActive()); user.setAuthType( StringUtils.isBlank(dto.getAuthType()) ? AuthType.ABIQUO : AuthType.valueOf(dto.getAuthType())); if (!StringUtils.isEmpty(dto.getAvailableVirtualDatacenters())) { String[] ids = dto.getAvailableVirtualDatacenters().split(","); Collection<Integer> idsI = CollectionUtils.collect(Arrays.asList(ids), new Transformer() { @Override public Object transform(final Object input) { return Integer.valueOf(input.toString()); } }); user.setAvailableVirtualDatacenters(idsI.toArray(new Integer[idsI.size()])); } else { user.setAvailableVirtualDatacenters(new Integer[] {}); } user.setCreationDate(Calendar.getInstance().getTime()); return user; }
From source file:com.moviejukebox.tools.StringTools.java
public static String[] tokenizeToArray(String sourceString, String delimiter) { StringTokenizer st = new StringTokenizer(sourceString, delimiter); Collection<String> keywords = new ArrayList<>(); while (st.hasMoreTokens()) { keywords.add(st.nextToken());//from w ww .j a va 2s. com } return keywords.toArray(new String[keywords.size()]); }
From source file:com.bjond.utilities.MiscUtils.java
/** * <code>toArray</code> method will convert the collection of T to a corresponding array of T. * This is a convenience method which is somewhat simpler and hides some of the details. * The syntax of Java never makes this syntax easy. This is the best I can accomplish. * * example usage: /*from w w w. j a v a 2s . com*/ Collection<User> users = identityService.getAllMembers(group); Users[] userArray = MiscUtils.<User>toArray(users, User.class) * * * @param <T> Type of class c returned. * @param collection <code>java.util.Collection<T></code> value * @param c <code>Class<T></code> value * @return T <code>T[]</code> value */ @SuppressWarnings("unchecked") public static <T> T[] toArray(Collection<? extends T> collection, Class<T> c) { return collection.toArray((T[]) java.lang.reflect.Array.newInstance(c, collection.size())); }
From source file:com.carrotsearch.util.httpclient.HttpUtils.java
/** * Opens a HTTP/1.1 connection to the given URL using the GET method, decompresses * compressed response streams, if supported by the server. * //from w w w .ja v a 2 s. c o m * @param url The URL to open. The URL must be properly escaped, this method will * <b>not</b> perform any escaping. * @param params Query string parameters to be attached to the url. * @param headers Any extra HTTP headers to add to the request. * @return The {@link HttpUtils.Response} object. Note that entire payload is read and * buffered so that the HTTP connection can be closed when leaving this * method. */ public static Response doGET(String url, Collection<NameValuePair> params, Collection<Header> headers) throws HttpException, IOException { final HttpClient client = HttpClientFactory.getTimeoutingClient(); client.getParams().setVersion(HttpVersion.HTTP_1_1); final GetMethod request = new GetMethod(); final Response response = new Response(); try { request.setURI(new URI(url, true)); if (params != null) { request.setQueryString(params.toArray(new NameValuePair[params.size()])); } request.setRequestHeader(HttpHeaders.URL_ENCODED); request.setRequestHeader(HttpHeaders.GZIP_ENCODING); if (headers != null) { for (Header header : headers) request.setRequestHeader(header); } Logger.getLogger(HttpUtils.class).debug("GET: " + request.getURI()); final int statusCode = client.executeMethod(request); response.status = statusCode; InputStream stream = request.getResponseBodyAsStream(); final Header encoded = request.getResponseHeader("Content-Encoding"); if (encoded != null && "gzip".equalsIgnoreCase(encoded.getValue())) { stream = new GZIPInputStream(stream); response.compression = COMPRESSION_GZIP; } else { response.compression = COMPRESSION_NONE; } final Header[] respHeaders = request.getResponseHeaders(); response.headers = new String[respHeaders.length][]; for (int i = 0; i < respHeaders.length; i++) { response.headers[i] = new String[] { respHeaders[i].getName(), respHeaders[i].getValue() }; } response.payload = StreamUtils.readFullyAndClose(stream); return response; } finally { request.releaseConnection(); } }
From source file:com.jroossien.boxx.util.Str.java
/** * @see Str#bestMatch(String, String...) *///from www . j ava2 s .c o m public static String bestMatch(String input, Collection<? extends String> values) { return bestMatch(input, values.toArray(new String[values.size()])); }
From source file:com.persistent.cloudninja.controller.AuthFilterUtils.java
/** * // w w w.java2s. com * @param cloudNinjaUser * @param cookieName * @return */ public static Cookie createNewCookieForACSAuthenticatedUser(CloudNinjaUser cloudNinjaUser, String cookieName) { Collection<GrantedAuthority> authorities = cloudNinjaUser.getUser().getAuthorities(); if (authorities != null) { GrantedAuthority[] grantedAuthorities = new GrantedAuthority[authorities.size()]; authorities.toArray(grantedAuthorities); } StringBuffer sb = new StringBuffer(5); sb.append(CloudNinjaConstants.COOKIE_TENANTID_PREFIX) .append(CloudNinjaConstants.COOKIE_FIELD_AND_VALUE_SEPARATOR).append(cloudNinjaUser.getTenantId()) .append(CloudNinjaConstants.COOKIE_FIELDS_SEPARATOR); sb.append(CloudNinjaConstants.COOKIE_USERNAME_PREFIX) .append(CloudNinjaConstants.COOKIE_FIELD_AND_VALUE_SEPARATOR) .append(cloudNinjaUser.getUser().getUsername()).append(CloudNinjaConstants.COOKIE_FIELDS_SEPARATOR); sb.append(CloudNinjaConstants.COOKIE_AUTHORITIES_PREFIX) .append(CloudNinjaConstants.COOKIE_FIELD_AND_VALUE_SEPARATOR).append(authorities.toString()) .append(CloudNinjaConstants.COOKIE_FIELDS_SEPARATOR); sb.append(CloudNinjaConstants.COOKIE_AUTH_SESSION_START_PREFIX) .append(CloudNinjaConstants.COOKIE_FIELD_AND_VALUE_SEPARATOR) .append(cloudNinjaUser.getAuthenticatedSessionStartTime().getTime()) .append(CloudNinjaConstants.COOKIE_FIELDS_SEPARATOR); sb.append(CloudNinjaConstants.COOKIE_AUTH_SESSION_END_PREFIX) .append(CloudNinjaConstants.COOKIE_FIELD_AND_VALUE_SEPARATOR) .append(cloudNinjaUser.getAuthenticatedSessionExpiryTime().getTime()) .append(CloudNinjaConstants.COOKIE_FIELDS_SEPARATOR); String newCookieValue = sb.toString(); Cookie newCookie = new Cookie(cookieName, newCookieValue); newCookie.setPath("/"); return newCookie; }
From source file:com.cloudmine.api.rest.JsonUtilities.java
/** * Enclose all the passed in strings in a JSON collection * @param jsonEntities JSON strings to put in the collection * @return { jsonEntities[0], jsonEntities[1], ...} *//* www.jav a 2 s .c om*/ public static Transportable jsonStringsCollection(Collection<String> jsonEntities) { return jsonCollection(jsonEntities.toArray(new String[jsonEntities.size()])); }