List of usage examples for java.util ArrayList addAll
public boolean addAll(Collection<? extends E> c)
From source file:FileUtils.java
/** * Returns all jpg images from a directory in an array. * * @param directory the directory to start with * @param descendIntoSubDirectories should we include sub directories? * @return an ArrayList<String> containing all the files or nul if none are found.. * @throws IOException/*from w w w . j a v a 2 s . c om*/ */ public static ArrayList<String> getAllImages(File directory, boolean descendIntoSubDirectories) throws IOException { ArrayList<String> resultList = new ArrayList<String>(256); File[] f = directory.listFiles(); for (File file : f) { if (file != null && file.getName().toLowerCase().endsWith(".jpg") && !file.getName().startsWith("tn_")) { resultList.add(file.getCanonicalPath()); } if (descendIntoSubDirectories && file.isDirectory()) { ArrayList<String> tmp = getAllImages(file, true); if (tmp != null) { resultList.addAll(tmp); } } } if (resultList.size() > 0) return resultList; else return null; }
From source file:com.oinux.lanmitm.util.RequestParser.java
public static ArrayList<BasicClientCookie> getCookiesFromHeaders(ArrayList<String> headers) { ArrayList<String> values = getHeaderValues("Cookie", headers); if (values != null && values.size() > 0) { ArrayList<BasicClientCookie> cookies = new ArrayList<BasicClientCookie>(); for (String value : values) { ArrayList<BasicClientCookie> lineCookies = parseRawCookie(value); if (lineCookies != null && lineCookies.size() > 0) { cookies.addAll(lineCookies); }//from w w w. ja va 2 s . c o m } Iterator<BasicClientCookie> it = cookies.iterator(); while (it.hasNext()) { BasicClientCookie cookie = (BasicClientCookie) it.next(); if (cookie.getName().startsWith("__utm") || cookie.getName().equals("__cfduid")) it.remove(); } return cookies.size() > 0 ? cookies : new ArrayList<BasicClientCookie>(); } return new ArrayList<BasicClientCookie>(); }
From source file:info.varden.anatychia.Main.java
private static File[] listRegionContainers(File base) { ArrayList<File> ret = new ArrayList<File>(); File[] contents = base.listFiles(); for (File f : contents) { if (f.isDirectory()) { ret.addAll(Arrays.asList(listRegionContainers(f))); } else {// w ww . jav a2 s .c o m if (f.getName().endsWith(".mca") && !ret.contains(base)) { ret.add(base); } } } return ret.toArray(new File[0]); }
From source file:com.qpark.eip.core.failure.BaseFailureHandler.java
/** * Handles the exception classes:// ww w . j a v a 2s .c om * <ul> * <li>{@link FailureException}</li> * <li>{@link SoapFaultClientException}</li> * <li>{@link Exception}</li> * </ul> * * @param e * @param rp * @param defaultCode * @param log */ public static FailureDescription handleException(final Throwable e, final String defaultCode, final Logger log, final Object... data) { FailureDescription fd = null; if (InvocationTargetException.class.isInstance(e)) { fd = handleException(((InvocationTargetException) e).getTargetException(), defaultCode, log, data); } else if (MessageHandlingException.class.isInstance(e)) { fd = handleException(((MessagingException) e).getCause(), defaultCode, log, data); } else if (MessagingException.class.isInstance(e)) { fd = handleException(((MessagingException) e).getCause(), defaultCode, log, data); } else if (SoapFaultClientException.class.isInstance(e)) { ArrayList<Object> list = new ArrayList<Object>(data == null ? 1 : data.length + 1); if (data != null) { list.addAll(Arrays.asList(data)); } if (e.getMessage() != null) { list.add(0, e.getMessage()); } fd = getFailure("E_SOAP_FAULT_CLIENT_ERROR", e, list.toArray(new Object[list.size()])); if (log.isDebugEnabled()) { log.error(e.getMessage(), e); } else { log.error(e.getMessage()); } } else if (WebServiceIOException.class.isInstance(e)) { fd = handleWebServiceIOException((WebServiceIOException) e, defaultCode, log, data); } else if (SoapFaultException.class.isInstance(e)) { ArrayList<Object> list = new ArrayList<Object>(data == null ? 1 : data.length + 1); if (data != null) { list.addAll(Arrays.asList(data)); } if (e.getMessage() != null) { list.add(0, e.getMessage()); } fd = handleSoapFaultException((SoapFaultException) e, defaultCode, log, list.toArray(new Object[list.size()])); if (fd == null) { fd = getFailure("E_SOAP_MESSAGE_VALIDATION_ERROR", e); } if (log.isDebugEnabled()) { log.error(e.getMessage(), e); } else { log.error(e.getMessage()); } } else if (SQLException.class.isInstance(e)) { fd = handleSQLException((SQLException) e, DEFAULT_DATABASE, log, data); } else if (e.getCause() != null) { fd = handleException(e.getCause(), defaultCode, log, data); } else { fd = getFailure(defaultCode == null ? DEFAULT : defaultCode, e); if (log.isDebugEnabled()) { log.error(e.getMessage(), e); } else { log.error(e.getMessage()); } } return fd; }
From source file:edu.oregonstate.eecs.mcplan.abstraction.PairDataset.java
public static <S, X extends FactoredRepresentation<S>, A extends VirtualConstructor<A>> ArrayList<PairInstance> makePairDataset( final RandomGenerator rng, final int max_pairwise_instances, final Instances single) { final ReservoirSampleAccumulator<PairInstance> negative = new ReservoirSampleAccumulator<PairInstance>(rng, max_pairwise_instances);/* ww w . ja v a2 s . c o m*/ final ReservoirSampleAccumulator<PairInstance> positive = new ReservoirSampleAccumulator<PairInstance>(rng, max_pairwise_instances); for (int i = 0; i < single.size(); ++i) { for (int j = i + 1; j < single.size(); ++j) { final Instance ii = single.get(i); final Instance ij = single.get(j); final int label; if (ii.classValue() == ij.classValue()) { label = 1; if (positive.acceptNext()) { final PairInstance pair_instance = new PairInstance(ii.toDoubleArray(), ij.toDoubleArray(), label); positive.addPending(pair_instance); } } else { label = 0; if (negative.acceptNext()) { final PairInstance pair_instance = new PairInstance(ii.toDoubleArray(), ij.toDoubleArray(), label); negative.addPending(pair_instance); } } } } final ArrayList<PairInstance> result = new ArrayList<PairInstance>(negative.n() + positive.n()); result.addAll(negative.samples()); result.addAll(positive.samples()); return result; }
From source file:Model.Picture.java
public static ArrayList<Picture> getNeighbors(String fileName) { ArrayList<Picture> neighbors = new ArrayList<Picture>(); ArrayList<Picture> uploaded = (ArrayList) getUploadedPictures(); for (int i = 0; i < uploaded.size() && neighbors.isEmpty(); i++) { if (uploaded.get(i).getName().equals(fileName)) { neighbors.addAll(Tools.getNeighbors(uploaded, i, Tools.NOT_CIRCULAR)); }/* w ww .ja v a2s. c om*/ } return neighbors; }
From source file:Model.Picture.java
private static ArrayList<String> upload_excel(String fileName, FileItem fileItem) throws Exception { ArrayList<String> errors = new ArrayList<String>(); if (Tools.excelExtension(Tools.getExtension(fileName))) { new File(Constants.TEMP_DIR).mkdirs(); File file = new File(Constants.TEMP_DIR + fileName); fileItem.write(file);/*from w w w .j a v a2s . c om*/ errors.addAll(enterUploadedData(fileName)); file.delete(); } else errors.add(Constants.NOT_EXCEL); return errors; }
From source file:dk.hippogrif.prettyxml.PrettyPrint.java
private static ArrayList initKeys() { ArrayList keys = new ArrayList(Arrays.asList(BASIC_KEYS)); if (keys == null) throw new RuntimeException("basic keys null"); keys.addAll(Arrays.asList(EXTENDED_KEYS)); if (keys == null) throw new RuntimeException("added keys null"); return keys;//from www. j a va 2s. c om }
From source file:net.servicestack.client.Utils.java
public static <T> ArrayList<T> createList(T... params) { ArrayList<T> to = new ArrayList<T>(); to.addAll(Arrays.asList(params)); return to;//from ww w .ja va 2s.c o m }
From source file:edu.oregonstate.eecs.mcplan.domains.blackjack.AbstractionDiscovery.java
private static MetricConstrainedKMeans makeClustering(final RandomGenerator rng, final RealMatrix A0, final ArrayList<RealVector> XL, final ArrayList<BlackjackAction> y, final ArrayList<RealVector> XU, final boolean with_metric_learning) { final int K = 4; final int d = XL.get(0).getDimension(); //52 + 52; final double u = 4.0; //1.0; final double ell = 16.0; //2.0; final double gamma = 1.0; final ArrayList<RealVector> X = new ArrayList<RealVector>(); X.addAll(XL); X.addAll(XU);/* w ww. j a va 2 s . c o m*/ final TIntObjectMap<Pair<int[], double[]>> M = new TIntObjectHashMap<Pair<int[], double[]>>(); final TIntObjectMap<Pair<int[], double[]>> C = new TIntObjectHashMap<Pair<int[], double[]>>(); for (int i = 0; i < XL.size(); ++i) { final TIntList m = new TIntArrayList(); final TIntList c = new TIntArrayList(); for (int j = i + 1; j < XL.size(); ++j) { if (y.get(i).equals(y.get(j))) { m.add(j); } else { c.add(j); } } M.put(i, Pair.makePair(m.toArray(), Fn.repeat(1.0, m.size()))); C.put(i, Pair.makePair(c.toArray(), Fn.repeat(1.0, c.size()))); } final ArrayList<int[]> S = new ArrayList<int[]>(); M.forEachKey(new TIntProcedure() { @Override public boolean execute(final int i) { final Pair<int[], double[]> p = M.get(i); if (p != null) { for (final int j : p.first) { S.add(new int[] { i, j }); } } return true; } }); final ArrayList<int[]> D = new ArrayList<int[]>(); C.forEachKey(new TIntProcedure() { @Override public boolean execute(final int i) { final Pair<int[], double[]> p = C.get(i); if (p != null) { for (final int j : p.first) { D.add(new int[] { i, j }); } } return true; } }); final RealMatrix A; if (with_metric_learning) { final InformationTheoreticMetricLearner itml = new InformationTheoreticMetricLearner(X, S, D, u, ell, A0, gamma, rng); itml.run(); A = itml.A(); } else { A = MatrixUtils.createRealIdentityMatrix(d); } final MetricConstrainedKMeans kmeans = new MetricConstrainedKMeans(K, d, X, A, M, C, rng); kmeans.run(); return kmeans; }