List of usage examples for java.util ArrayList toArray
@SuppressWarnings("unchecked") public <T> T[] toArray(T[] a)
From source file:com.palantir.atlasdb.keyvalue.impl.partition.FailableKeyValueServices.java
public static DynamicPartitionMap createInMemoryMap(Collection<? extends KeyValueService> services, QuorumParameters parameters) {/*from ww w.j av a 2s. co m*/ ArrayList<Byte> keyList = new ArrayList<>(); NavigableMap<byte[], KeyValueEndpoint> ring = Maps.newTreeMap(UnsignedBytes.lexicographicalComparator()); keyList.add((byte) 0); for (KeyValueService kvs : services) { KeyValueEndpoint endpoint = InMemoryKeyValueEndpoint.create(kvs, InMemoryPartitionMapService.createEmpty()); byte[] key = ArrayUtils.toPrimitive(keyList.toArray(new Byte[keyList.size()])); ring.put(key, endpoint); keyList.add((byte) 0); } DynamicPartitionMap partitionMap = DynamicPartitionMapImpl.create(parameters, ring, PTExecutors.newCachedThreadPool()); for (KeyValueEndpoint endpoint : ring.values()) { endpoint.partitionMapService().updateMap(partitionMap); } return partitionMap; }
From source file:Main.java
/** * Compare two dumps and get a list of all indices where * they differ from each other./*from ww w . ja v a 2 s.c om*/ * @param dump1 The first dump. The sector number is key and the * string array represents the blocks. * @param dump2 The second dump. The sector number is key and the * string array represents the blocks. * @return Indices where the two dumps differ. The key represents * the sector number. The first dimension of the value represents the * block number and the second is a list of indices where dump2 is * different from dump1. If the value is Integer[0][0] then the sector * exists only in dump1. If the value is Integer[1][0] then the sector * exists only in dump2. */ public static SparseArray<Integer[][]> diffIndices(SparseArray<String[]> dump1, SparseArray<String[]> dump2) { SparseArray<Integer[][]> ret = new SparseArray<Integer[][]>(); // Walk through all sectors of dump1. for (int i = 0; i < dump1.size(); i++) { String[] sector1 = dump1.valueAt(i); int sectorNr = dump1.keyAt(i); String[] sector2 = dump2.get(sectorNr); // Check if dump2 has the current sector of dump1. if (sector2 == null) { ret.put(sectorNr, new Integer[0][0]); continue; } // Check the blocks. Integer[][] diffSector = new Integer[sector1.length][]; // Walk through all blocks. for (int j = 0; j < sector1.length; j++) { ArrayList<Integer> diffIndices = new ArrayList<Integer>(); // Walk through all symbols. for (int k = 0; k < sector1[j].length(); k++) { if (sector1[j].charAt(k) != sector2[j].charAt(k)) { // Found different symbol at index k. diffIndices.add(k); } } if (diffIndices.size() == 0) { // Block was identical. diffSector[j] = new Integer[0]; } else { diffSector[j] = diffIndices.toArray(new Integer[diffIndices.size()]); } } ret.put(sectorNr, diffSector); } // Are there sectors that occur only in dump2? for (int i = 0; i < dump2.size(); i++) { int sectorNr = dump2.keyAt(i); if (dump1.get(sectorNr) == null) { // Sector only exists in dump2. ret.put(sectorNr, new Integer[1][0]); } } return ret; }
From source file:de.arago.portlet.util.UserContainer.java
public static String[] getUserGroups(String userId) { if (userId == null || userId.isEmpty()) return new String[0]; ArrayList<String> result = new ArrayList<String>(); try {//from w ww . ja v a 2s. co m List<UserGroup> groups = UserGroupLocalServiceUtil.getUserUserGroups(Long.valueOf(userId, 10)); for (UserGroup g : groups) { result.add(g.getName()); } } catch (Exception ex) { Logger.getLogger(SecurityHelper.class.getName()).log(Level.SEVERE, null, ex); } return result.toArray(new String[0]); }
From source file:org.prx.playerhater.util.PlaylistParser.java
private static Uri[] parsePls(Uri uri) { try {//from ww w . ja v a 2 s. com HttpClient httpclient = new DefaultHttpClient(); HttpResponse response = httpclient.execute(new HttpGet(uri.toString())); HttpEntity entity = response.getEntity(); InputStream inputStream = entity.getContent(); BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream)); String header = reader.readLine(); if (header.trim().equalsIgnoreCase("[playlist]")) { String line; ArrayList<Uri> uriList = new ArrayList<Uri>(); do { line = reader.readLine(); if (line != null) { if (line.startsWith("File")) { String fileName = line.substring(line.indexOf("=") + 1).trim(); uriList.add(Uri.parse(fileName)); } } } while (line != null); if (uriList.size() > 0) { Uri[] res = new Uri[uriList.size()]; return uriList.toArray(res); } } } catch (Exception e) { e.printStackTrace(); } return new Uri[] { uri }; }
From source file:de.kapsi.net.daap.DaapHeaderConstructor.java
/** * Creates a new Chunk Header/*from ww w. j av a 2s . c o m*/ * * @param request * @param contentLength * @return */ public static byte[] createChunkHeader(DaapRequest request, int contentLength) { try { DaapConnection connection = request.getConnection(); String serverName = connection.getServer().getConfig().getServerName(); ArrayList headers = new ArrayList(); headers.add(new Header("Date", DaapUtil.now())); headers.add(new Header("DAAP-Server", serverName)); headers.add(new Header("Content-Type", "application/x-dmap-tagged")); headers.add(new Header("Content-Length", Integer.toString(contentLength))); if (DaapUtil.COMPRESS) { headers.add(new Header("Content-Encoding", "gzip")); } return toByteArray(HTTP_OK, (Header[]) headers.toArray(new Header[0])); } catch (UnsupportedEncodingException err) { // Should never happen throw new RuntimeException(err); } catch (IOException err) { // Should never happen throw new RuntimeException(err); } }
From source file:de.zib.gndms.gritserv.delegation.DelegationAux.java
public static void addDelegationEPR(ContextT con, EndpointReferenceType epr) throws IOException, SerializationException { ContextTEntry[] entries = con.getEntry(); ArrayList<ContextTEntry> al; if (entries != null) { al = new ArrayList<ContextTEntry>(entries.length + 1); for (ContextTEntry e : entries) al.add(e);/* ww w.j a v a 2s.c o m*/ } else al = new ArrayList<ContextTEntry>(1); ContextTEntry ct = new ContextTEntry(); ct.set_value(encodeDelegationEPR(epr)); ct.setKey(new Token(DELEGATION_EPR_KEY)); al.add(ct); con.setEntry(al.toArray(new ContextTEntry[al.size()])); }
From source file:com.hihframework.core.utils.BeanUtils.java
public static Object[] getArgs(Object obj, String... excludes) { ArrayList<Object> args = new ArrayList<Object>(); String[] fieldsName = ReflectUtil.getAllFieldsName(obj); for (String fieldName : fieldsName) { Object value = ReflectUtil.getFieldValue(obj, fieldName); if (fieldName.equals("id")) continue; for (String exclude : excludes) { if (fieldName.equals(exclude)) continue; }//from ww w . ja v a2 s .c om if (value != null) { args.add(value); } } return args.toArray(new Object[args.size()]); }
From source file:com.erudika.para.utils.ValidationUtils.java
/** * Validates objects using Hibernate Validator. * @param content an object to be validated * @return a list of error messages or empty if object is valid *//*from w ww . java 2 s . c o m*/ public static String[] validateObject(ParaObject content) { if (content == null) { return new String[] { "Object cannot be null." }; } ArrayList<String> list = new ArrayList<String>(); try { for (ConstraintViolation<ParaObject> constraintViolation : getValidator().validate(content)) { String prop = "'".concat(constraintViolation.getPropertyPath().toString()).concat("'"); list.add(prop.concat(" ").concat(constraintViolation.getMessage())); } } catch (Exception e) { logger.error(null, e); } return list.toArray(new String[] {}); }
From source file:com.qtplaf.library.util.StringUtils.java
/** * Parse a comma separated list of strings "S1, S2, S3". * * @param string The string to be tokenized. * @return the array of tokens./*from w w w . ja va 2 s . c o m*/ */ public static String[] parseCommaSeparatedStrings(String string) { StringTokenizer tokenizer = new StringTokenizer(string, ","); ArrayList<String> list = new ArrayList<>(); while (tokenizer.hasMoreTokens()) { list.add(tokenizer.nextToken().trim()); } return list.toArray(new String[list.size()]); }
From source file:com.qtplaf.library.util.StringUtils.java
/** * Parse a string/*from w w w . j ava 2 s .co m*/ * * @param string The string to parse. * @param separator The separator. * @return the array of tokens */ public static String[] parse(String string, String separator) { StringTokenizer tokenizer = new StringTokenizer(string, separator); ArrayList<String> list = new ArrayList<>(); while (tokenizer.hasMoreTokens()) { list.add(tokenizer.nextToken().trim()); } return list.toArray(new String[list.size()]); }