List of usage examples for java.util ArrayList clear
public void clear()
From source file:hochschuledarmstadt.photostream_tools.AndroidSocket.java
private void initializeSocket() { /*socket.on(Socket.EVENT_ERROR, new Emitter.Listener() { @Override/*from w w w .j av a2s.co m*/ public void call(Object... args) { // onMessageListener.onError(); } }); socket.on(Socket.EVENT_CONNECT_ERROR, new Emitter.Listener() { @Override public void call(Object... args) { // onMessageListener.onConnectError(uri); } }); socket.on(Socket.EVENT_RECONNECT_FAILED, new Emitter.Listener() { @Override public void call(Object... args) { // onMessageListener.onConnectError(uri); } }); socket.on(Socket.EVENT_DISCONNECT, new Emitter.Listener() { @Override public void call(Object... args) { onMessageListener.onDisconnect(); } });*/ socket.on(Socket.EVENT_CONNECT, new Emitter.Listener() { @Override public void call(Object... args) { onMessageListener.onConnect(); } }); socket.on(NEW_PHOTO, new Emitter.Listener() { @Override public void call(Object... args) { final Photo photo = new Gson().fromJson(args[0].toString(), Photo.class); ArrayList<Photo> list = new ArrayList<>(1); list.add(photo); imageLoader.execute(list); HttpImageLoader.HttpImage httpImage = imageLoader.take(); if (httpImage != null) { try { imageCacher.cacheImage(httpImage.getPhoto(), httpImage.getImageData()); } catch (IOException e) { e.printStackTrace(); } handler.post(new Runnable() { @Override public void run() { onMessageListener.onNewPhoto(photo); } }); } list.clear(); } }); socket.on(NEW_COMMENT, new Emitter.Listener() { @Override public void call(Object... args) { JSONObject jsonObject = (JSONObject) args[0]; Gson gson = new Gson(); final Comment comment = gson.fromJson(jsonObject.toString(), Comment.class); handler.post(new Runnable() { @Override public void run() { onMessageListener.onNewComment(comment); } }); } }); socket.on(COMMENT_DELETED, new Emitter.Listener() { @Override public void call(Object... args) { final int commentId = Integer.parseInt(args[0].toString()); handler.post(new Runnable() { @Override public void run() { onMessageListener.onCommentDeleted(commentId); } }); } }); socket.on(PHOTO_DELETED, new Emitter.Listener() { @Override public void call(Object... args) { final int photoId = Integer.parseInt(args[0].toString()); handler.post(new Runnable() { @Override public void run() { onMessageListener.onPhotoDeleted(photoId); } }); } }); socket.on(NEW_COMMENT_COUNT, new Emitter.Listener() { @Override public void call(Object... args) { JSONObject jsonObject = (JSONObject) args[0]; try { final int photoId = jsonObject.getInt("photo_id"); final int comment_count = jsonObject.getInt("comment_count"); handler.post(new Runnable() { @Override public void run() { onMessageListener.onCommentCountChanged(photoId, comment_count); } }); } catch (JSONException e) { e.printStackTrace(); } } }); }
From source file:org.apache.hadoop.hbase.regionserver.HFileReadWriteTest.java
private void performMerge(List<StoreFileScanner> scanners, HStore store, StoreFile.Writer writer) throws IOException { InternalScanner scanner = null;//from w w w. ja v a2s .co m try { Scan scan = new Scan(); // Include deletes scanner = new StoreScanner(store, store.getScanInfo(), scan, scanners, ScanType.COMPACT_DROP_DELETES, Long.MIN_VALUE, Long.MIN_VALUE); ArrayList<Cell> kvs = new ArrayList<Cell>(); while (scanner.next(kvs) || kvs.size() != 0) { numKV.addAndGet(kvs.size()); for (Cell c : kvs) { KeyValue kv = KeyValueUtil.ensureKeyValue(c); totalBytes.addAndGet(kv.getLength()); writer.append(kv); } kvs.clear(); } } finally { if (scanner != null) scanner.close(); } }
From source file:edu.harvard.i2b2.analysis.dataModel.ConceptTableModel.java
public void fillDataFromTable(ArrayList<ArrayList<ConceptTableRow>> list) { list.clear(); ConceptTableRow row = null;//w w w. j a va 2s . c o m ArrayList<ConceptTableRow> group = null; Integer curRow = null; LinkedHashMap<Integer, ArrayList<ConceptTableRow>> rowMap = new LinkedHashMap<Integer, ArrayList<ConceptTableRow>>(); for (int i = 1; i < rowCount; i++) { row = new ConceptTableRow(); curRow = new Integer((String) content.get("0/" + i)); row.rowNumber = curRow.intValue(); if (!rowMap.containsKey(curRow)) { group = new ArrayList<ConceptTableRow>(); list.add(group); rowMap.put(curRow, group); } else { group = rowMap.get(curRow); } row.conceptName = (String) content.get("1/" + i); row.dateText = (String) content.get("2/" + i); row.valueText = (String) content.get("3/" + i); row.height = (String) content.get("4/" + i); row.color = (RGB) content.get("5/" + i); row.conceptXml = (String) content.get("6/" + i); row.data = (QueryModel) content.get("7/" + i); row.rowId = i; group.add(row); } }
From source file:geva.Mapper.ContextFreeGrammar.java
/** Update recursive and minimumDepth fields for every Rule * and Production in grammar.*///w w w . ja v a 2s. c o m void updateRuleFields() { ArrayList<Rule> visitedRules = new ArrayList<Rule>(); Iterator<Rule> ruleIt = rules.iterator(); Rule r; clearRuleFields(); // Go through each rule in the grammar while (ruleIt.hasNext()) { r = ruleIt.next(); visitedRules.clear(); r.setRecursive(isRecursive(visitedRules, r)); } ruleIt = rules.iterator(); // Second pass calculating minimumDepth while (ruleIt.hasNext()) { r = ruleIt.next(); visitedRules.clear(); //System.out.println("Start:"+r.getLHS().getSymbolString()); calculateMinimumDepthRecursive(r, visitedRules); //System.out.println(r.getLHS().getSymbolString()+" minDepth:"+r.getMinimumDepth() +" isRecursive:"+r.getRecursive()); } ruleIt = rules.iterator(); // setting the minimum depth of the productions while (ruleIt.hasNext()) { r = ruleIt.next(); visitedRules.clear(); //System.out.println("Start:"+r.getLHS().getSymbolString()); setProductionMinimumDepth(r); } }
From source file:com.swg.parse.docx.OpenFolderAction.java
/*** * Simply grab all the content of the .txt file and put it into a string * @return contentOfTxtFile/*from w w w. ja v a 2 s . com*/ * @throws FileNotFoundException */ private String readTxtFile() throws FileNotFoundException { ArrayList<String> list = new ArrayList<>(); BufferedReader br = null; try { br = new BufferedReader(new FileReader(TxtFile)); String availalbe; while ((availalbe = br.readLine()) != null) { list.add(availalbe.toLowerCase()); } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { if (br != null) { try { br.close(); } catch (IOException e) { e.printStackTrace(); } } } StringBuilder builder = new StringBuilder(); for (String str : list) { builder.append(str).append("\n"); } list.clear(); list = null; return builder.toString(); }
From source file:com.chinamobile.bcbsp.pipes.TaskHandler.java
@Override public boolean saveResult(ArrayList<String> vertexEdge) { try {//from ww w. jav a 2 s . c om OutputFormat outputformat = (OutputFormat) ReflectionUtils.newInstance( job.getConf().getClass(Constants.USER_BC_BSP_JOB_OUTPUT_FORMAT_CLASS, OutputFormat.class), job.getConf()); outputformat.initialize(job.getConf()); RecordWriter output1 = outputformat.getRecordWriter(job, sid); // for (int i = 0; i < graphData.sizeForAll(); i++) { // Vertex<?, ?, Edge> vertex = graphData.getForAll(i); for (int i = 0; i < vertexEdge.size(); i++) { LOG.info("+++++++++++vertexEdge++++++++" + vertexEdge.get(i)); output1.write(new Text(vertexEdge.get(i))); } output1.close(job); vertexEdge.clear(); // graphData.clean(); } catch (Exception e) { LOG.error("Exception has been catched in BSPStaff--saveResult !", e); BSPConfiguration conf = new BSPConfiguration(); if (staff.getRecoveryTimes() < conf.getInt(Constants.BC_BSP_JOB_RECOVERY_ATTEMPT_MAX, 0)) { staff.recovery(job, staff, workerAgent); } else { workerAgent.setStaffStatus(sid, Constants.SATAFF_STATUS.FAULT, new Fault(Fault.Type.DISK, Fault.Level.INDETERMINATE, workerAgent.getWorkerManagerName(job.getJobID(), sid), e.toString(), job.toString(), sid.toString()), 2); LOG.info("=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*" + "=*=*=*=*=*"); LOG.error("Other Exception has happened and been catched, " + "the exception will be reported to WorkerManager", e); } } return true; }
From source file:com.softdesign.devintensive.ui.view.animations.internal.BaseItemAnimator.java
@Override public void runPendingAnimations() { boolean removalsPending = !mPendingRemovals.isEmpty(); boolean movesPending = !mPendingMoves.isEmpty(); boolean changesPending = !mPendingChanges.isEmpty(); boolean additionsPending = !mPendingAdditions.isEmpty(); if (!removalsPending && !movesPending && !additionsPending && !changesPending) { // nothing to animate return;/*from w w w .j a v a2s . co m*/ } // First, remove stuff for (ViewHolder holder : mPendingRemovals) { doAnimateRemove(holder); } mPendingRemovals.clear(); // Next, move stuff if (movesPending) { final ArrayList<MoveInfo> moves = new ArrayList<>(); moves.addAll(mPendingMoves); mMovesList.add(moves); mPendingMoves.clear(); Runnable mover = () -> { for (MoveInfo moveInfo : moves) { animateMoveImpl(moveInfo.holder, moveInfo.fromX, moveInfo.fromY, moveInfo.toX, moveInfo.toY); } moves.clear(); mMovesList.remove(moves); }; if (removalsPending) { View view = moves.get(0).holder.itemView; ViewCompat.postOnAnimationDelayed(view, mover, getRemoveDuration()); } else { mover.run(); } } // Next, change stuff, to run in parallel with move animations if (changesPending) { final ArrayList<ChangeInfo> changes = new ArrayList<>(); changes.addAll(mPendingChanges); mChangesList.add(changes); mPendingChanges.clear(); Runnable changer = () -> { for (ChangeInfo change : changes) { animateChangeImpl(change); } changes.clear(); mChangesList.remove(changes); }; if (removalsPending) { ViewHolder holder = changes.get(0).oldHolder; ViewCompat.postOnAnimationDelayed(holder.itemView, changer, getRemoveDuration()); } else { changer.run(); } } // Next, add stuff if (additionsPending) { final ArrayList<ViewHolder> additions = new ArrayList<>(); additions.addAll(mPendingAdditions); mAdditionsList.add(additions); mPendingAdditions.clear(); Runnable adder = () -> { for (ViewHolder holder : additions) { doAnimateAdd(holder); } additions.clear(); mAdditionsList.remove(additions); }; if (removalsPending || movesPending || changesPending) { long removeDuration = removalsPending ? getRemoveDuration() : 0; long moveDuration = movesPending ? getMoveDuration() : 0; long changeDuration = changesPending ? getChangeDuration() : 0; long totalDelay = removeDuration + Math.max(moveDuration, changeDuration); View view = additions.get(0).itemView; ViewCompat.postOnAnimationDelayed(view, adder, totalDelay); } else { adder.run(); } } }
From source file:com.xabber.android.ui.activity.ContactListActivity.java
/** * Open chat with specified contact.//from w ww. ja va2s .c o m * <p/> * Show dialog to choose account if necessary. * * @param user * @param text can be <code>null</code>. */ private void openChat(UserJid user, String text) { UserJid bareAddress = user.getBareUserJid(); ArrayList<BaseEntity> entities = new ArrayList<>(); for (AbstractChat check : MessageManager.getInstance().getChats()) { if (check.isActive() && check.getUser().equals(bareAddress)) { entities.add(check); } } if (entities.size() == 1) { openChat(entities.get(0), text); return; } entities.clear(); Collection<AccountJid> enabledAccounts = AccountManager.getInstance().getEnabledAccounts(); RosterManager rosterManager = RosterManager.getInstance(); for (AccountJid accountJid : enabledAccounts) { RosterContact rosterContact = rosterManager.getRosterContact(accountJid, user); if (rosterContact != null && rosterContact.isEnabled()) { entities.add(rosterContact); } } if (entities.size() == 1) { openChat(entities.get(0), text); return; } if (enabledAccounts.isEmpty()) { return; } if (enabledAccounts.size() == 1) { openChat(rosterManager.getBestContact(enabledAccounts.iterator().next(), bareAddress), text); return; } AccountChooseDialogFragment.newInstance(bareAddress, text).show(getFragmentManager(), "OPEN_WITH_ACCOUNT"); }
From source file:ca.cs.ualberta.localpost.controller.ElasticSearchOperations.java
/** * /* ww w . j a va 2 s .co m*/ * @param uuid Pulls Model from ES using UUID * @return Arraylist of Root(Top Leve) Comment models * @throws ClientProtocolException Internet Exception * @throws IOException Handles IO exceptions */ public ArrayList<CommentModel> getAllRootComments(String uuid) throws ClientProtocolException, IOException { ArrayList<CommentModel> returnArray = new ArrayList<CommentModel>(); HttpGet search = new HttpGet(urlRoot + "_search"); HttpResponse response = httpclient.execute(search); String status = response.getStatusLine().toString(); //System.out.println(status); String json = getEntityContent(response); Type searchType = new TypeToken<ElasticSearchSearchResponse<RootCommentModel>>() { }.getType(); ElasticSearchSearchResponse<RootCommentModel> esResponse = gson.fromJson(json, searchType); for (ElasticSearchResponse<RootCommentModel> r : esResponse.getHits()) { RootCommentModel model = r.getSource(); if (uuid == null) { //deleteComment(model.getPostId(),2); returnArray.add(model); } if (model.getPostId().toString().equals(uuid)) { returnArray.clear(); returnArray.add(model); return returnArray; } } return returnArray; }
From source file:com.golfmarin.golf.HoleActivity.java
/** * Scans through list of courses to find the one close to the current location. * * @param location current gps location/*from w w w. j a v a 2 s .c o m*/ * @return Courses closest to current location */ private ArrayList<Course> getCurrentCourse(Location location) { // Search for course closest to current location ArrayList<Course> bestCourses = new ArrayList<Course>(); float bestYards = 20000; float conv = (float) 1.0936133; for (Course course : allCourses) { // Not all courses have hole locations, skip those if (course.holeList != null) { float yards = location.distanceTo(course.getLocation()) * conv; if (yards < bestYards) { bestYards = yards; bestCourses.clear(); bestCourses.add(course); } // Some clubs have multiple courses else if (yards == bestYards) { bestCourses.add(course); } } /* if (course.name.equals("Golf Course Name")) { bestCourses.clear(); bestCourses.add(course); } */ //Verify that a course with holes was identified. } if (bestCourses.size() > 0) startup = false; return bestCourses; }