java.util.ArrayList#indexOf ( )源码实例Demo

下面列出了java.util.ArrayList#indexOf ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: ramus   文件: Runner.java
public static void saveFileToHistory(File file) {
    if (file != null) {
        ArrayList<String> files = new ArrayList<String>();
        files.add(file.getAbsolutePath());
        String[] lasts = getLastOpenedFiles();
        int count = 0;
        for (String last : lasts) {
            if (count > 10)
                break;
            if (files.indexOf(last) < 0)
                files.add(last);
            count++;
        }

        setLastOpenedFiles(files.toArray(new String[files.size()]));
        Options.setString("LAST_FILE", file.getAbsolutePath());
        Options.setString("LAST_FILE_FIRST", file.getAbsolutePath());
    }
}
 
源代码2 项目: charts   文件: GraphCalculator.java
private ArrayList<ArrayList<GraphNode>> createRealPathsRecursive(ArrayList<GraphNode>[][] paths, ArrayList<GraphNode> graphNodes, GraphNode from, GraphNode to){
    if(paths[graphNodes.indexOf(from)][graphNodes.indexOf(to)].size() == 1 && paths[graphNodes.indexOf(from)][graphNodes.indexOf(to)].get(0).equals(from)){
        return new ArrayList<>();
    } else{
        ArrayList<ArrayList<GraphNode>> ListOfLists = new ArrayList<>();
        for(GraphNode node: paths[graphNodes.indexOf(from)][graphNodes.indexOf(to)] ){
            //ListOfLists.add(createRealPathsRecursive(paths, graphNodes, node, from));
            ArrayList<ArrayList<GraphNode>> subpaths = createRealPathsRecursive(paths, graphNodes, node, from);
            if(subpaths.isEmpty()){
                ArrayList<GraphNode> temp = new ArrayList<>();
                temp.add(node);
                ListOfLists.add(temp);
            } else {
                for(ArrayList<GraphNode> ap: subpaths){
                    ap.add(node);
                    ListOfLists.add(ap);
                }
            }
        }
        return ListOfLists;
    }
}
 
/**
 * @see ITypeHierarchy
 */
public synchronized void addTypeHierarchyChangedListener(ITypeHierarchyChangedListener listener) {
	ArrayList listeners = this.changeListeners;
	if (listeners == null) {
		this.changeListeners = listeners = new ArrayList();
	}

	// register with JavaCore to get Java element delta on first listener added
	if (listeners.size() == 0) {
		JavaCore.addElementChangedListener(this);
	}

	// add listener only if it is not already present
	if (listeners.indexOf(listener) == -1) {
		listeners.add(listener);
	}
}
 
源代码4 项目: KEEL   文件: TreeNode.java
/**
 * Gets an array with the frecuencies of the classes in the node
 * 
 * @return an array with the frecuencies of the classes in the node
 */
private int [] getOutputClassDistribution () {
    int [] output;
    int num_classes = getNumClasses();
    ArrayList <Double> which_classes = getClasses();
    
    output = new int [num_classes];
    
    // Before starting, the number of elements in each class is 0
    for (int i=0; i<num_classes; i++) {
        output[i] = 0;
    }
    
    // We count every instance in the node for the class distribution
    for (int i=0; i<oclass.size(); i++) {
        int position = which_classes.indexOf (oclass.get(i));
        output[position]++;
    }
    
    return output;
}
 
源代码5 项目: buffer_bci   文件: ServerController.java
protected void updateBufferConnections(final BufferConnectionInfo[] connectionInfos) {
    for (final BufferConnectionInfo bufferconnection : connectionInfos) {
        if (bufferConnections.get(bufferconnection.getConnectionID()) == null) {
            bufferConnections.put(bufferconnection.getConnectionID(), bufferconnection);
            bufferConnectionsArray.add(bufferconnection);
        } else {
            bufferConnections.get(bufferconnection.getConnectionID()).update(bufferconnection);
            ArrayList<BufferConnectionInfo> tempInfo = new ArrayList<BufferConnectionInfo>(bufferConnectionsArray);
            for (BufferConnectionInfo oldConnection : tempInfo) {
                if (oldConnection.getConnectionID() == bufferconnection.getConnectionID()) { //Removing duplicates of BufferConnectionInfo with same connectionID
                    int index = tempInfo.indexOf(oldConnection);
                    bufferConnectionsArray.remove(index);
                    bufferConnectionsArray.add(bufferconnection);
                }
            }
        }
    }
}
 
源代码6 项目: vscode-as3mxml   文件: AIROptionsParserTests.java
@Test
void testApplicationContent()
{
	String filename = "content.swf";
	String dirPath = "path/to";
	String value = dirPath + "/" + filename;
	String formattedDirPath = Paths.get(dirPath).toString();
	ObjectNode options = JsonNodeFactory.instance.objectNode();
	ArrayList<String> result = new ArrayList<>();
	parser.parse(AIRPlatform.AIR, false, "application.xml", value, options, result);
	Assertions.assertFalse(result.contains(value),
		"AIROptionsParser.parse() incorrectly contains application content path.");
	int optionIndex = result.indexOf("-C");
	Assertions.assertNotEquals(-1, optionIndex);
	Assertions.assertEquals(optionIndex + 1, result.indexOf(formattedDirPath));
	Assertions.assertEquals(optionIndex + 2, result.indexOf(filename));
}
 
源代码7 项目: juniversal   文件: CSharpASTNodeWriter.java
public void writeWildcardTypeSyntheticName(ArrayList<WildcardType> wildcardTypes, WildcardType wildcardType) {
    int index = wildcardTypes.indexOf(wildcardType);
    if (index == -1)
        throw new JUniversalException("Wildcard type not found in list");

    if (wildcardTypes.size() == 1)
        write("TWildcard");
    else write("TWildcard" + (index + 1));
}
 
源代码8 项目: PocketMaps   文件: IO.java
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private static void addSelection(AlertDialog.Builder builder1, boolean cacheDir, final Runnable callback, Activity activity)
{
  String curFolder = Variable.getVariable().getMapsFolder().getPath();
  int curSelected = 0;
  final ArrayList<String> items = listSelectionPathsLollipop(activity, cacheDir);
  final ArrayList<String> itemsText = new ArrayList<String>();
  for (String item : items)
  {
    itemsText.add(getStorageText(new File(item)));
    if (curFolder.startsWith(item))
    {
      curSelected = items.indexOf(item);
    }
  }
  OnClickListener listener = new OnClickListener()
  {
    @Override
    public void onClick(DialogInterface dialog, int buttonNr)
    {
      String selection = items.get(buttonNr);
      Variable.getVariable().setBaseFolder(selection);
      File mapsFolder = Variable.getVariable().getMapsFolder();
      if (!mapsFolder.exists()) { mapsFolder.mkdirs(); }
      Variable.getVariable().saveVariables(Variable.VarType.Base);
      Variable.getVariable().getLocalMaps().clear();
      dialog.dismiss();
      callback.run();
    }
  };
  builder1.setSingleChoiceItems(itemsText.toArray(new String[0]), curSelected, listener);
}
 
源代码9 项目: android_9.0.0_r45   文件: FocusFinder.java
private static View getPreviousFocusable(View focused, ArrayList<View> focusables, int count) {
    if (focused != null) {
        int position = focusables.indexOf(focused);
        if (position > 0) {
            return focusables.get(position - 1);
        }
    }
    if (!focusables.isEmpty()) {
        return focusables.get(count - 1);
    }
    return null;
}
 
源代码10 项目: hadoop-gpu   文件: SerializedRecord.java
private static void move(ArrayList<String> keys, String key, int position) {
  int cur = keys.indexOf(key);
  if (cur == -1)
    return;
  keys.set(cur, keys.get(position));
  keys.set(position, key);
}
 
源代码11 项目: cpsolver   文件: SuggestionsBranchAndBound.java
/**
 * Check bound
 * @param requests2resolve requests to resolve
 * @param idx current depth
 * @param depth remaining depth
 * @param value enrollment in question
 * @param conflicts conflicting enrollments
 * @return false if the branch can be cut
 */
protected boolean checkBound(ArrayList<Request> requests2resolve, int idx, int depth, Enrollment value,
        Set<Enrollment> conflicts) {
    if (iMaxSectionsWithPenalty < 0.0 && idx > 0 && !conflicts.isEmpty()) return false;
    int nrUnassigned = requests2resolve.size() - idx;
    if ((nrUnassigned + conflicts.size() > depth)) {
        return false;
    }
    for (Enrollment conflict : conflicts) {
        int confIdx = requests2resolve.indexOf(conflict.variable());
        if (confIdx >= 0 && confIdx <= idx)
            return false;
    }
    if (iMaxSectionsWithPenalty >= 0) {
        double sectionsWithPenalty = 0;
        for (Request r : iStudent.getRequests()) {
            Enrollment e = iAssignment.getValue(r);
            if (r.equals(value.variable())) {
                e = value;
            } else if (conflicts.contains(e)) {
                e = null;
            }
            if (e != null && e.isCourseRequest()) {
                sectionsWithPenalty += iModel.getOverExpected(iAssignment, e, value, conflicts);
            }
        }
        if (sectionsWithPenalty > iMaxSectionsWithPenalty)
            return false;
    }
    return true;
}
 
源代码12 项目: vscode-as3mxml   文件: AIROptionsParserTests.java
@Test
void testConnectDebugAndroid()
{
	boolean value = true;
	ObjectNode options = JsonNodeFactory.instance.objectNode();
	ObjectNode android = JsonNodeFactory.instance.objectNode();
	android.set(AIROptions.CONNECT, JsonNodeFactory.instance.booleanNode(value));
	options.set(AIRPlatform.ANDROID, android);
	ArrayList<String> result = new ArrayList<>();
	parser.parse(AIRPlatform.ANDROID, true, "application.xml", "content.swf", options, result);
	int optionIndex = result.indexOf("-" + AIROptions.CONNECT);
	Assertions.assertNotEquals(-1, optionIndex);
}
 
源代码13 项目: vscode-as3mxml   文件: AIROptionsParserTests.java
@Test
void testArch()
{
	String value = "x86";
	ObjectNode options = JsonNodeFactory.instance.objectNode();
	ObjectNode android = JsonNodeFactory.instance.objectNode();
	android.set(AIROptions.ARCH, JsonNodeFactory.instance.textNode(value));
	options.set(AIRPlatform.ANDROID, android);
	ArrayList<String> result = new ArrayList<>();
	parser.parse(AIRPlatform.ANDROID, false, "application.xml", "content.swf", options, result);
	int optionIndex = result.indexOf("-" + AIROptions.ARCH);
	Assertions.assertNotEquals(-1, optionIndex);
	Assertions.assertEquals(optionIndex + 1, result.indexOf(value));
}
 
源代码14 项目: KEEL   文件: TreeNode.java
/**
 * Gets the output class of the majority of the instances. If there are two majority classes, it
 * selects randomly one of them
 *
 * @return the majority class of the node
 */
private int getMajorOutputClass () {
    int num_classes = getNumClasses();
    int [] repetitions = new int [num_classes];
    int max, posmax;
    ArrayList <Double> which_classes = getClasses();
    
    for (int i=0; i<num_classes; i++) {
        repetitions[i] = 0;
    }
 
    // Count the frecuence of each output class
    for (int j=0; j<oclass.size(); j++) {
        int position = which_classes.indexOf (oclass.get(j));
        repetitions[position]++;
    }
    
    max = repetitions[0];
    posmax = 0;
 
    // Find the maximum output class
    for (int i=1; i<num_classes; i++) {
        if (repetitions[i] > max) {
            max = repetitions[i];
            posmax = i;
        }
        else if (repetitions[i] == max) {
            // If the maximum is equal, then decide a maximum randomly
            System.out.println("Can't decide better outputClass between " + posmax + " y " + i);
            int selection = generator.nextInt(2);
            if (selection == 1) {
                max = repetitions[i];
                posmax = i;
            }
            System.out.println("Finally selected " + posmax);
        }
    }
    
    return posmax;
}
 
源代码15 项目: matrix-android-console   文件: Matrix.java
/**
 * Retrieve the default session if one exists.
 *
 * The default session may be user-configured, or it may be the last session the user was using.
 * @return The default session or null.
 */
public synchronized MXSession getDefaultSession() {
    ArrayList<MXSession> sessions = getSessions();

    if (sessions.size() > 0) {
        return sessions.get(0);
    }

    ArrayList<HomeserverConnectionConfig> hsConfigList = mLoginStorage.getCredentialsList();

    // any account ?
    if ((hsConfigList == null) || (hsConfigList.size() == 0)) {
        return null;
    }

    ArrayList<String> matrixIds = new ArrayList<String>();
    sessions = new ArrayList<MXSession>();

    for(HomeserverConnectionConfig config: hsConfigList) {
        // avoid duplicated accounts.
        if (config.getCredentials() != null && matrixIds.indexOf(config.getCredentials().userId) < 0) {
            MXSession session = createSession(config);
            sessions.add(session);
            matrixIds.add(config.getCredentials().userId);
        }
    }

    synchronized (instance) {
        mMXSessions = sessions;
    }

    return sessions.get(0);
}
 
源代码16 项目: CircularReveal   文件: DynamicAnimation.java
/**
 * Remove an entry from the list by marking it {@code null} and clean up later.
 */
private static <T> void removeEntry(ArrayList<T> list, T entry) {
  int id = list.indexOf(entry);
  if (id >= 0) {
    list.set(id, null);
  }
}
 
源代码17 项目: vscode-as3mxml   文件: AIROptionsParserTests.java
@Test
void testConnectListenDebugDefaultsAndroid()
{
	ObjectNode options = JsonNodeFactory.instance.objectNode();
	ObjectNode android = JsonNodeFactory.instance.objectNode();
	options.set(AIRPlatform.ANDROID, android);
	ArrayList<String> result = new ArrayList<>();
	parser.parse(AIRPlatform.ANDROID, true, "application.xml", "content.swf", options, result);
	int optionIndex1 = result.indexOf("-" + AIROptions.CONNECT);
	Assertions.assertNotEquals(-1, optionIndex1);
	int optionIndex2 = result.indexOf("-" + AIROptions.LISTEN);
	Assertions.assertEquals(-1, optionIndex2);
}
 
源代码18 项目: Album   文件: AlbumActivity.java
@Override
public void onPreviewChanged(AlbumFile albumFile) {
    ArrayList<AlbumFile> albumFiles = mAlbumFolders.get(mCurrentFolder).getAlbumFiles();
    int position = albumFiles.indexOf(albumFile);
    int notifyPosition = mHasCamera ? position + 1 : position;
    mView.notifyItem(notifyPosition);

    if (albumFile.isChecked()) {
        if (!mCheckedList.contains(albumFile)) mCheckedList.add(albumFile);
    } else {
        if (mCheckedList.contains(albumFile)) mCheckedList.remove(albumFile);
    }
    setCheckedCount();
}
 
源代码19 项目: android-discourse   文件: ImageClickableSpan.java
@SuppressWarnings("unchecked")
@Override
public void onClick(View v) {
    ArrayList<String> imgs = (ArrayList<String>) v.getTag(R.id.poste_image_data);
    final Integer index = imgs.indexOf(mURL);
    Context a = v.getContext();
    String[] img = new String[imgs.size()];
    img = imgs.toArray(img);
    ActivityUtils.openPhotosActivity(a, index, img);
}
 
源代码20 项目: PhrackCTF-Platform-Team   文件: CommonUtils.java
@SuppressWarnings("unchecked")
public static long getTeamrank(Teams teamobj,TeamServices teamServices,UserServices userServices,SubmissionServices submissionServices){
	List<Teams> teamlist = teamServices.getAllTeams();
	List<Users> userforrank = userServices.getUsersForRank();
	List<Submissions> subs = submissionServices.getAllCorrectOrderByTime();
	ArrayList<TeamRankObj> teamranklist = new ArrayList<TeamRankObj>();
	Teams thisteam = null;
	for (Teams tm:teamlist) {
		if (!tm.getIsenabled()) {
			continue;
		}
		TeamRankObj tro = new TeamRankObj(tm);
		for (Submissions sb:subs) {
			Users subuserobj = null;
			for (Users u:userforrank) {
				if (u.getId().longValue()==sb.getUserid().longValue()) {
					subuserobj = u;
					break;
				}
			}
			if (subuserobj!=null && subuserobj.getTeamid()!=null && subuserobj.getTeamid().longValue()==tm.getId().longValue()) {
				tro.setLastSummit(sb.getSubmitTime());
				break;
			}
		}
		if (tro.getLastSummit()==null) {
			tro.setLastSummit(new Date());
		}
		teamranklist.add(tro);
		if (tm.getId().longValue()==teamobj.getId().longValue()) {
			thisteam = tro;
		}
		
	}
	
	CompareTeamScore c = new CompareTeamScore();
	Collections.sort(teamranklist,c);
	
	return teamranklist.indexOf(thisteam)+1;

}