List of usage examples for java.util List clear
void clear();
From source file:com.akop.bach.parser.LiveParser.java
protected static void getInputs(String response, List<NameValuePair> inputs, Pattern pattern) { Matcher allAttrs = PATTERN_INPUT_ATTR_LIST.matcher(response); inputs.clear(); boolean add;/*from w w w . j a va 2s . c om*/ while (allAttrs.find()) { String name = null, value = null; Matcher attrs = PATTERN_GET_ATTRS.matcher(allAttrs.group(1)); add = true; while (attrs.find()) { /* * We actually need this; at least for message composition if (attrs.group(1).equalsIgnoreCase("type") && attrs.group(2).equalsIgnoreCase("submit")) { add = false; break; } */ if (attrs.group(1).equalsIgnoreCase("name")) name = attrs.group(2); else if (attrs.group(1).equalsIgnoreCase("value")) value = attrs.group(2); } if (!add || name == null || value == null) continue; // If a pattern is supplied, make sure NAME matches pattern if (pattern != null) { if (!pattern.matcher(name).find()) continue; } for (NameValuePair p : inputs) { if (p.getName().equals(name)) { add = false; break; } } if (!add) continue; inputs.add(new BasicNameValuePair(name, value)); } }
From source file:net.tirasa.ilgrosso.resetdb.Main.java
private static void resetOracle(final Connection conn) throws Exception { final Statement statement = conn.createStatement(); ResultSet resultSet = statement.executeQuery( "SELECT 'DROP VIEW ' || object_name || ';'" + " FROM user_objects WHERE object_type='VIEW'"); final List<String> drops = new ArrayList<String>(); while (resultSet.next()) { drops.add(resultSet.getString(1)); }//from w w w . j a v a2 s. c om resultSet.close(); for (String drop : drops) { statement.executeUpdate(drop.substring(0, drop.length() - 1)); } drops.clear(); resultSet = statement.executeQuery("SELECT 'DROP INDEX ' || object_name || ';'" + " FROM user_objects WHERE object_type='INDEX'" + " AND object_name NOT LIKE 'SYS_%'"); while (resultSet.next()) { drops.add(resultSet.getString(1)); } resultSet.close(); for (String drop : drops) { try { statement.executeUpdate(drop.substring(0, drop.length() - 1)); } catch (SQLException e) { LOG.error("Could not perform: {}", drop); } } drops.clear(); resultSet = statement.executeQuery("SELECT 'DROP TABLE ' || table_name || ' CASCADE CONSTRAINTS;'" + " FROM all_TABLES WHERE owner='" + ((String) ctx.getBean("username")).toUpperCase() + "'"); while (resultSet.next()) { drops.add(resultSet.getString(1)); } resultSet.close(); resultSet = statement .executeQuery("SELECT 'DROP SEQUENCE ' || sequence_name || ';'" + " FROM user_SEQUENCES"); while (resultSet.next()) { drops.add(resultSet.getString(1)); } resultSet.close(); for (String drop : drops) { statement.executeUpdate(drop.substring(0, drop.length() - 1)); } statement.close(); conn.close(); }
From source file:hudson.search.Search.java
public static List<SuggestedItem> suggest(SearchIndex index, final String tokenList) { class Tag implements Comparable<Tag> { final SuggestedItem item; final int distance; /** If the path to this suggestion starts with the token list, 1. Otherwise 0. */ final int prefixMatch; Tag(SuggestedItem i) {//from w w w . ja va 2 s .c o m item = i; distance = EditDistance.editDistance(i.getPath(), tokenList); prefixMatch = i.getPath().startsWith(tokenList) ? 1 : 0; } public int compareTo(Tag that) { int r = this.prefixMatch - that.prefixMatch; if (r != 0) return -r; // ones with head match should show up earlier return this.distance - that.distance; } } List<Tag> buf = new ArrayList<Tag>(); List<SuggestedItem> items = find(Mode.SUGGEST, index, tokenList); // sort them for (SuggestedItem i : items) buf.add(new Tag(i)); Collections.sort(buf); items.clear(); for (Tag t : buf) items.add(t.item); return items; }
From source file:Main.java
public static void removeDuplicateWithOrder(List<ResolveInfo> list) { if (list == null) { return;// w w w. j ava 2 s . c om } Set<String> set = new HashSet<String>(); List<ResolveInfo> newList = new ArrayList<ResolveInfo>(); for (Iterator<ResolveInfo> iter = list.iterator(); iter.hasNext();) { ResolveInfo info = (ResolveInfo) iter.next(); if (set.add(info.activityInfo.packageName)) { newList.add(info); } } list.clear(); list.addAll(newList); }
From source file:hudson.search.Search.java
private static List<SuggestedItem> find(Mode m, SearchIndex index, String tokenList) { TokenList tokens = new TokenList(tokenList); if (tokens.length() == 0) return Collections.emptyList(); // no tokens given List<SuggestedItem>[] paths = new List[tokens.length() + 1]; // we won't use [0]. for (int i = 1; i <= tokens.length(); i++) paths[i] = new ArrayList<SuggestedItem>(); List<SearchItem> items = new ArrayList<SearchItem>(); // items found in 1 step // first token int w = 1; // width of token for (String token : tokens.subSequence(0)) { items.clear(); m.find(index, token, items);/*from ww w . jav a 2s . co m*/ for (SearchItem si : items) paths[w].add(new SuggestedItem(si)); w++; } // successive tokens for (int j = 1; j < tokens.length(); j++) { // for each length w = 1; for (String token : tokens.subSequence(j)) { // for each candidate for (SuggestedItem r : paths[j]) { items.clear(); m.find(r.item.getSearchIndex(), token, items); for (SearchItem i : items) paths[j + w].add(new SuggestedItem(r, i)); } w++; } } return paths[tokens.length()]; }
From source file:Main.java
public static List<Map<String, Object>> setFirstMapFromList(List<Map<String, Object>> list, String field, String value) {//from w ww . j a v a 2s.c o m List<Map<String, Object>> collection = new ArrayList<Map<String, Object>>(); for (Iterator<Map<String, Object>> iter = list.iterator(); iter.hasNext();) { Map<String, Object> map = iter.next(); String deField = map.get(field).toString(); if (deField.equalsIgnoreCase(value)) { collection.add(map); collection.addAll(list); list.clear(); list.addAll(collection); break; } } return list; }
From source file:com.subgraph.vega.internal.model.web.WebPath.java
private static List<NameValuePair> parseParameters(String query) { if (query == null || query.isEmpty()) return Collections.emptyList(); final List<NameValuePair> parameterList = new ArrayList<NameValuePair>(); try {//from w ww. j av a2 s. c o m URLEncodedUtils.parse(parameterList, new Scanner(query), "UTF-8"); } catch (RuntimeException e) { parameterList.clear(); parameterList.add(new BasicNameValuePair(query, null)); } return parameterList; }
From source file:com.omertron.slackbot.functions.Meetup.java
/** * Retrieve and process the MeetUps from the site. * * @param pageSize/* w ww . j a v a2 s. co m*/ * @throws ApiException */ public static void readMeetUp(int pageSize) throws ApiException { MEETUPS.clear(); if (StringUtils.isBlank(BASE_URL)) { throw new ApiException(ApiExceptionType.INVALID_URL, "Meetup URL is not set in the properties file! Use the property " + Constants.MEETUP_URL); } try { URL url = HttpTools.createUrl(BASE_URL + pageSize); List<MeetupDetails> meetups = MAPPER.readValue(url, new TypeReference<List<MeetupDetails>>() { }); MEETUPS.addAll(meetups); } catch (IOException ex) { LOG.warn("Failed to read MeetUp data: {}", ex.getMessage(), ex); return; } catch (ApiException ex) { LOG.warn("Failed to convert URL: {}", ex.getMessage(), ex); return; } LOG.info("Processed {} MeetUp events", MEETUPS.size()); }
From source file:Main.java
/** * Using like subList() but it take randoms elements. * * @param list//from w w w . j a v a 2s. co m * @param sizeOfSubList */ public static <E> void randomSubList(List<E> list, int sizeOfSubList) { List<E> subList = Collections.emptyList(); if (isNotEmpty(list) && list.size() > sizeOfSubList) { subList = new ArrayList<E>(sizeOfSubList); Random generator = new Random(); for (int i = 0; i < sizeOfSubList; i++) { int random = generator.nextInt(list.size()); subList.add(list.get(random)); list.remove(random); } } list.clear(); list.addAll(subList); }
From source file:com.appsimobile.appsii.module.weather.ImageDownloadHelper.java
public static void getEligiblePhotosFromResponse(@Nullable JSONObject jsonObject, List<PhotoInfo> result, int minDimension) { result.clear(); if (jsonObject == null) return;//from w w w . ja v a2 s .c om JSONObject photos = jsonObject.optJSONObject("photos"); if (photos == null) return; JSONArray photoArr = photos.optJSONArray("photo"); if (photoArr == null) return; int N = photoArr.length(); for (int i = 0; i < N; i++) { JSONObject object = photoArr.optJSONObject(i); if (object == null) continue; String id = object.optString("id"); if (TextUtils.isEmpty(id)) continue; String urlH = urlFromImageObject(object, "url_h", "width_h", "height_h", minDimension - 100); String urlO = urlFromImageObject(object, "url_o", "width_o", "height_o", minDimension - 100); if (urlH != null) { result.add(new PhotoInfo(id, urlH)); } else if (urlO != null) { result.add(new PhotoInfo(id, urlO)); } } }