本文整理了Java中java.util.ArrayList.indexOf()
方法的一些代码示例,展示了ArrayList.indexOf()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ArrayList.indexOf()
方法的具体详情如下:
包路径:java.util.ArrayList
类名称:ArrayList
方法名:indexOf
[英]Returns the index of the first occurrence of the specified element in this list, or -1 if this list does not contain the element. More formally, returns the lowest index i such that (o==null ? get(i)==null : o.equals(get(i))), or -1 if there is no such index.
[中]返回此列表中指定元素第一次出现的索引,如果此列表不包含该元素,则返回-1。更正式地说,返回最低的索引i(o==null?get(i)==null:o.equals(get(i)),或者如果没有这样的索引,返回-1。
代码示例来源:origin: zhihu/Matisse
public int checkedNumOf(Item item) {
int index = new ArrayList<>(mItems).indexOf(item);
return index == -1 ? CheckView.UNCHECKED : index + 1;
}
}
代码示例来源:origin: stackoverflow.com
ViewPager pager = /* get my ViewPager */;
// assume this actually has stuff in it
final ArrayList<String> titles = new ArrayList<String>();
FragmentManager fm = getSupportFragmentManager();
pager.setAdapter(new FragmentStatePagerAdapter(fm) {
public int getCount() {
return titles.size();
}
public Fragment getItem(int position) {
MyFragment fragment = new MyFragment();
fragment.setTitle(titles.get(position));
return fragment;
}
public int getItemPosition(Object item) {
MyFragment fragment = (MyFragment)item;
String title = fragment.getTitle();
int position = titles.indexOf(title);
if (position >= 0) {
return position;
} else {
return POSITION_NONE;
}
}
});
代码示例来源:origin: pentaho/pentaho-kettle
@Override
public FileStream getStream( String filename ) {
int index = namesList.indexOf( filename );
return index == -1 ? null : streamsList.get( index );
}
代码示例来源:origin: javax.portlet/portlet-api
private void addToMap(Map<String, Method> map, String name, Method newMethod) {
Method mapMethod = map.get(name);
// Adds new method to map if method does not exist in map
// or if class of new method is subclass of class of method in map.
if ((mapMethod != null) && (newMethod != null)) {
// get the class hierarchy.
ArrayList<Class<?>> classHierarchy = new ArrayList<Class<?>>();
for (Class<?> cls=this.getClass(); cls != null; cls=cls.getSuperclass()) {
classHierarchy.add(cls);
}
int classLevelMap = classHierarchy.indexOf(mapMethod.getDeclaringClass());
int classLevelNew = classHierarchy.indexOf(newMethod.getDeclaringClass());
if (classLevelMap <= classLevelNew) {
return;
}
}
map.put(name, newMethod);
}
}
代码示例来源:origin: TeamNewPipe/NewPipe
/**
* Shuffles the current play queue.
*
* This method first backs up the existing play queue and item being played.
* Then a newly shuffled play queue will be generated along with currently
* playing item placed at the beginning of the queue.
*
* Will emit a {@link ReorderEvent} in any context.
* */
public synchronized void shuffle() {
if (backup == null) {
backup = new ArrayList<>(streams);
}
final int originIndex = getIndex();
final PlayQueueItem current = getItem();
Collections.shuffle(streams);
final int newIndex = streams.indexOf(current);
if (newIndex != -1) {
streams.add(0, streams.remove(newIndex));
}
queueIndex.set(0);
broadcast(new ReorderEvent(originIndex, queueIndex.get()));
}
代码示例来源:origin: apache/hive
/**
* @return the partDescs for paths
*/
public List<PartitionDesc> getPartDescs(List<Path> paths) {
List<PartitionDesc> parts = new ArrayList<PartitionDesc>(paths.size());
for (Path path : paths) {
parts.add(partDesc.get(partDir.indexOf(path.getParent())));
}
return parts;
}
代码示例来源:origin: com.h2database/h2
/**
* Add a SQL statement to the history.
*
* @param sql the SQL statement
*/
void addCommand(String sql) {
if (sql == null) {
return;
}
sql = sql.trim();
if (sql.length() == 0) {
return;
}
if (commandHistory.size() > MAX_HISTORY) {
commandHistory.remove(0);
}
int idx = commandHistory.indexOf(sql);
if (idx >= 0) {
commandHistory.remove(idx);
}
commandHistory.add(sql);
if (server.isCommandHistoryAllowed()) {
server.saveCommandHistoryList(commandHistory);
}
}
代码示例来源:origin: crazycodeboy/TakePhoto
/**
* 为被裁切的图片设置已被裁切的标识
*
* @param uri 被裁切的图片
* @return 该图片是否是最后一张
*/
public Map setCropWithUri(Uri uri, boolean cropped) {
if (!cropped) {
hasFailed = true;
}
int index = outUris.indexOf(uri);
tImages.get(index).setCropped(cropped);
Map result = new HashMap();
result.put("index", index);
result.put("isLast", index == outUris.size() - 1 ? true : false);
return result;
}
}
代码示例来源:origin: gzu-liyujiang/AndroidPicker
private void initHourData() {
hours.clear();
int currentHour = 0;
if (!resetWhileWheel) {
if (timeMode == HOUR_24) {
currentHour = Calendar.getInstance().get(Calendar.HOUR_OF_DAY);
} else {
currentHour = Calendar.getInstance().get(Calendar.HOUR);
}
}
for (int i = startHour; i <= endHour; i++) {
String hour = DateUtils.fillZero(i);
if (!resetWhileWheel) {
if (i == currentHour) {
selectedHour = hour;
}
}
hours.add(hour);
}
if (hours.indexOf(selectedHour) == -1) {
//当前设置的小时不在指定范围,则默认选中范围开始的小时
selectedHour = hours.get(0);
}
if (!resetWhileWheel) {
selectedMinute = DateUtils.fillZero(Calendar.getInstance().get(Calendar.MINUTE));
}
}
代码示例来源:origin: chat-sdk/chat-sdk-android
public void removePicture(User user, String url) {
ArrayList<String> urls = fromUser(user);
boolean isDefault = urls.indexOf(url) == 0;
urls.remove(url);
urls.add("");
if (isDefault) {
setDefaultPicture(user, urls.get(0), urls);
}
setPictures(user, urls);
}
代码示例来源:origin: seven332/EhViewer
int index = mSceneTagList.indexOf(tag);
if (index < 0) {
Log.e(TAG, "finishScene: Can't find the tag in tag list: " + tag);
if (mSceneTagList.size() == 1) {
if (index == mSceneTagList.size() - 1) {
next = fragmentManager.findFragmentByTag(mSceneTagList.get(index - 1));
mSceneTagList.remove(index);
代码示例来源:origin: Rajawali/Rajawali
/**
* Adds a texture to this material. Throws and error if the maximum number of textures was reached.
*
* @param texture
*
* @throws TextureException
*/
public void addTexture(ATexture texture) throws TextureException {
if (mTextureList.indexOf(texture) > -1) return;
if (mTextureList.size() + 1 > mMaxTextures) {
throw new TextureException("Maximum number of textures for this material has been reached. Maximum number of textures is " + mMaxTextures + ".");
}
mTextureList.add(texture);
TextureManager.getInstance().addTexture(texture);
texture.registerMaterial(this);
mIsDirty = true;
}
代码示例来源:origin: lingochamp/okdownload
public Builder bindSetTask(@NonNull DownloadTask task) {
final int index = boundTaskList.indexOf(task);
if (index >= 0) {
// replace
boundTaskList.set(index, task);
} else {
boundTaskList.add(task);
}
return this;
}
代码示例来源:origin: facebook/stetho
public synchronized boolean unregister(PathMatcher path, HttpHandler handler) {
int index = mPathMatchers.indexOf(path);
if (index >= 0) {
if (handler == mHttpHandlers.get(index)) {
mPathMatchers.remove(index);
mHttpHandlers.remove(index);
return true;
}
}
return false;
}
代码示例来源:origin: cmusphinx/sphinx4
assert graph != null : "Graph not defined";
assert ((!isFinalNode(node)) && (!isInitialNode(node)));
int nodePosition = nodes.indexOf(node);
nodes.remove(nodePosition);
int index;
for (graph.startNodeIterator(), index = nodePosition;
graph.hasMoreNodes(); index++) {
nodes.add(index, graph.nextNode());
代码示例来源:origin: apache/geode
/**
* Hint size is used for filter ordering. Smaller values have preference
*/
public int getHintSize(String indexName) {
return -(hints.size() - hints.indexOf(indexName));
}
代码示例来源:origin: smuyyh/BookReader
public void removeFooter(ItemView view) {
int position = headers.size() + getCount() + footers.indexOf(view);
footers.remove(view);
notifyItemRemoved(position);
}
代码示例来源:origin: lealone/Lealone
private static void remove(ArrayList<? extends DbObject> list, DbObject obj) {
if (list != null) {
int i = list.indexOf(obj);
if (i >= 0) {
list.remove(i);
}
}
}
代码示例来源:origin: cmusphinx/sphinx4
/**
* Copies a path
*/
private static void duplicatePath(int lastPathIndex, State fromState,
State toState, ArrayList<ArrayList<State>> paths) {
ArrayList<State> lastPath = paths.get(lastPathIndex);
// copy the last path to a new one, from start to current state
int fromIndex = lastPath.indexOf(fromState);
int toIndex = lastPath.indexOf(toState);
if (toIndex == -1) {
toIndex = lastPath.size() - 1;
}
ArrayList<State> newPath = new ArrayList<State>(lastPath.subList(
fromIndex, toIndex));
paths.add(newPath);
}
代码示例来源:origin: sannies/mp4parser
assert stsc != null;
if (stsc.getEntries().isEmpty()) {
List<SampleToChunkBox.Entry> entries = new ArrayList<SampleToChunkBox.Entry>();
stsc.setEntries(entries);
entries.add(new SampleToChunkBox.Entry(chunkNumber, samples.size(), 1));
if (ctts == null) {
ctts = new CompositionTimeToSample();
ctts.setEntries(new ArrayList<CompositionTimeToSample.Entry>());
ArrayList<Box> bs = new ArrayList<Box>(stbl.getBoxes());
bs.add(bs.indexOf(stts), ctts);
if (stts.getEntries().isEmpty()) {
ArrayList<TimeToSampleBox.Entry> entries = new ArrayList<TimeToSampleBox.Entry>(stts.getEntries());
entries.add(new TimeToSampleBox.Entry(1, sample.getDuration()));
stts.setEntries(entries);
} else {
内容来源于网络,如有侵权,请联系作者删除!