List of usage examples for java.util List clear
void clear();
From source file:com.igormaznitsa.sciareto.preferences.FileHistoryManager.java
private static void fillList(@Nonnull @MustNotContainNull final String[] paths, @Nonnull @MustNotContainNull final List<File> list) { list.clear(); for (final String s : paths) { if (s != null && !s.trim().isEmpty()) { list.add(new File(s)); }/*from w w w. jav a2s. c o m*/ } }
From source file:Main.java
public static <T> void removeWithoutUsingRemoveMethod(List<T> list, int index) { if (index < 0 || index >= list.size()) { throw new IllegalArgumentException("index out of range"); }// w w w. ja v a 2 s . c o m List<T> part1 = new ArrayList<T>(list.subList(0, index)); List<T> part2 = new ArrayList<T>(list.subList(index + 1, list.size())); list.clear(); list.addAll(part1); list.addAll(part2); }
From source file:automaticdatabaseupdate.FileHandler.java
/** * * @param strFilePath - path of given file e.g. "D:\\EGYETEM\\Szakdolgozat\\Mernoki_tervezes\\update files\\sr28upd\\ADD_NUTR.txt" * @param strFileType - type of the given file e.g. AddFood * @param TList - list to fill with data e.g. List<FileFoodStruct> ListFFS *//*from w w w .j a v a 2 s .co m*/ public static <T> void readFile(String strFilePath, List<T> TList, String strFileType) { TList.clear(); try { File file = FileUtils.getFile(strFilePath); LineIterator iter = FileUtils.lineIterator(file); while (iter.hasNext()) { String strLine = iter.next(); switch (strFileType) { case "ADD_FOOD": { ArrayList<String> strList = ParseUpdateFile(strLine); FileFoodStruct Object = new FileFoodStruct(Integer.valueOf(strList.get(0)), strList.get(2), strList.get(3), Integer.valueOf(strList.get(8))); TList.add((T) Object); System.out.println(Object.toString()); break; } case "ADD_NUTR": { ArrayList<String> strList = ParseUpdateFile(strLine); FileNutrientStruct Object = new FileNutrientStruct(Integer.valueOf(strList.get(0)), Integer.valueOf(strList.get(1)), Double.valueOf(strList.get(2))); TList.add((T) Object); System.out.println(Object.toString()); break; } case "ADD_WGT": { ArrayList<String> strList = ParseUpdateFile(strLine); FileWeightStruct Object = new FileWeightStruct(Integer.valueOf(strList.get(0)), Double.valueOf(strList.get(2)), strList.get(3), Double.valueOf(strList.get(4))); TList.add((T) Object); System.out.println(Object.toString()); break; } case "CHG_FOOD": { ArrayList<String> strList = ParseUpdateFile(strLine); FileFoodStruct Object = new FileFoodStruct(Integer.valueOf(strList.get(0)), strList.get(2), strList.get(3), Integer.valueOf(strList.get(8))); TList.add((T) Object); System.out.println(Object.toString()); break; } case "CHG_NUTR": { ArrayList<String> strList = ParseUpdateFile(strLine); FileNutrientStruct Object = new FileNutrientStruct(Integer.valueOf(strList.get(0)), Integer.valueOf(strList.get(1)), Double.valueOf(strList.get(2))); TList.add((T) Object); System.out.println(Object.toString()); break; } case "CHG_WGT": { ArrayList<String> strList = ParseUpdateFile(strLine); FileWeightStruct Object = new FileWeightStruct(Integer.valueOf(strList.get(0)), Double.valueOf(strList.get(2)), strList.get(3), Double.valueOf(strList.get(4))); TList.add((T) Object); System.out.println(Object.toString()); break; } case "DEL_FOOD": { ArrayList<String> strList = ParseUpdateFile(strLine); FileFoodStruct Object = new FileFoodStruct(Integer.valueOf(strList.get(0)), strList.get(1)); TList.add((T) Object); System.out.println(Object.toString()); break; } case "DEL_NUTR": { ArrayList<String> strList = ParseUpdateFile(strLine); FileNutrientStruct Object = new FileNutrientStruct(Integer.valueOf(strList.get(0)), Integer.valueOf(strList.get(1))); TList.add((T) Object); System.out.println(Object.toString()); break; } case "DEL_WGT": { ArrayList<String> strList = ParseUpdateFile(strLine); FileWeightStruct Object = new FileWeightStruct(Integer.valueOf(strList.get(0)), Double.valueOf(strList.get(2)), strList.get(3), Double.valueOf(strList.get(4))); TList.add((T) Object); System.out.println(Object.toString()); break; } case "LOG_FILE": { ArrayList<String> strList = ParseLogFile(strLine); TraceMessage Object = new TraceMessage(strList.get(0), strList.get(1)); TList.add((T) Object); break; } } } //System.out.println( "Total line: " + moduleCounter ); iter.close(); } catch (IOException ex) { Logger.getLogger(FileHandler.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:Main.java
private static void getIndexSublist(int numbers, int length, List<List<Integer>> result) { List<List<Integer>> results = new ArrayList<>(); results.addAll(result);/*from w w w.ja v a2 s. co m*/ if (result.get(0).size() == length) { return; } result.clear(); for (List<Integer> one : results) { for (int i = 1; i < numbers; i++) { if (i > one.get(one.size() - 1)) { ArrayList<Integer> temp = new ArrayList<Integer>(); temp.addAll(one); temp.add(i); result.add(temp); } } } getIndexSublist(numbers, length, result); }
From source file:Deal.java
public static ArrayList<Card> dealHand(List<Card> deck, int n) { int deckSize = deck.size(); List<Card> handView = deck.subList(deckSize - n, deckSize); ArrayList<Card> hand = new ArrayList<Card>(handView); handView.clear(); return hand;// w w w . j a v a2s . c om }
From source file:controllers.FileHandler.java
/** * brief: read content of a given file to the proper list * @param strFilePath - path of given file e.g. "D:\\EGYETEM\\Szakdolgozat\\Mernoki_tervezes\\update files\\sr28upd\\ADD_NUTR.txt" * @param strFileType - type of the given file e.g. AddFood * @param TList - list to fill with data e.g. List<FileFoodStruct> ListFFS *//*from ww w.j ava 2 s .c om*/ public static <T> void readFile(String strFilePath, List<T> TList, String strFileType) { TList.clear(); try { File file = FileUtils.getFile(strFilePath); LineIterator iter = FileUtils.lineIterator(file); while (iter.hasNext()) { String strLine = iter.next(); switch (strFileType) { case "ADD_FOOD": { ArrayList<String> strList = ParseUpdateFile(strLine); FileStructFood Object = new FileStructFood(strList.get(0), strList.get(2), strList.get(3), Integer.valueOf(strList.get(8))); TList.add((T) Object); //System.out.println(Object.toString()); break; } case "ADD_NUTR": { ArrayList<String> strList = ParseUpdateFile(strLine); FileStructNutrient Object = new FileStructNutrient(strList.get(0), strList.get(1), Double.valueOf(strList.get(2))); TList.add((T) Object); //System.out.println(Object.toString()); break; } case "ADD_WGT": { ArrayList<String> strList = ParseUpdateFile(strLine); FileStructWeight Object = new FileStructWeight(strList.get(0), Double.valueOf(strList.get(2)), strList.get(3), Double.valueOf(strList.get(4))); TList.add((T) Object); //System.out.println(Object.toString()); break; } case "CHG_FOOD": { ArrayList<String> strList = ParseUpdateFile(strLine); FileStructFood Object = new FileStructFood(strList.get(0), strList.get(2), strList.get(3), Integer.valueOf(strList.get(8))); TList.add((T) Object); //System.out.println(Object.toString()); break; } case "CHG_NUTR": { ArrayList<String> strList = ParseUpdateFile(strLine); FileStructNutrient Object = new FileStructNutrient(strList.get(0), strList.get(1), Double.valueOf(strList.get(2))); TList.add((T) Object); //System.out.println(Object.toString()); break; } case "CHG_WGT": { ArrayList<String> strList = ParseUpdateFile(strLine); FileStructWeight Object = new FileStructWeight(strList.get(0), Double.valueOf(strList.get(2)), strList.get(3), Double.valueOf(strList.get(4))); TList.add((T) Object); //System.out.println(Object.toString()); break; } case "DEL_FOOD": { ArrayList<String> strList = ParseUpdateFile(strLine); FileStructFood Object = new FileStructFood(strList.get(0), strList.get(1)); TList.add((T) Object); //System.out.println(Object.toString()); break; } case "DEL_NUTR": { ArrayList<String> strList = ParseUpdateFile(strLine); FileStructNutrient Object = new FileStructNutrient(strList.get(0), strList.get(1)); TList.add((T) Object); //System.out.println(Object.toString()); break; } case "DEL_WGT": { ArrayList<String> strList = ParseUpdateFile(strLine); FileStructWeight Object = new FileStructWeight(strList.get(0), Double.valueOf(strList.get(2)), strList.get(3), Double.valueOf(strList.get(4))); TList.add((T) Object); //System.out.println(Object.toString()); break; } case "ADD_NDEF": { ArrayList<String> strList = ParseUpdateFile(strLine); FileStructNutrient Object = new FileStructNutrient(strList.get(0), strList.get(1), strList.get(2), strList.get(3), Integer.valueOf(strList.get(4))); TList.add((T) Object); System.out.println(strList.get(0) + " " + strList.get(1) + " " + strList.get(2) + " " + strList.get(3) + " " + Integer.valueOf(strList.get(4))); break; } case "CHG_NDEF": { ArrayList<String> strList = ParseUpdateFile(strLine); FileStructNutrient Object = new FileStructNutrient(strList.get(0), strList.get(1), strList.get(2), strList.get(3), Integer.valueOf(strList.get(4))); TList.add((T) Object); System.out.println(strList.get(0) + " " + strList.get(1) + " " + strList.get(2) + " " + strList.get(3) + " " + Integer.valueOf(strList.get(4))); break; } case "LOG_FILE": { ArrayList<String> strList = ParseLogFile(strLine); TraceMessage Object = new TraceMessage(strList.get(0), strList.get(1)); TList.add((T) Object); break; } } } iter.close(); } catch (IOException ex) { Logger.getLogger(FileHandler.class.getName()).log(Level.SEVERE, null, ex); } finally { return; } }
From source file:Main.java
public static void removeDuplicateWithOrder(List arlList) { Set set = new HashSet(); List newList = new ArrayList(); for (Iterator iter = arlList.iterator(); iter.hasNext();) { Object element = iter.next(); if (set.add(element)) newList.add(element);/*from w w w. j a v a2s . c o m*/ } arlList.clear(); arlList.addAll(newList); }
From source file:edu.uci.ics.hyracks.algebricks.core.algebra.util.OperatorManipulationUtil.java
public static ILogicalOperator eliminateSingleSubplanOverEts(SubplanOperator subplan) { if (subplan.getNestedPlans().size() > 1) { // not a single subplan List<Mutable<ILogicalOperator>> subInpList = subplan.getInputs(); subInpList.clear(); subInpList.add(new MutableObject<ILogicalOperator>(new EmptyTupleSourceOperator())); return subplan; }/*from w ww . j a va2 s . c om*/ ILogicalPlan plan = subplan.getNestedPlans().get(0); if (plan.getRoots().size() > 1) { // not a single subplan List<Mutable<ILogicalOperator>> subInpList = subplan.getInputs(); subInpList.clear(); subInpList.add(new MutableObject<ILogicalOperator>(new EmptyTupleSourceOperator())); return subplan; } return plan.getRoots().get(0).getValue(); }
From source file:Main.java
public static List<Field> getPublicFields(Class<?> clazz) { List<Field> publicList = new ArrayList<Field>(); List<Field> accessibleList = getAccessibleFields(clazz, Object.class); for (Field f : accessibleList) { if (Modifier.isPublic(f.getModifiers()) == true) { publicList.add(f);/*from w ww. ja v a 2 s .c om*/ } } accessibleList.clear(); return publicList; }
From source file:me.StevenLawson.BukkitTelnetClient.BTC_PlayerListDecoder.java
public static final boolean checkForPlayerListMessage(final String message, final List<PlayerInfo> playerList) { final Matcher matcher = PLAYER_LIST_MESSAGE.matcher(message); if (matcher.find()) { final String data = matcher.group(1); try {/*from w w w . jav a 2s .c o m*/ playerList.clear(); final JSONObject json = new JSONObject(data); final JSONArrayIterable players = new JSONArrayIterable(json.getJSONArray("players")); for (JSONObject player : players) { final String name = getStringSafe(player, "name"); playerList.add(new PlayerInfo(name, getStringSafe(player, "ip"), getStringSafe(player, "displayName"), getStringSafe(player, "uuid"), Boolean.valueOf(getStringSafe(player, "tfm.admin.isAdmin")), Boolean.valueOf(getStringSafe(player, "tfm.admin.isTelnetAdmin")), Boolean.valueOf(getStringSafe(player, "tfm.admin.isSeniorAdmin")), getStringSafe(player, "tfm.playerdata.getTag"), getStringSafe(player, "tfm.essentialsBridge.getNickname"))); } Collections.sort(playerList, PlayerInfo.getComparator()); return true; } catch (JSONException ex) { } } return false; }