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

The following examples show how to use java.util.ArrayList#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: Runner.java    From ramus with GNU General Public License v3.0 6 votes vote down vote up
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());
    }
}
 
Example 2
Source File: AIROptionsParserTests.java    From vscode-as3mxml with Apache License 2.0 6 votes vote down vote up
@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));
}
 
Example 3
Source File: ServerController.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
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);
                }
            }
        }
    }
}
 
Example 4
Source File: TreeNode.java    From KEEL with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 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;
}
 
Example 5
Source File: TypeHierarchy.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * @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);
	}
}
 
Example 6
Source File: GraphCalculator.java    From charts with Apache License 2.0 6 votes vote down vote up
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;
    }
}
 
Example 7
Source File: FocusFinder.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 8
Source File: SerializedRecord.java    From hadoop-gpu with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 9
Source File: SuggestionsBranchAndBound.java    From cpsolver with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * 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;
}
 
Example 10
Source File: AIROptionsParserTests.java    From vscode-as3mxml with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 11
Source File: AIROptionsParserTests.java    From vscode-as3mxml with Apache License 2.0 5 votes vote down vote up
@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));
}
 
Example 12
Source File: TreeNode.java    From KEEL with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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;
}
 
Example 13
Source File: Matrix.java    From matrix-android-console with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example 14
Source File: DynamicAnimation.java    From CircularReveal with MIT License 5 votes vote down vote up
/**
 * 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);
  }
}
 
Example 15
Source File: AIROptionsParserTests.java    From vscode-as3mxml with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 16
Source File: AlbumActivity.java    From Album with Apache License 2.0 5 votes vote down vote up
@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();
}
 
Example 17
Source File: IO.java    From PocketMaps with MIT License 5 votes vote down vote up
@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);
}
 
Example 18
Source File: ImageClickableSpan.java    From android-discourse with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 19
Source File: CSharpASTNodeWriter.java    From juniversal with MIT License 5 votes vote down vote up
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));
}
 
Example 20
Source File: CommonUtils.java    From PhrackCTF-Platform-Team with Apache License 2.0 4 votes vote down vote up
@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;

}