Java Code Examples for java.util.ArrayList.listIterator()

The following are Jave code examples for showing how to use listIterator() of the java.util.ArrayList class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: GitHub   File: Code.java   Source Code and License Vote up 6 votes
static List<Term> replaceReturn(List<Term> code, String replacement) {
  ArrayList<Term> result = new ArrayList<>(code);
  ListIterator<Term> it = result.listIterator();
  boolean wasReturn = false;
  while (it.hasNext()) {
    Term t = it.next();
    if (t.isWordOrNumber() && t.is("return")) {
      it.set(new Other(replacement));
      wasReturn = true;
    }
  }
  if (!wasReturn) {
    ListIterator<Term> revIt = Lists.reverse(result).listIterator();
    if (nextNonBlankIs(revIt, "}")) {
      nextNonBlankIs(revIt, ";");
      revIt.previous();
      revIt.add(new Delimiter(";"));
      revIt.add(new Other(replacement));
      revIt.add(new Whitespace("\n"));
    }
  }
  return result;
}
 
Example 2
Project: romanov   File: Frequency.java   Source Code and License Vote up 6 votes
private static String initializeNoteNameRegex()
{
	// noteName is built using the keys from the noteNameOffsets hashmap
	// The reverserList is a bit ridiculous, but necessary to reverse the 
	// order of the the keys so that Do and Fa come before D and F.
	// (There is no .previous() method for a regular Iterator.)
	ArrayList< String > reverserList = new ArrayList< String >();
	Iterator< String > iterator = noteNameOffsets.keySet().iterator();
	while( iterator.hasNext() )
	{
		reverserList.add( iterator.next() );	
	}
	// so that Do comes before D and is found first.
	String nNR = "(";
	ListIterator< String > listIterator = reverserList.listIterator( reverserList.size() );
	while( listIterator.hasPrevious() )
	{
		nNR += listIterator.previous() + "|";
	}
	// remove last | or empty string is included
	nNR = nNR.substring( 0, nNR.length() - 1 );
	nNR += ")";
	return nNR;
}
 
Example 3
Project: VirtualHook   File: ActivityStack.java   Source Code and License Vote up 6 votes
/**
 * App started in VA may be removed in OverView screen, then AMS.removeTask
 * will be invoked, all data struct about the task in AMS are released,
 * while the client's process is still alive. So remove related data in VA
 * as well. A new TaskRecord will be recreated in `onActivityCreated`
 */
private void optimizeTasksLocked() {
    // noinspection deprecation
    ArrayList<ActivityManager.RecentTaskInfo> recentTask = new ArrayList<>(mAM.getRecentTasks(Integer.MAX_VALUE,
            ActivityManager.RECENT_WITH_EXCLUDED | ActivityManager.RECENT_IGNORE_UNAVAILABLE));
    int N = mHistory.size();
    while (N-- > 0) {
        TaskRecord task = mHistory.valueAt(N);
        ListIterator<ActivityManager.RecentTaskInfo> iterator = recentTask.listIterator();
        boolean taskAlive = false;
        while (iterator.hasNext()) {
            ActivityManager.RecentTaskInfo info = iterator.next();
            if (info.id == task.taskId) {
                taskAlive = true;
                iterator.remove();
                break;
            }
        }
        if (!taskAlive) {
            mHistory.removeAt(N);
        }
    }
}
 
Example 4
Project: parabuild-ci   File: WebHitDataSet.java   Source Code and License Vote up 6 votes
public static void main(java.lang.String[] args) {
	try {
		WebHitDataSet whDataSet = new WebHitDataSet();
		SimpleDateFormat sdf = new SimpleDateFormat("dd-MMM-yyyy");
		ArrayList results = whDataSet.getDataBySection(sdf.parse("01-Aug-2002"));
		Iterator iter = results.listIterator();
		while (iter.hasNext()) {
			WebHit wh = (WebHit)iter.next();
			System.out.println(wh.getSection() + " - " + wh.getHitCount());
		}
		System.out.println("Finished.");

	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
Example 5
Project: TPlayer   File: ActivityStack.java   Source Code and License Vote up 6 votes
/**
 * App started in VA may be removed in OverView screen, then AMS.removeTask
 * will be invoked, all data struct about the task in AMS are released,
 * while the client's process is still alive. So remove related data in VA
 * as well. A new TaskRecord will be recreated in `onActivityCreated`
 */
private void optimizeTasksLocked() {
    // noinspection deprecation
    ArrayList<ActivityManager.RecentTaskInfo> recentTask = new ArrayList<>(mAM.getRecentTasks(Integer.MAX_VALUE,
            ActivityManager.RECENT_WITH_EXCLUDED | ActivityManager.RECENT_IGNORE_UNAVAILABLE));
    int N = mHistory.size();
    while (N-- > 0) {
        TaskRecord task = mHistory.valueAt(N);
        ListIterator<ActivityManager.RecentTaskInfo> iterator = recentTask.listIterator();
        boolean taskAlive = false;
        while (iterator.hasNext()) {
            ActivityManager.RecentTaskInfo info = iterator.next();
            if (info.id == task.taskId) {
                taskAlive = true;
                iterator.remove();
                break;
            }
        }
        if (!taskAlive) {
            mHistory.removeAt(N);
        }
    }
}
 
Example 6
Project: container   File: ActivityStack.java   Source Code and License Vote up 6 votes
/**
 * App started in VA may be removed in OverView screen, then AMS.removeTask
 * will be invoked, all data struct about the task in AMS are released,
 * while the client's process is still alive. So remove related data in VA
 * as well. A new TaskRecord will be recreated in `onActivityCreated`
 */
private void optimizeTasksLocked() {
    // noinspection deprecation
    ArrayList<ActivityManager.RecentTaskInfo> recentTask = new ArrayList<>(mAM.getRecentTasks(Integer.MAX_VALUE,
            ActivityManager.RECENT_WITH_EXCLUDED | ActivityManager.RECENT_IGNORE_UNAVAILABLE));
    int N = mHistory.size();
    while (N-- > 0) {
        TaskRecord task = mHistory.valueAt(N);
        ListIterator<ActivityManager.RecentTaskInfo> iterator = recentTask.listIterator();
        boolean taskAlive = false;
        while (iterator.hasNext()) {
            ActivityManager.RecentTaskInfo info = iterator.next();
            if (info.id == task.taskId) {
                taskAlive = true;
                iterator.remove();
                break;
            }
        }
        if (!taskAlive) {
            mHistory.removeAt(N);
        }
    }
}
 
Example 7
Project: Saiy-PS   File: SaiyTextToSpeech.java   Source Code and License Vote up 6 votes
private ArrayList<SaiyVoice> filterGender(@NonNull final ArrayList<SaiyVoice> voiceArray) {
    if (DEBUG) {
        MyLog.i(CLS_NAME, "filterGender");
    }

    final Gender preferredGender = SPH.getDefaultTTSGender(mContext);
    final ArrayList<SaiyVoice> voiceArrayCopy = new ArrayList<>(voiceArray);

    final ListIterator<SaiyVoice> itr = voiceArrayCopy.listIterator();

    SaiyVoice v;
    while (itr.hasNext()) {
        v = itr.next();
        if (v.getGender() != preferredGender) {
            itr.remove();
        }
    }

    if (voiceArrayCopy.isEmpty()) {
        return filterLegacy(voiceArray);
    } else {
        return filterLegacy(voiceArrayCopy);
    }
}
 
Example 8
Project: AndroidOpen   File: TransitionHelper.java   Source Code and License Vote up 6 votes
public static ActivityOptionsCompat makeOptionsCompat(Activity fromActivity, Pair<View, String>... sharedElements) {
    ArrayList<Pair<View, String>> list = new ArrayList<>(Arrays.asList(sharedElements));

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        list.add(Pair.create(fromActivity.findViewById(android.R.id.statusBarBackground), Window.STATUS_BAR_BACKGROUND_TRANSITION_NAME));
        list.add(Pair.create(fromActivity.findViewById(android.R.id.navigationBarBackground), Window.NAVIGATION_BAR_BACKGROUND_TRANSITION_NAME));
    }

    //remove any views that are null
    for (ListIterator<Pair<View, String>> iter = list.listIterator(); iter.hasNext();) {
        Pair pair = iter.next();
        if (pair.first == null) iter.remove();
    }

    sharedElements = list.toArray(new Pair[list.size()]);
    return ActivityOptionsCompat.makeSceneTransitionAnimation(
            fromActivity,
            sharedElements
    );
}
 
Example 9
Project: GitHub   File: Code.java   Source Code and License Vote up 5 votes
static List<Term> trimLeadingIndent(List<Term> code) {
  ArrayList<Term> result = new ArrayList<>(code);
  ListIterator<Term> it = result.listIterator();
  while (it.hasNext()) {
    Term t = it.next();
    if (t.isWhitespace()) {
      String whitespace = t.toString();
      int indexOf = whitespace.indexOf('\n');
      if (indexOf >= 0) {
        it.set(new Whitespace(whitespace.substring(0, indexOf + 1)));
      }
    }
  }
  return result;
}
 
Example 10
Project: java-tools   File: XLSXFileWriter.java   Source Code and License Vote up 5 votes
public void run() throws Exception
{
	zipStream = new ZipOutputStream(targetStream);
	
	ArrayList<ResultWorksheet> resultWorksheets = new ArrayList<ResultWorksheet>();
	makeWorksheets(resultWorksheets);
	
	if (resultWorksheets.size() == 0)
		throw new Exception("Cannot create workbook without worksheets"); 
	
	createResultSheetContentsAndClearMatrices(resultWorksheets);
	
	ListIterator<ResultWorksheet> it = resultWorksheets.listIterator();
	while (it.hasNext())
	{
		ResultWorksheet resultWorksheet = it.next();
		save(resultWorksheet.document, "xl/" + resultWorksheet.filename);
	}
	
	makeWorkbookRels(resultWorksheets);
	save(resultWorkbookRels, "xl/_rels/workbook.xml.rels");
	
	makeWorkbookDefinition(resultWorksheets);
	save(resultWorkbookDefinition, "xl/workbook.xml");
	
	makeRelsContentTypes(resultWorksheets);
	save(resultContentTypes, "[Content_Types].xml");
	
	makeRelsBase();
	save(resultRelsBase, "_rels/.rels");
	
	makeStyles();
	save(styles, "xl/styles.xml");
	
	zipStream.close();
}
 
Example 11
Project: IslamicLibraryAndroid   File: BookSearcher.java   Source Code and License Vote up 5 votes
public BookSearchResultsContainer getBookSearchResultsContainer(int bookId) {
    BookDatabaseHelper bookDatabaseHelper = BookDatabaseHelper.getInstance(context, bookId);
    ArrayList<SearchResult> results = bookDatabaseHelper.search(searchString,searchOptions);

    BookPartsInfo bookPartsInfo=bookDatabaseHelper.getBookPartsInfo();

    ListIterator<SearchResult> searchResultIterator = results.listIterator();
    while (searchResultIterator.hasNext()) {
        SearchResult searchResult = searchResultIterator.next();
        if (!searchResult.isRequired()) {
            searchResultIterator.remove();
        }
    }
    return new BookSearchResultsContainer(isExpanded, bookId, bookDatabaseHelper.getBookName(),bookPartsInfo, results);
}
 
Example 12
Project: APCSAB   File: IteratorLab_shell.java   Source Code and License Vote up 5 votes
public static ArrayList<Integer> replaceNeg(ArrayList<Integer> a) {
    ListIterator<Integer> iterator = a.listIterator();
    while (iterator.hasNext())
        if (iterator.next() < 0)
            iterator.set(0);
    return a;
}
 
Example 13
Project: hanlpStudy   File: CommonSynonymDictionary.java   Source Code and License Vote up 5 votes
/**
 * 随机挑一个近义词
 * @param type 类型
 * @return
 */
public Synonym randomSynonym(Type type, String preWord)
{
    ArrayList<Synonym> synonymArrayList = new ArrayList<Synonym>(synonymList);
    ListIterator<Synonym> listIterator = synonymArrayList.listIterator();
    if (type != null) while (listIterator.hasNext())
    {
        Synonym synonym = listIterator.next();
        if (synonym.type != type || (preWord != null && CoreBiGramTableDictionary.getBiFrequency(preWord, synonym.realWord) == 0)) listIterator.remove();
    }
    if (synonymArrayList.size() == 0) return null;
    return synonymArrayList.get((int) (System.currentTimeMillis() % (long)synonymArrayList.size()));
}
 
Example 14
Project: Idea-Plagiarism   File: checkPlagiarism.java   Source Code and License Vote up 5 votes
private ArrayList<String> extractMainWords(ArrayList<String> file) {
    List<String> commonWords = new ArrayList<>(Arrays.asList(common));
    ListIterator<String> iterator = file.listIterator();
    while (iterator.hasNext()) {
        iterator.set(iterator.next()
                .replaceAll("[^0-9][.]|[.][^0-9]|(?![.,])\\p{Punct}|\\,", "")
                .replace("\n", "")
                .replace("\r", "")
                .replaceAll("\\s+", " ")
                .toLowerCase());
    }
    for (int k = 0; k < file.size(); k++) {
        String[] words = file.get(k).split(" ");
        ArrayList<String> wordsList = new ArrayList<>(Arrays.asList(words));
        for (int i = 0; i < wordsList.size(); i++) {
            for (int j = 0; j < common.length; j++) {
                if (wordsList.contains(common[j])) {
                    wordsList.remove(common[j]);
                }
            }
        }
        StringBuilder sb = new StringBuilder();
        for (String s : wordsList) {
            sb.append(s);
            sb.append(" ");
        }
        file.set(k, sb.toString());
    }
    return file;
}
 
Example 15
Project: Saiy-PS   File: SaiyTextToSpeech.java   Source Code and License Vote up 5 votes
private ArrayList<SaiyVoice> filterLegacy(@NonNull final ArrayList<SaiyVoice> voiceArray) {
    if (DEBUG) {
        MyLog.i(CLS_NAME, "filterLegacy");
    }

    if (isNetworkAllowed) {

        final ArrayList<SaiyVoice> voiceArrayCopy = new ArrayList<>(voiceArray);
        final ListIterator<SaiyVoice> itr = voiceArrayCopy.listIterator();

        SaiyVoice v;
        while (itr.hasNext()) {
            v = itr.next();
            if (v.getFeatures().contains(TTSDefaults.LEGACY_ENGINE_FIELD)) {
                itr.remove();
            }
        }

        if (voiceArrayCopy.isEmpty()) {
            return filterQuality(voiceArray);
        } else {
            return filterQuality(voiceArrayCopy);
        }
    }

    return filterQuality(voiceArray);
}
 
Example 16
Project: Reer   File: RelativePath.java   Source Code and License Vote up 4 votes
public ListIterator<String> segmentIterator() {
    ArrayList<String> content = new ArrayList<String>(Arrays.asList(segments));
    return content.listIterator();
}
 
Example 17
Project: Swift-Braille-Soft-keyboard   File: Common.java   Source Code and License Vote up 4 votes
public static void changeKeyboardLanguage(KeyboardSurface keyboardSurface, InputConnection inputConnection) {
    try {
        ArrayList<Integer> activatedLanguages = new ArrayList<>();

        //Add activated languages to the list
        if(isEnglishInputMethodActivated){
            activatedLanguages.add(ENGLISH_LANGUAGE_INPUT_METHOD);
        }

        if(isArabicInputMethodActivated){
            activatedLanguages.add(ARABIC_LANGUAGE_INPUT_METHOD);
        }

        if(isSpanishInputMethodActivated){
            activatedLanguages.add(SPANISH_LANGUAGE_INPUT_METHOD);
        }

        if(isFrenchInputMethodActivated){
            activatedLanguages.add(FRENCH_LANGUAGE_INPUT_METHOD);
        }

        //Check the next language
        int nextLang;
        Iterator activatedLanguagesIterator;
        if(activatedLanguages.indexOf(currentLanguage) < activatedLanguages.size() - 1){
            activatedLanguagesIterator = activatedLanguages.listIterator(activatedLanguages.indexOf(currentLanguage));
            activatedLanguagesIterator.next(); //For initialization to first position purpose
            //I don't need the current iterator, move to the next one
            nextLang = (int)activatedLanguagesIterator.next();
        } else{
            activatedLanguagesIterator = activatedLanguages.iterator();
            //I need the current iterator
            nextLang = (int)activatedLanguagesIterator.next();
        }

        //Change to the next language
        if(nextLang == ENGLISH_LANGUAGE_INPUT_METHOD){
            keyboardSurface.patternSurface = new EnglishSmallCharPattern(context);
        } else if(nextLang == ARABIC_LANGUAGE_INPUT_METHOD){
            keyboardSurface.patternSurface = new ArabicCharPattern(context);
        } else if(nextLang == SPANISH_LANGUAGE_INPUT_METHOD){
            keyboardSurface.patternSurface = new SpanishSmallCharPattern(context, inputConnection);
        } else if(nextLang == FRENCH_LANGUAGE_INPUT_METHOD){
            keyboardSurface.patternSurface = new FrenchSmallCharPattern(context);
        }

        //Speech current keyboard language
        speechCurrentKeyboardLanguage();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example 18
Project: personium-core   File: CollectionTest.java   Source Code and License Vote up 4 votes
/**
 * PROPPATCH階層型の返却値のチェック関数.
 * @param doc 解析するXMLオブジェクト
 * @param resorce PROPPATCHを設定したリソースパス
 * @param lapName propタグ内でプロパティをラップしているタグ名
 * @param map チェックするプロパティのKeyValue KeyとValueに値を入れれば値があることのチェック ValueをnullにするとKeyが無いことのチェック(removeの確認に使う)
 */
private void proppatchClassResponseTest(Element doc, String resorce, String lapName, ArrayList<String> list) {
    NodeList response = doc.getElementsByTagName("response");
    assertEquals(1, response.getLength());
    Element node = (Element) response.item(0);
    assertEquals(
            resorce,
            node.getElementsByTagName("href").item(0).getFirstChild().getNodeValue());
    assertEquals(
            "HTTP/1.1 200 OK",
            node.getElementsByTagName("status").item(0).getFirstChild().getNodeValue());

    String lapNameFlg = null;
    NodeList tmp = node.getElementsByTagName("prop").item(0).getChildNodes();
    for (int i = 0; i < tmp.getLength(); i++) {
        Node child = tmp.item(i);
        if (child instanceof Element) {
            // プロパティをラップしているタグ名判断
            Element childElement = (Element) child;
            if (childElement.getLocalName().equals(lapName)) {
                lapNameFlg = "true";
                // Pathタグの内のプロパティ判断
                NodeList pTmp = childElement.getChildNodes();
                for (int ii = 0; ii < pTmp.getLength(); ii++) {
                    Node pChild = pTmp.item(ii);
                    if (pChild instanceof Element) {
                        Element pChildElement = (Element) pChild;
                        NamedNodeMap attrs = pChildElement.getAttributes();
                        if (attrs != null) {
                            String falg = null;
                            for (Iterator<String> it = list.listIterator(); it.hasNext();) {
                                Object key = it.next();
                                Object value = it.next();
                                Node attr = (Node) attrs.getNamedItem((String) key);
                                if (attr != null && attr.getNodeValue().equals(value)) {
                                    falg = "true";
                                }
                            }
                            assertNotNull(falg);
                        }
                    }
                }
            }
        }
    }
    // プロパティをラップしているタグ名判断
    assertNotNull(lapNameFlg);
}