List of usage examples for java.util Collections addAll
@SafeVarargs public static <T> boolean addAll(Collection<? super T> c, T... elements)
From source file:com.asakusafw.directio.tools.DirectIoList.java
@Override public int run(String[] args) throws Exception { LinkedList<String> argList = new LinkedList<>(); Collections.addAll(argList, args); while (argList.isEmpty() == false) { String arg = argList.removeFirst(); if (arg.equals("--")) { //$NON-NLS-1$ break; } else {//from www . jav a2 s. c o m argList.addFirst(arg); break; } } if (argList.size() < 2) { LOG.error(MessageFormat.format("Invalid arguments: {0}", Arrays.toString(args))); System.err.println(MessageFormat.format( "Usage: hadoop {0} -conf <datasource-conf.xml> base-path resource-pattern [resource-pattern [...]]", getClass().getName())); return 1; } String path = argList.removeFirst(); List<FilePattern> patterns = new ArrayList<>(); for (String arg : argList) { patterns.add(FilePattern.compile(arg)); } if (repository == null) { repository = HadoopDataSourceUtil.loadRepository(getConf()); } String basePath = repository.getComponentPath(path); DirectDataSource source = repository.getRelatedDataSource(path); for (FilePattern pattern : patterns) { List<ResourceInfo> list = source.list(basePath, pattern, new Counter()); for (ResourceInfo info : list) { System.out.println(info.getPath()); } } return 0; }
From source file:com.uber.stream.kafka.chaperone.collector.Deduplicator.java
public Deduplicator(int id, String redisHost, int redisPort, int keyTTLInSec, String dupHostPrefix, String hostsWithDup) {//from w ww . j a v a2 s. c om this.identity = id; this.redisHost = redisHost; this.redisPort = redisPort; this.keyTTLInSec = keyTTLInSec; this.hasDupHostPrefix = !StringUtils.isEmpty(dupHostPrefix); this.dupHostPrefix = dupHostPrefix; String[] hosts = hostsWithDup.split(","); this.hostSetWithDup = new HashSet<>(); Collections.addAll(hostSetWithDup, hosts); logger.info("Hosts that might send out duplicate msg: {} and dupHostPrefix={}", hostSetWithDup, dupHostPrefix); OLD_RECORDS_DETECTED = Metrics.getRegistry() .meter(String.format("deduplicator.%d.oldRecordsDetected", identity)); DUP_RECORDS_DETECTED = Metrics.getRegistry() .meter(String.format("deduplicator.%d.dupRecordsDetected", identity)); REDIS_CAS_FAILURE = Metrics.getRegistry() .meter(String.format("deduplicator.%d.redisCheckAndSetFailure", identity)); REDIS_CAS_LATENCY = Metrics.getRegistry() .timer(String.format("deduplicator.%d.redisCheckAndSetLatency", identity)); }
From source file:com.c123.billbuddy.dal.Top10PaymentReducer.java
@Override public Payment[] reduce(SpaceRemotingResult<Payment[]>[] results, SpaceRemotingInvocation remotingInvocation) throws Exception { log.info("Starting Top10MerchantFeeAmountReducer"); List<Payment> payments = new ArrayList<Payment>(); // Each result is an array of events. Each result is from a single partition. for (SpaceRemotingResult<Payment[]> result : results) { if (result.getException() != null) { // just log the fact that there was an exception log.error("Executor Remoting Exception [" + result.getException() + "]"); continue; }/*from w w w . ja v a 2s. c o m*/ Collections.addAll(payments, result.getResult()); } Collections.sort(payments, new Comparator<Payment>() { public int compare(Payment p1, Payment p2) { return p2.getPaymentAmount().compareTo(p1.getPaymentAmount()); } }); // If the number of results needed is less than the number of events that were reduced, then // return a sublist. Otherwise, return the entire list of events. Payment[] top10Payment; if (payments.size() < 10) { top10Payment = new Payment[payments.size()]; payments.toArray(top10Payment); } else { top10Payment = new Payment[10]; payments.subList(0, 10).toArray(top10Payment); } return top10Payment; }
From source file:com.c123.billbuddy.dal.Top5MerchantFeeAmountReducer.java
public Merchant[] reduce(SpaceRemotingResult<Merchant[]>[] results, SpaceRemotingInvocation remotingInvocation) throws Exception { log.info("Starting Top5MerchantFeeAmountReducer"); List<Merchant> merchants = new ArrayList<Merchant>(); // Each result is an array of events. Each result is from a single partition. for (SpaceRemotingResult<Merchant[]> result : results) { if (result.getException() != null) { // just log the fact that there was an exception log.error("Executor Remoting Exception [" + result.getException() + "]"); continue; }//from ww w . ja v a 2 s.c o m Collections.addAll(merchants, result.getResult()); } Collections.sort(merchants, new Comparator<Merchant>() { public int compare(Merchant p1, Merchant p2) { return p2.getFeeAmount().compareTo(p1.getFeeAmount()); } }); // If the number of results needed is less than the number of events that were reduced, then // return a sublist. Otherwise, return the entire list of events. Merchant[] top5Merchant; if (merchants.size() < 5) { top5Merchant = new Merchant[merchants.size()]; merchants.toArray(top5Merchant); } else { top5Merchant = new Merchant[5]; merchants.subList(0, 5).toArray(top5Merchant); } return top5Merchant; }
From source file:com.c123.billbuddy.dal.Top10ProcessingFeeReducer.java
public ProcessingFee[] reduce(SpaceRemotingResult<ProcessingFee[]>[] results, SpaceRemotingInvocation remotingInvocation) throws Exception { log.info("Starting Top10MerchantFeeAmountReducer"); List<ProcessingFee> processingFees = new ArrayList<ProcessingFee>(); // Each result is an array of events. Each result is from a single partition. for (SpaceRemotingResult<ProcessingFee[]> result : results) { if (result.getException() != null) { // just log the fact that there was an exception log.error("Executor Remoting Exception [" + result.getException() + "]"); continue; }//from w w w . ja v a2 s. com Collections.addAll(processingFees, result.getResult()); } Collections.sort(processingFees, new Comparator<ProcessingFee>() { public int compare(ProcessingFee p1, ProcessingFee p2) { return p2.getAmount().compareTo(p1.getAmount()); } }); // If the number of results needed is less than the number of events that were reduced, then // return a sublist. Otherwise, return the entire list of events. ProcessingFee[] top10ProcessingFee; if (processingFees.size() < 10) { top10ProcessingFee = new ProcessingFee[processingFees.size()]; processingFees.toArray(top10ProcessingFee); } else { top10ProcessingFee = new ProcessingFee[10]; processingFees.subList(0, 10).toArray(top10ProcessingFee); } return top10ProcessingFee; }
From source file:org.haedus.io.ClassPathFileHandler.java
@Override public List<List<String>> readTable(String path) { List<List<String>> table = new ArrayList<List<String>>(); for (String line : readLines(path)) { List<String> row = new ArrayList<String>(); Collections.addAll(row, line.split("\t")); table.add(row);//from ww w . j a v a 2s . co m } return table; }
From source file:com.github.ljtfreitas.restify.http.spring.contract.metadata.reflection.SpringWebRequestMappingMetadata.java
public String[] headers() { ArrayList<String> headers = new ArrayList<>(); Collections.addAll(headers, mappedHeaders()); consumes().ifPresent(c -> headers.add(c)); produces().ifPresent(p -> headers.add(p)); return headers.toArray(new String[0]); }
From source file:ipLock.Signal.java
@Override public String toString() { List<String> parts = new ArrayList<>(); parts.add(getSenderId().toString()); parts.add(getCode().toString());// w w w . j a va2 s . co m Collections.addAll(parts, params); return StringUtils.join(parts, ':'); }
From source file:io.uengine.util.StringUtils.java
/** * ? ? .//ww w. j a v a 2 s . c o m * * @param values ? * @return ? */ public static List<String> arrayToCollection(String[] values) { List<String> list = new ArrayList<String>(values.length); Collections.addAll(list, values); return list; }
From source file:com.zimbra.cs.lmtpserver.utils.LmtpInject.java
public static void main(String[] args) { CliUtil.toolSetup();//from w w w .j av a 2 s .c o m CommandLine cl = parseArgs(args); if (cl.hasOption("h")) { usage(null); } boolean quietMode = cl.hasOption("q"); int threads = 1; if (cl.hasOption("t")) { threads = Integer.valueOf(cl.getOptionValue("t")).intValue(); } String host = null; if (cl.hasOption("a")) { host = cl.getOptionValue("a"); } else { host = "localhost"; } int port; Protocol proto = null; if (cl.hasOption("smtp")) { proto = Protocol.SMTP; port = 25; } else port = 7025; if (cl.hasOption("p")) port = Integer.valueOf(cl.getOptionValue("p")).intValue(); String[] recipients = cl.getOptionValues("r"); String sender = cl.getOptionValue("s"); boolean tracingEnabled = cl.hasOption("T"); int everyN; if (cl.hasOption("N")) { everyN = Integer.valueOf(cl.getOptionValue("N")).intValue(); } else { everyN = 100; } // Process files from the -d option. List<File> files = new ArrayList<File>(); if (cl.hasOption("d")) { File dir = new File(cl.getOptionValue("d")); if (!dir.isDirectory()) { System.err.format("%s is not a directory.\n", dir.getPath()); System.exit(1); } File[] fileArray = dir.listFiles(); if (fileArray == null || fileArray.length == 0) { System.err.format("No files found in directory %s.\n", dir.getPath()); } Collections.addAll(files, fileArray); } // Process files specified as arguments. for (String arg : cl.getArgs()) { files.add(new File(arg)); } // Validate file content. if (!cl.hasOption("noValidation")) { Iterator<File> i = files.iterator(); while (i.hasNext()) { InputStream in = null; File file = i.next(); boolean valid = false; try { in = new FileInputStream(file); if (FileUtil.isGzipped(file)) { in = new GZIPInputStream(in); } in = new BufferedInputStream(in); // Required for RFC 822 check if (!EmailUtil.isRfc822Message(in)) { System.err.format("%s does not contain a valid RFC 822 message.\n", file.getPath()); } else { valid = true; } } catch (IOException e) { System.err.format("Unable to validate %s: %s.\n", file.getPath(), e.toString()); } finally { ByteUtil.closeStream(in); } if (!valid) { i.remove(); } } } if (files.size() == 0) { System.err.println("No files to inject."); System.exit(1); } if (!quietMode) { System.out.format( "Injecting %d message(s) to %d recipient(s). Server %s, port %d, using %d thread(s).\n", files.size(), recipients.length, host, port, threads); } int totalFailed = 0; int totalSucceeded = 0; long startTime = System.currentTimeMillis(); boolean verbose = cl.hasOption("v"); boolean skipTLSCertValidation = cl.hasOption("skipTLSCertValidation"); LmtpInject injector = null; try { injector = new LmtpInject(threads, sender, recipients, files, host, port, proto, quietMode, tracingEnabled, verbose, skipTLSCertValidation); } catch (Exception e) { mLog.error("Unable to initialize LmtpInject", e); System.exit(1); } injector.setReportEvery(everyN); injector.markStartTime(); try { injector.run(); } catch (IOException e) { e.printStackTrace(); System.exit(1); } int succeeded = injector.getSuccessCount(); int failedThisTime = injector.getFailureCount(); long elapsedMS = System.currentTimeMillis() - startTime; double elapsed = elapsedMS / 1000.0; double msPerMsg = 0.0; double msgSizeKB = 0.0; if (succeeded > 0) { msPerMsg = elapsedMS; msPerMsg /= succeeded; msgSizeKB = injector.mFileSizeTotal / 1024.0; msgSizeKB /= succeeded; } double msgPerSec = ((double) succeeded / (double) elapsedMS) * 1000; if (!quietMode) { System.out.println(); System.out.printf( "LmtpInject Finished\n" + "submitted=%d failed=%d\n" + "%.2fs, %.2fms/msg, %.2fmsg/s\n" + "average message size = %.2fKB\n", succeeded, failedThisTime, elapsed, msPerMsg, msgPerSec, msgSizeKB); } totalFailed += failedThisTime; totalSucceeded += succeeded; if (totalFailed != 0) System.exit(1); }