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

The following are Jave code examples for showing how to use indexOf() 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: brModelo   File: LogicoCardinalidade.java   Source Code and License Vote up 6 votes
@Override
public ArrayList<InspectorProperty> GenerateProperty() {
    ArrayList<InspectorProperty> res = super.GenerateProperty();

    String[] afetados = new String[]{"setWidth", "setHeight"};

    InspectorProperty tmp = InspectorProperty.FindByProperty(res, "setHeight");
    int p = res.indexOf(tmp) + 1;

    res.add(p, InspectorProperty.PropertyFactorySN("cardinalidade.tamanhoautmatico", "setTamanhoAutmatico", isTamanhoAutmatico()).AddCondicaoForFalse(afetados));
    res.add(p + 1, InspectorProperty.PropertyFactorySN("cardinalidade.movimentacaomanual", "setMovimentacaoManual", isMovimentacaoManual()));

    //res.add(InspectorProperty.PropertyFactorySeparador("mer"));
    ArrayList<String> strCards = new ArrayList<>();
    for (int i = 0; i < 4; i++) {
        strCards.add(CardToString(IntToCard(i)));
    }
    res.add(InspectorProperty.PropertyFactoryMenu("cardinalidade.card", "setCard", CardToInt(), strCards));

    return res;

}
 
Example 2
Project: LaunchEnr   File: Launcher.java   Source Code and License Vote up 6 votes
@Override
public void bindScreens(ArrayList<Long> orderedScreenIds) {
    // Make sure the first screen is always at the start.
    if (orderedScreenIds.indexOf(Workspace.FIRST_SCREEN_ID) != 0) {
        orderedScreenIds.remove(Workspace.FIRST_SCREEN_ID);
        orderedScreenIds.add(0, Workspace.FIRST_SCREEN_ID);
        LauncherModel.updateWorkspaceScreenOrder(this, orderedScreenIds);
    } else if (orderedScreenIds.isEmpty()) {
        // If there are no screens, we need to have an empty screen
        mWorkspace.addExtraEmptyScreen();
    }
    bindAddScreens(orderedScreenIds);

    // Create the custom content page (this call updates mDefaultScreen which calls
    // setCurrentPage() so ensure that all pages are added before calling this).
    if (hasCustomContentToLeft()) {
        mWorkspace.createCustomContentContainer();
        populateCustomContentContainer();
    }

    // After we have added all the screens, if the wallpaper was locked to the default state,
    // then notify to indicate that it can be released and a proper wallpaper offset can be
    // computed before the next layout
    mWorkspace.unlockWallpaperFromDefaultPageOnNextLayout();
}
 
Example 3
Project: cyp2sql   File: WithSQL.java   Source Code and License Vote up 6 votes
private static StringBuilder getOrderByForWith(StringBuilder sWith, ArrayList<String> tokens) {
    int posOfOrder = tokens.indexOf("order");
    sWith.append(" ORDER BY ");

    tokens = new ArrayList<>(tokens.subList(posOfOrder, tokens.size()));

    // deals with clauses such as ORDER BY <alias> ASC/DESC
    if (tokens.size() == 3 || tokens.size() == 4) {
        sWith.append(tokens.get(2)).append(" ").append((tokens.size() == 4) ? tokens.get(3) : "ASC");
        return sWith;
    }

    while (true) {
        String field = tokens.get(4);
        String dir = (tokens.get(5).equals("asc") || tokens.get(5).equals("desc")) ? tokens.get(5) : null;
        sWith.append(field).append(" ").append((dir == null) ? "" : dir);

        int posOfComma = tokens.indexOf(",");
        if (posOfComma == -1) break;
        else tokens = new ArrayList<>(tokens.subList(posOfComma + 1, tokens.size()));
    }
    return sWith;
}
 
Example 4
Project: routineKeen   File: HabitEditActivity.java   Source Code and License Vote up 6 votes
private boolean validationSuccess(){
    ArrayList typeList = HabitListController.getTypeList();
    String editedTitle = titleEditText.getText().toString().trim();
    if(typeList.indexOf((editedTitle))!= -1 && !editedTitle.equals(oldHabitType)){
        Toast.makeText(this, "This habit type already exist.",
                Toast.LENGTH_SHORT).show();
        return false;
    }

    if (titleEditText.getText().toString().isEmpty()) {
        Toast.makeText(this, "Please enter a habit name.",
                Toast.LENGTH_SHORT).show();
        return false;
    }

    if (reasonEditText.getText().toString().isEmpty()) {
        Toast.makeText(this, "Please enter a habit reason.",
                Toast.LENGTH_SHORT).show();
        return false;
    }

    return true;
}
 
Example 5
Project: VennTracker   File: Circles.java   Source Code and License Vote up 6 votes
private static int getLastIndex(ArrayList<LatLng> circlePoints, ArrayList<LatLng> checkAgainst) {
    int endIndex = 0;
    boolean stopChecking = false;
    for (LatLng latLng : circlePoints) {

        if (!PolyUtil.containsLocation(latLng, checkAgainst, isGeoDisc)) {
            endIndex = circlePoints.indexOf(latLng);
            stopChecking = true;
        } else {
            if (stopChecking) {
                break;
            }
        }
    }
    return endIndex;
}
 
Example 6
Project: brModelo   File: EapBarraLigacao.java   Source Code and License Vote up 6 votes
protected Forma calcMaisADireita(ArrayList<EapBarraLigacao> ja, HashMap<Forma, EapBarraLigacao> areas) {
    if (ja.indexOf(this) > -1) {
        return null;
    }
    ja.add(this);
    ArrayList<Forma> lst = getListaDeFormasLigadas();
    Forma ma = capturePrincipal();
    lst.remove(ma);
    for (Forma forma : lst) {
        if (areas.get(forma) != null) {
            Forma tmp = areas.get(forma).calcMaisADireita(ja, areas);
            if (tmp != null) {
                forma = tmp;
            }
        }
        if (forma.getLeftWidth() > ma.getLeftWidth()) {
            ma = forma;
        }
    }
    return ma;
}
 
Example 7
Project: openjdk-jdk10   File: PrintServiceLookupProvider.java   Source Code and License Vote up 6 votes
private int addPrintServiceToList(ArrayList<PrintService> printerList, PrintService ps) {
    int index = printerList.indexOf(ps);
    // Check if PrintService with same name is already in the list.
    if (CUPSPrinter.isCupsRunning() && index != -1) {
        // Bug in Linux: Duplicate entry of a remote printer
        // and treats it as local printer but it is returning wrong
        // information when queried using IPP. Workaround is to remove it.
        // Even CUPS ignores these entries as shown in lpstat or using
        // their web configuration.
        PrinterURI uri = ps.getAttribute(PrinterURI.class);
        if (uri.getURI().getHost().equals("localhost")) {
            IPPPrintService.debug_println(debugPrefix+"duplicate PrintService, ignoring the new local printer: "+ps);
            return index;  // Do not add this.
        }
        PrintService oldPS = printerList.get(index);
        uri = oldPS.getAttribute(PrinterURI.class);
        if (uri.getURI().getHost().equals("localhost")) {
            IPPPrintService.debug_println(debugPrefix+"duplicate PrintService, removing existing local printer: "+oldPS);
            printerList.remove(oldPS);
        } else {
            return index;
        }
    }
    printerList.add(ps);
    return (printerList.size() - 1);
}
 
Example 8
Project: sentimental-analyzer   File: Bayesian.java   Source Code and License Vote up 6 votes
public void getlblClass(ArrayList<Double> lblClass,
		ArrayList<Integer> lblCount, ArrayList<Float> lblProba) {
	int j = 0;
	for (double i : labels) {
		// 如果当前的label不存在于lblClass则加入
		if (!lblClass.contains(i)) {
			lblClass.add(j, i);
			lblCount.add(j++, 1);
		}

		else // 如果label中已经存在,就将其计数加1
		{
			int index = lblClass.indexOf(i);
			int count = lblCount.get(index);
			lblCount.set(index, ++count);
		}
	}

	for (int i = 0; i < lblClass.size(); i++) {
		// System.out.println("值为"+lblClass.get(i)+"的个数有"+lblCount.get(i)+"概率是"+lblCount.get(i)/(float)labels.length);
		lblProba.add(i, lblCount.get(i) / (float) labels.length);
	}
}
 
Example 9
Project: COE1186   File: Mbo.java   Source Code and License Vote up 5 votes
private double calculateSafeBrakingDistance(String trainID) {

		// get the current block
		TrainInfo train = trains.get(trainID);
		MboBlock block = getBlockFromCoordinates(train.getPosition());
		ArrayList<MboBlock> line;
		if (block.getLine().equals("red")) {
			line = redLine;
		} else {
			line = greenLine;
		}

		// get displacement into block. this is positive from the start of the block's coordinate list
		int blockIndex = line.indexOf(block);
		int blockDisplacement = block.getOffset(train.getPosition());
		
		// calculate the safe braking distance by determining how far a meter on each block slows the train down
		double potentialSpeed = train.getSpeed();
		int distance = 0;
		while (potentialSpeed > 0) {
			int[] blockInfo = getBlockAfterMoving(line, blockIndex, blockDisplacement, distance, train.getDirection());
			potentialSpeed = calculateSpeedAfterMeter(potentialSpeed, line.get(blockInfo[0]), blockInfo[1], train.getMass());
			distance += 1;
		}

    	return distance;
    }
 
Example 10
Project: brModelo   File: PreRelacionamento.java   Source Code and License Vote up 5 votes
@Override
public boolean CanLiga(Forma forma, Linha lin) {
    if (forma == null) {
        return true;
    }
    if (super.CanLiga(forma, lin)) {
        if (forma instanceof PreAtributo) {
            return forma.CanLiga(this, lin);
        }
        if (forma instanceof PreEntidade) {
            ArrayList<Forma> lst = getListaDeFormasLigadasNaoExclusiva(PreEntidade.class);
            if (AutoRelacionamento(lst) || getPrincipal() == forma) {
                return false;
            }
            if (isSubComponente()) { //entidade ass.
                if (lst.indexOf(forma) > -1) {
                    return false; //NÃO PODE SER AUTO-REL.
                }
            } else {
                if (lst.indexOf(forma) > -1 && lst.size() > 1) {
                    return false; //já está ligado e possui outra ligação, por isso não pode ser alto-rel.
                }
            }
            return true;
        }
    }
    return false;
}
 
Example 11
Project: TigerIsland   File: GameState.java   Source Code and License Vote up 5 votes
private int coordinateIndex(ArrayList<Coordinate> settlementCoords, Coordinate nukedCoord){
    for(Coordinate c : settlementCoords){
        if(c.getX() == nukedCoord.getX() && c.getY() == nukedCoord.getY()){
            return settlementCoords.indexOf(c);
        }
    }
    return -1;
}
 
Example 12
Project: brModelo   File: Diagrama.java   Source Code and License Vote up 5 votes
/**
 * Com base nos nomes dos objetos traduzidos nos arq. de confg. nomeia os objetos no ato de criação.
 *
 * @param padrao nome dado por mim
 * @return nome traduzido/configurado pelo usuário.
 */
public final String Nomeie(String padrao) {
    String txt = Editor.fromConfiguracao.getValor("diagrama." + padrao + ".nome");
    int res = 1;
    ArrayList<String> txts = new ArrayList<>();
    ListaDeItens.stream().filter((el) -> (el instanceof Forma)).map(el -> (Forma) el).forEach(el -> el.EscrevaTexto(txts));

    while (txts.indexOf(txt + "_" + res) != -1) {
        res++;
    }
    return txt + "_" + res;
}
 
Example 13
Project: routineKeen   File: NewHabitActivity.java   Source Code and License Vote up 5 votes
private boolean validationSuccess() {
        ArrayList typeList = HabitListController.getTypeList();
        if(typeList.indexOf(hTitle.getText().toString().trim())!= -1 ){
            Toast.makeText(this, "This habit type already exist.",
                    Toast.LENGTH_SHORT).show();
            return false;
        }

        if (hTitle.getText().toString().isEmpty()) {
            Toast.makeText(this, "Please enter a habit name.",
                    Toast.LENGTH_SHORT).show();
            return false;
        }

        if (hReason.getText().toString().isEmpty()) {
            Toast.makeText(this, "Please enter a habit reason.",
                    Toast.LENGTH_SHORT).show();
            return false;
        }

        if (hDate.getText().toString().trim().length() == 0) {
            Toast.makeText(this, "Please enter a start date.",
                    Toast.LENGTH_SHORT).show();
            return false;

        }// else {
//            Date hDateInput = DateHelpers.formatStringToDate(
//                    hDate.getText().toString(), "MM/dd/yyyy");
//            Date currentDate = DateHelpers.removeTime(new Date());
//            if (hDateInput.before(currentDate)) {
//                Toast.makeText(this, "Date is in the past, try again.",
//                        Toast.LENGTH_SHORT).show();
//                return false;
//            }
//        }

        return true;
    }
 
Example 14
Project: letv   File: RequestParams.java   Source Code and License Vote up 5 votes
public String toString() {
    StringBuilder result = new StringBuilder();
    for (Entry<String, String> entry : this.urlParams.entrySet()) {
        if (result.length() > 0) {
            result.append("&");
        }
        result.append((String) entry.getKey());
        result.append(SearchCriteria.EQ);
        result.append((String) entry.getValue());
    }
    for (Entry<String, FileWrapper> entry2 : this.fileParams.entrySet()) {
        if (result.length() > 0) {
            result.append("&");
        }
        result.append((String) entry2.getKey());
        result.append(SearchCriteria.EQ);
        result.append("FILE");
    }
    for (Entry<String, ArrayList<String>> entry3 : this.urlParamsWithArray.entrySet()) {
        if (result.length() > 0) {
            result.append("&");
        }
        ArrayList<String> values = (ArrayList) entry3.getValue();
        Iterator it = values.iterator();
        while (it.hasNext()) {
            String value = (String) it.next();
            if (values.indexOf(value) != 0) {
                result.append("&");
            }
            result.append((String) entry3.getKey());
            result.append(SearchCriteria.EQ);
            result.append(value);
        }
    }
    return result.toString();
}
 
Example 15
Project: openjdk-jdk10   File: IntegerSwitchNode.java   Source Code and License Vote up 5 votes
private static int addNewSuccessor(AbstractBeginNode newSuccessor, ArrayList<AbstractBeginNode> newSuccessors) {
    int index = newSuccessors.indexOf(newSuccessor);
    if (index == -1) {
        index = newSuccessors.size();
        newSuccessors.add(newSuccessor);
    }
    return index;
}
 
Example 16
Project: ramus   File: NewProjectDialog.java   Source Code and License Vote up 5 votes
private void add(final ArrayList<String> list, final String value) {
    final String c = value.trim();
    if (!"".equals(c)) {
        if (list.indexOf(c) < 0)
            list.add(c);
    }

}
 
Example 17
Project: openjdk-jdk10   File: TypeSwitchNode.java   Source Code and License Vote up 4 votes
@Override
public void simplify(SimplifierTool tool) {
    if (value() instanceof ConstantNode) {
        Constant constant = value().asConstant();

        int survivingEdge = keySuccessorIndex(keyCount());
        for (int i = 0; i < keyCount(); i++) {
            Constant typeHub = keyAt(i);
            Boolean equal = tool.getConstantReflection().constantEquals(constant, typeHub);
            if (equal == null) {
                /* We don't know if this key is a match or not, so we cannot simplify. */
                return;
            } else if (equal.booleanValue()) {
                survivingEdge = keySuccessorIndex(i);
            }
        }
        killOtherSuccessors(tool, survivingEdge);
    }
    if (value() instanceof LoadHubNode && ((LoadHubNode) value()).getValue().stamp() instanceof ObjectStamp) {
        ObjectStamp objectStamp = (ObjectStamp) ((LoadHubNode) value()).getValue().stamp();
        if (objectStamp.type() != null) {
            int validKeys = 0;
            for (int i = 0; i < keyCount(); i++) {
                if (objectStamp.type().isAssignableFrom(keys[i])) {
                    validKeys++;
                }
            }
            if (validKeys == 0) {
                tool.addToWorkList(defaultSuccessor());
                graph().removeSplitPropagate(this, defaultSuccessor());
            } else if (validKeys != keys.length) {
                ArrayList<AbstractBeginNode> newSuccessors = new ArrayList<>(blockSuccessorCount());
                ResolvedJavaType[] newKeys = new ResolvedJavaType[validKeys];
                int[] newKeySuccessors = new int[validKeys + 1];
                double[] newKeyProbabilities = new double[validKeys + 1];
                double totalProbability = 0;
                int current = 0;
                for (int i = 0; i < keyCount() + 1; i++) {
                    if (i == keyCount() || objectStamp.type().isAssignableFrom(keys[i])) {
                        int index = newSuccessors.indexOf(keySuccessor(i));
                        if (index == -1) {
                            index = newSuccessors.size();
                            newSuccessors.add(keySuccessor(i));
                        }
                        newKeySuccessors[current] = index;
                        if (i < keyCount()) {
                            newKeys[current] = keys[i];
                        }
                        newKeyProbabilities[current] = keyProbability(i);
                        totalProbability += keyProbability(i);
                        current++;
                    }
                }
                if (totalProbability > 0) {
                    for (int i = 0; i < current; i++) {
                        newKeyProbabilities[i] /= totalProbability;
                    }
                } else {
                    for (int i = 0; i < current; i++) {
                        newKeyProbabilities[i] = 1.0 / current;
                    }
                }

                for (int i = 0; i < blockSuccessorCount(); i++) {
                    AbstractBeginNode successor = blockSuccessor(i);
                    if (!newSuccessors.contains(successor)) {
                        tool.deleteBranch(successor);
                    }
                    setBlockSuccessor(i, null);
                }

                AbstractBeginNode[] successorsArray = newSuccessors.toArray(new AbstractBeginNode[newSuccessors.size()]);
                TypeSwitchNode newSwitch = graph().add(new TypeSwitchNode(value(), successorsArray, newKeys, newKeyProbabilities, newKeySuccessors, tool.getConstantReflection()));
                ((FixedWithNextNode) predecessor()).setNext(newSwitch);
                GraphUtil.killWithUnusedFloatingInputs(this);
            }
        }
    }
}
 
Example 18
Project: AP-Computer-Science-Labs   File: Lab1.java   Source Code and License Vote up 4 votes
public static ArrayList<Double> remove(ArrayList<Double> array, double x){
	while(array.indexOf(x)!=-1){ // Loop until x isn't found in list
		array.remove(array.indexOf(x)); // Remove first value of x
	}
	return array;
}
 
Example 19
Project: modern.core.java.repo   File: Courses.java   Source Code and License Vote up 4 votes
public void getSpecificCourseCost() {
   ArrayList<Double> CourseCost = this.selectCourseCost();
   int costIndex = CourseCost.indexOf(750D);
   System.out.println(costIndex);
}
 
Example 20
Project: SimpleUILauncher   File: LauncherDbUtils.java   Source Code and License Vote up 4 votes
/**
 * Makes the first screen as screen 0 (if screen 0 already exists,
 * renames it to some other number).
 * If the first row of screen 0 is non empty, runs a 'lossy' GridMigrationTask to clear
 * the first row. The items in the first screen are moved and resized but the carry-forward
 * items are simply deleted.
 */
public static boolean prepareScreenZeroToHostQsb(SQLiteDatabase db) {
    db.beginTransaction();
    try {
        // Get the existing screens
        ArrayList<Long> screenIds = getScreenIdsFromCursor(db.query(WorkspaceScreens.TABLE_NAME,
                null, null, null, null, null, WorkspaceScreens.SCREEN_RANK));

        if (screenIds.isEmpty()) {
            // No update needed
            return true;
        }
        if (screenIds.get(0) != 0) {
            // First screen is not 0, we need to rename screens
            if (screenIds.indexOf(0L) > -1) {
                // There is already a screen 0. First rename it to a differen screen.
                long newScreenId = 1;
                while (screenIds.indexOf(newScreenId) > -1) newScreenId++;
                renameScreen(db, 0, newScreenId);
            }

            // Rename the first screen to 0.
            renameScreen(db, screenIds.get(0), 0);
        }

        // Check if the first row is empty
        try (Cursor c = db.query(Favorites.TABLE_NAME, null,
                "container = -100 and screen = 0 and cellY = 0", null, null, null, null)) {
            if (c.getCount() == 0) {
                // First row is empty, no need to migrate.
                return true;
            }
        }

        LauncherAppState app = LauncherAppState.getInstance();
        new LossyScreenMigrationTask(app.getContext(), app.getInvariantDeviceProfile(), db)
                .migrateScreen0();
        db.setTransactionSuccessful();
        return true;
    } catch (Exception e) {
        Log.e(TAG, "Failed to update workspace size", e);
        return false;
    } finally {
        db.endTransaction();
    }
}