Java Code Examples for java.util.LinkedList#indexOf()

The following examples show how to use java.util.LinkedList#indexOf() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ViewPool.java    From imsdk-android with MIT License 6 votes vote down vote up
public static void recycleView(View v) {
    Class type = v.getClass();
    if (v != null && type != null) {
        LinkedList<View> recycleQueue = recycleMap.get(type);
        LinkedList<View> usingList = usingMap.get(type);
        if (recycleQueue == null) {
            recycleQueue = new LinkedList<>();
            recycleMap.put(type, recycleQueue);
        }
        if (usingList == null) {
            usingList = new LinkedList<>();
            usingMap.put(type, usingList);
        }
        int index = usingList.indexOf(v);
        if (index != -1) {
            Object o = v.getTag(TAG_VIEW_CANNOT_RECYCLE);
            if (o == null) {
                recycleQueue.add(v);
                usingList.remove(v);
            }
        }
    }
}
 
Example 2
Source File: CEventCenter.java    From NettyChat with Apache License 2.0 5 votes vote down vote up
/**
 * 注册监听器
 * @param listener
 *                  监听器
 * @param topics
 *                  主题(一个服务可以发布多个主题事件)
 */
public static void registerEventListener(I_CEventListener listener, String[] topics) {
    if(null == listener || null == topics) {
        return;
    }

    synchronized (mListenerLock) {
        for(String topic : topics) {
            if(TextUtils.isEmpty(topic)) {
                continue;
            }
            Object obj = mListenerMap.get(topic);
            if(null == obj) {
                // 还没有监听器,直接放到Map集合
                mListenerMap.put(topic, listener);
            }else if(obj instanceof I_CEventListener) {
                // 有一个监听器
                I_CEventListener oldListener = (I_CEventListener) obj;
                if(listener == oldListener) {
                    // 去重
                    continue;
                }
                LinkedList<I_CEventListener> list = new LinkedList<I_CEventListener>();
                list.add(oldListener);
                list.add(listener);
                mListenerMap.put(topic, list);
            }else if(obj instanceof List) {
                // 有多个监听器
                LinkedList<I_CEventListener> listenerList = (LinkedList<I_CEventListener>) obj;
                if(listenerList.indexOf(listener) >= 0) {
                    // 去重
                    continue;
                }
                listenerList.add(listener);
            }
        }
    }
}
 
Example 3
Source File: CEventCenter.java    From CEventCenter with Apache License 2.0 5 votes vote down vote up
/**
 * 注册监听器
 *
 * @param listener 监听器
 * @param topics   多个主题
 */
public static void registerEventListener(I_CEventListener listener, String[] topics) {
    if (null == listener || null == topics) {
        return;
    }

    synchronized (LISTENER_LOCK) {
        for (String topic : topics) {
            if (TextUtils.isEmpty(topic)) {
                continue;
            }

            Object obj = LISTENER_MAP.get(topic);
            if (null == obj) {
                // 还没有监听器,直接放到Map集合
                LISTENER_MAP.put(topic, listener);
            } else if (obj instanceof I_CEventListener) {
                // 有一个监听器
                I_CEventListener oldListener = (I_CEventListener) obj;
                if (listener == oldListener) {
                    // 去重
                    continue;
                }
                LinkedList<I_CEventListener> list = new LinkedList<>();
                list.add(oldListener);
                list.add(listener);
                LISTENER_MAP.put(topic, list);
            } else if (obj instanceof List) {
                // 有多个监听器
                LinkedList<I_CEventListener> listeners = (LinkedList<I_CEventListener>) obj;
                if (listeners.indexOf(listener) >= 0) {
                    // 去重
                    continue;
                }
                listeners.add(listener);
            }
        }
    }
}
 
Example 4
Source File: DownloadManager.java    From MHViewer with Apache License 2.0 5 votes vote down vote up
public void deleteDownload(String gid) {
    stopDownloadInternal(gid);
    DownloadInfo info = mAllInfoMap.get(gid);
    if (info != null) {
        // Remove from DB
        EhDB.removeDownloadInfo(info.gid);

        // Remove all list and map
        mAllInfoList.remove(info);
        mAllInfoMap.remove(info.gid);

        // Remove label list
        LinkedList<DownloadInfo> list = getInfoListForLabel(info.label);
        if (list != null) {
            int index = list.indexOf(info);
            if (index >= 0) {
                list.remove(info);
                // Update listener
                for (DownloadInfoListener l: mDownloadInfoListeners) {
                    l.onRemove(info, list, index);
                }
            }
        }

        // Ensure download
        ensureDownload();
    }
}
 
Example 5
Source File: SchemaUpdate.java    From iceberg with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("checkstyle:IllegalType")
private static List<Types.NestedField> moveFields(List<Types.NestedField> fields,
                                                  Collection<Move> moves) {
  LinkedList<Types.NestedField> reordered = Lists.newLinkedList(fields);

  for (Move move : moves) {
    Types.NestedField toMove = Iterables.find(reordered, field -> field.fieldId() == move.fieldId());
    reordered.remove(toMove);

    switch (move.type()) {
      case FIRST:
        reordered.addFirst(toMove);
        break;

      case BEFORE:
        Types.NestedField before = Iterables.find(reordered, field -> field.fieldId() == move.referenceFieldId());
        int beforeIndex = reordered.indexOf(before);
        // insert the new node at the index of the existing node
        reordered.add(beforeIndex, toMove);
        break;

      case AFTER:
        Types.NestedField after = Iterables.find(reordered, field -> field.fieldId() == move.referenceFieldId());
        int afterIndex = reordered.indexOf(after);
        reordered.add(afterIndex + 1, toMove);
        break;

      default:
        throw new UnsupportedOperationException("Unknown move type: " + move.type());
    }
  }

  return reordered;
}
 
Example 6
Source File: LegacyNetVSBattleMode.java    From nullpomino with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Update player names
 */
private void updatePlayerNames() {
	LinkedList<NetPlayerInfo> pList = netLobby.getSameRoomPlayerInfoList();
	LinkedList<String> teamList = new LinkedList<String>();

	for(int i = 0; i < MAX_PLAYERS; i++) {
		playerNames[i] = "";
		playerTeams[i] = "";
		playerTeamColors[i] = 0;
		playerGamesCount[i] = 0;
		playerWinCount[i] = 0;

		for(NetPlayerInfo pInfo: pList) {
			if((pInfo.seatID != -1) && (getPlayerIDbySeatID(pInfo.seatID) == i)) {
				playerNames[i] = pInfo.strName;
				playerTeams[i] = pInfo.strTeam;
				playerGamesCount[i] = pInfo.playCountNow;
				playerWinCount[i] = pInfo.winCountNow;

				// Set team color
				if(playerTeams[i].length() > 0) {
					if(!teamList.contains(playerTeams[i])) {
						teamList.add(playerTeams[i]);
						playerTeamColors[i] = teamList.size();
					} else {
						playerTeamColors[i] = teamList.indexOf(playerTeams[i]) + 1;
					}
				}
			}
		}
	}
}
 
Example 7
Source File: Tools.java    From Zettelkasten with GNU General Public License v3.0 5 votes vote down vote up
/**
 * This method extracts all author IDs of footnotes in a HTML formatted entry.
 * This method is used when displaying an entry in the main window, to
 * show all authors of an entry, including those authors which appear
 * in footnotes, but are not assigned as author value.
 * 
 * @param content the HTML-formatted content of an entry.
 * @return all author IDs inside footnotes
 */
public static LinkedList extractFootnotesFromContent(String content) {
    // now prepare a reference list from possible footnotes
    LinkedList<String> footnotes = new LinkedList<>();
    // position index for finding the footnotes
    int pos = 0;
    // do search as long as pos is not -1 (not-found)
    while (pos != -1) {
        // find the html-tag for the footnote
        pos = content.indexOf(Constants.footnoteHtmlTag, pos);
        // if we found something...
        if (pos != -1) {
            // find the closing quotes
            int end = content.indexOf("\"", pos + Constants.footnoteHtmlTag.length());
            // if we found that as well...
            if (end != -1) {
                // extract footnote-number
                String fn = content.substring(pos + Constants.footnoteHtmlTag.length(), end);
                // and add it to the linked list, if it doesn't already exist
                if (-1 == footnotes.indexOf(fn)) {
                    footnotes.add(fn);
                }
                // set pos to new position
                pos = end;
            } else {
                pos = pos + Constants.footnoteHtmlTag.length();
            }
        }
    }
    return footnotes;
}
 
Example 8
Source File: SeqEval.java    From fnlp with GNU Lesser General Public License v3.0 5 votes vote down vote up
void getRightOOV(String string) {

		if(dict==null||dict.size()==0)
			return;

		TreeMap<String,String> set = new TreeMap<String,String>();
		for(int i=0;i<entityCs.size();i++){
			LinkedList<Entity>  cList =  entityCs.get(i);
			LinkedList<Entity>  pList =  entityPs.get(i);
			LinkedList<Entity>  cpList =  entityCinPs.get(i);

			for(Entity entity:cpList){
				String e = entity.getEntityStr();
				//				if(dict.contains(e))
				//					break;
				int idx = cList.indexOf(entity);
				String s= " ... ";
				if(idx!=-1){
					if(idx>0)
						s = cList.get(idx-1).getEntityStr() + s;
					if(idx<cList.size()-1)
						s = s+ cList.get(idx+1).getEntityStr();
				}
				adjust(set, s, 1);
			}	

		}
		List<Entry> sortedposFreq = MyCollection.sort(set);		
		MyCollection.write(sortedposFreq, string, true);

	}
 
Example 9
Source File: Core.java    From Rel with Apache License 2.0 5 votes vote down vote up
public static void updateRecentlyUsedDatabaseList(String dbURL) {
	if (dbURL.startsWith("db:")) {
		File urlFileRef = new File(dbURL.substring(3));
		dbURL = "db:" + urlFileRef.getAbsolutePath();
	}
	LinkedList<String> recentlyUsed = new LinkedList<String>();
	recentlyUsed.addAll(Arrays.asList(Preferences.getPreferenceStringArray(recentlyUsedDatabaseListPreference)));
	int indexOfDBURL = recentlyUsed.indexOf(dbURL);
	if (indexOfDBURL >= 0)
		recentlyUsed.remove(dbURL);
	recentlyUsed.addFirst(dbURL);
	Preferences.setPreference(recentlyUsedDatabaseListPreference, recentlyUsed.toArray(new String[0]));
}
 
Example 10
Source File: DownloadManager.java    From EhViewer with Apache License 2.0 5 votes vote down vote up
public void deleteDownload(long gid) {
    stopDownloadInternal(gid);
    DownloadInfo info = mAllInfoMap.get(gid);
    if (info != null) {
        // Remove from DB
        EhDB.removeDownloadInfo(info.gid);

        // Remove all list and map
        mAllInfoList.remove(info);
        mAllInfoMap.remove(info.gid);

        // Remove label list
        LinkedList<DownloadInfo> list = getInfoListForLabel(info.label);
        if (list != null) {
            int index = list.indexOf(info);
            if (index >= 0) {
                list.remove(info);
                // Update listener
                for (DownloadInfoListener l: mDownloadInfoListeners) {
                    l.onRemove(info, list, index);
                }
            }
        }

        // Ensure download
        ensureDownload();
    }
}
 
Example 11
Source File: NetDummyVSMode.java    From nullpomino with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * NET-VS: Update player variables
 */
@Override
protected void netUpdatePlayerExist() {
	netvsMySeatID = netLobby.netPlayerClient.getYourPlayerInfo().seatID;
	netvsNumPlayers = 0;
	netNumSpectators = 0;
	netPlayerName = netLobby.netPlayerClient.getPlayerName();
	netIsWatch = netvsIsWatch();

	for(int i = 0; i < NETVS_MAX_PLAYERS; i++) {
		netvsPlayerExist[i] = false;
		netvsPlayerReady[i] = false;
		netvsPlayerActive[i] = false;
		netvsPlayerSeatID[i] = -1;
		netvsPlayerUID[i] = -1;
		netvsPlayerWinCount[i] = 0;
		netvsPlayerPlayCount[i] = 0;
		netvsPlayerName[i] = "";
		netvsPlayerTeam[i] = "";
		owner.engine[i].framecolor = GameEngine.FRAME_COLOR_GRAY;
	}

	LinkedList<NetPlayerInfo> pList = netLobby.updateSameRoomPlayerInfoList();
	LinkedList<String> teamList = new LinkedList<String>();

	for(NetPlayerInfo pInfo: pList) {
		if(pInfo.roomID == netCurrentRoomInfo.roomID) {
			if(pInfo.seatID == -1) {
				netNumSpectators++;
			} else {
				netvsNumPlayers++;

				int playerID = netvsGetPlayerIDbySeatID(pInfo.seatID);
				netvsPlayerExist[playerID] = true;
				netvsPlayerReady[playerID] = pInfo.ready;
				netvsPlayerActive[playerID] = pInfo.playing;
				netvsPlayerSeatID[playerID] = pInfo.seatID;
				netvsPlayerUID[playerID] = pInfo.uid;
				netvsPlayerWinCount[playerID] = pInfo.winCountNow;
				netvsPlayerPlayCount[playerID] = pInfo.playCountNow;
				netvsPlayerName[playerID] = pInfo.strName;
				netvsPlayerTeam[playerID] = pInfo.strTeam;

				// Set frame color
				if(pInfo.seatID < NETVS_PLAYER_COLOR_FRAME.length) {
					owner.engine[playerID].framecolor = NETVS_PLAYER_COLOR_FRAME[pInfo.seatID];
				}

				// Set team color
				if(netvsPlayerTeam[playerID].length() > 0) {
					if(!teamList.contains(netvsPlayerTeam[playerID])) {
						teamList.add(netvsPlayerTeam[playerID]);
						netvsPlayerTeamColor[playerID] = teamList.size();
					} else {
						netvsPlayerTeamColor[playerID] = teamList.indexOf(netvsPlayerTeam[playerID]) + 1;
					}
				}
			}
		}
	}
}
 
Example 12
Source File: ListTests.java    From spotbugs with GNU Lesser General Public License v2.1 4 votes vote down vote up
public void test2NoBugs(LinkedList<CharSequence> list) {
    list.indexOf(new StringBuffer("Key"));
}
 
Example 13
Source File: ListTests.java    From spotbugs with GNU Lesser General Public License v2.1 4 votes vote down vote up
public void test2Bugs(LinkedList<CharSequence> list) {
    list.indexOf(Integer.valueOf(3));
}
 
Example 14
Source File: ExportTools.java    From Zettelkasten with GNU General Public License v3.0 4 votes vote down vote up
/**
 * This method creates a reference list in the export-format. This method is
 * used when exporting entries into html-format. The reference-list is
 * created from the used footnotes, i.e. each author-footnote in an entry is
 * added to the final reference-list. When exporting to HTML, the
 * authors-footnotes are linked with the author-value in the reference-list.
 *
 * @param dataObj
 * @param settingsObj
 * @param contentpage the complete html-page that is going to be exported,
 * so the author-footnotes can be extracted from this content.
 * @param footnotetag the footnote-tag, to identify where a footnote starts
 * @param footnoteclose the closing-tag of footnotes, so the author-number
 * within the footnote can be extracted
 * @param headeropen the header-tag, in case the title "reference list" is
 * surrounded by a header-tag
 * @param headerclose the header-tag, in case the title "reference list" is
 * surrounded by a header-tag
 * @param listtype whether the list is formatted in html or plain text. use
 * following constants:<br>
 * - CConstants.REFERENCE_LIST_TXT<br>
 * - CConstants.REFERENCE_LIST_HTML
 * @return a converted String containing the reference list with all
 * references (authors) that appeared as author-footnote in the export-file
 */
public static String createReferenceList(Daten dataObj, Settings settingsObj, String contentpage, String footnotetag, String footnoteclose, String headeropen, String headerclose, int listtype) {
    // now prepare a reference list from possible footnotes
    LinkedList<String> footnotes = new LinkedList<>();
    // position index for finding the footnotes
    int pos = 0;
    // get length of footnote-tag, so we know where to look for the author-number within the footnote
    int len = footnotetag.length();
    // do search as long as pos is not -1 (not-found)
    while (pos != -1) {
        // find the html-tag for the footnote
        pos = contentpage.indexOf(footnotetag, pos);
        // if we found something...
        if (pos != -1) {
            // find the closing quotes
            int end = contentpage.indexOf(footnoteclose, pos + len);
            // if we found that as well...
            if (end != -1) {
                // extract footnote-number
                String fn = contentpage.substring(pos + len, end);
                // and add it to the linked list, if it doesn't already exist
                if (-1 == footnotes.indexOf(fn)) {
                    footnotes.add(fn);
                }
                // set pos to new position
                pos = end;
            } else {
                pos = pos + len;
            }
        }
    }
    StringBuilder sb = new StringBuilder("");
    // now we have all footnotes, i.e. the author-index-numbers, in the linked
    // list. now we can create a reference list
    if (footnotes.size() > 0) {
        // first, init the list in html...
        sb.append(headeropen);
        // append a new headline with the bullet's name
        sb.append(resourceMap.getString("referenceListHeading"));
        sb.append(headerclose).append(System.lineSeparator());
        // iterator for the linked list
        Iterator<String> i = footnotes.iterator();
        // go through all footnotes
        while (i.hasNext()) {
            // get author-number-string
            String au = i.next();
            try {
                // convert string to int
                int aunr = Integer.parseInt(au);
                switch (listtype) {
                    case Constants.REFERENCE_LIST_TXT:
                        // prepare html-stuff for authors
                        sb.append("[").append(au).append("] ").append(dataObj.getAuthor(aunr)).append(System.lineSeparator());
                        break;
                    case Constants.REFERENCE_LIST_HTML:
                        // prepare html-stuff for authors
                        sb.append("<p class=\"reflist\"><b>[<a name=\"fn_").append(au).append("\">").append(au).append("</a>]</b> ");
                        sb.append(dataObj.getAuthor(aunr));
                        sb.append("</p>").append(System.lineSeparator());
                        break;
                }
            } catch (NumberFormatException e) {
                Constants.zknlogger.log(Level.WARNING, e.getLocalizedMessage());
            }
        }
    }
    return sb.toString();
}
 
Example 15
Source File: ExportToHtmlTask.java    From Zettelkasten with GNU General Public License v3.0 4 votes vote down vote up
/**
 *
 * @param createTOC
 * @return
 */
private String createFootnotes(boolean createTOC) {
    // now prepare a reference list from possible footnotes
    LinkedList<String> footnotes = new LinkedList<>();
    // position index for finding the footnotes
    int pos = 0;
    // we need the content of the stringbuilder in a string that we can search through
    String dummysb = exportPage.toString();
    // do search as long as pos is not -1 (not-found)
    while (pos != -1) {
        // find the html-tag for the footnote
        pos = dummysb.indexOf(Constants.footnoteHtmlTag, pos);
        // if we found something...
        if (pos != -1) {
            // find the closing quotes
            int end = dummysb.indexOf("\"", pos + Constants.footnoteHtmlTag.length());
            // if we found that as well...
            if (end != -1) {
                // extract footnote-number
                String fn = dummysb.substring(pos + Constants.footnoteHtmlTag.length(), end);
                // and add it to the linked list, if it doesn't already exist
                if (-1 == footnotes.indexOf(fn)) {
                    footnotes.add(fn);
                }
                // set pos to new position
                pos = end;
            } else {
                pos = pos + Constants.footnoteHtmlTag.length();
            }
        }
    }
    // now we have all footnotes, i.e. the author-index-numbers, in the linked
    // list. now we can create a reference list
    if (footnotes.size() > 0) {
        // insert a paragraph for space
        exportPage.append("<p>&nbsp;</p>").append(System.lineSeparator());
        // first, init the list in html and add title "references"
        exportPage.append("<h1>").append(resourceMap.getString("referenceListHeading")).append("</h1>").append(System.lineSeparator());
        // open unordered list-tag
        exportPage.append("<ul>").append(System.lineSeparator());
        // iterator for the linked list
        Iterator<String> i = footnotes.iterator();
        while (i.hasNext()) {
            String au = i.next();
            try {
                int aunr = Integer.parseInt(au);
                exportPage.append("<li class=\"reflist\"><b>[<a name=\"fn_").append(au).append("\">").append(au).append("</a>]</b> ");
                exportPage.append(dataObj.getAuthor(aunr));
                exportPage.append("</li>").append(System.lineSeparator());
            } catch (NumberFormatException e) {
                Constants.zknlogger.log(Level.WARNING, e.getLocalizedMessage());
            }
        }
        // close unordered list-tag
        exportPage.append("</ul>").append(System.lineSeparator());
    }
    // add table of contents, if requested
    if (createTOC) {
        exportPage.insert(0, exportTableOfContent.toString() + "<br><p>&nbsp;</p><br>");
    }
    // and if so, insert style-definition
    exportPage.insert(0, HtmlUbbUtil.getHtmlHeaderForDesktopExport(settingsObj));
    // and close tags
    exportPage.append("</body></html>");
    // return result
    return exportPage.toString();
}
 
Example 16
Source File: NiftyDDManager.java    From niftyeditor with Apache License 2.0 4 votes vote down vote up
private int findIndex(GElement dragged) {
    LinkedList<GElement> elements = dragged.getParent().getElements();
    return elements.indexOf(dragged);
}