Example usage for java.util List indexOf

List of usage examples for java.util List indexOf

Introduction

In this page you can find the example usage for java.util List indexOf.

Prototype

int indexOf(Object o);

Source Link

Document

Returns the index of the first occurrence of the specified element in this list, or -1 if this list does not contain the element.

Usage

From source file:ListSet.java

/**
 * Construct a <tt>ListSet</tt>.
 * //from  w  ww . java 2  s . c  o m
 * @param list
 *          The <tt>List</tt> which will be used for element storage.
 * 
 * @throws IllegalArgumentException
 *           List is <tt>null</tt> or contains duplicate entries.
 */
public ListSet(final List list) {
    if (list == null)
        throw new RuntimeException("list");

    // make sure there are no duplicates
    int size = list.size();
    for (int i = 0; i < size; i++) {
        Object obj = list.get(i);
        if (list.indexOf(obj) != list.lastIndexOf(obj)) {
            throw new IllegalArgumentException("list contains duplicate entries");
        }
    }

    this.list = list;
}

From source file:com.aw.swing.mvp.validation.support.AWDefaultRulesSource.java

public void validateRUC(Object propertyValidator) {
    BindingComponent inputComponent = ((PropertyValidator) propertyValidator).getBindingComponent();
    String ruc = (String) inputComponent.getValue();
    if (ruc == null || ruc.equals(""))
        return; // nothing to validate
    ruc = ruc.trim();//  w  w w. ja  v a2  s.c o  m

    // longitud
    if (ruc.length() != 11) {
        logger.info("RUC[" + ruc + "] no tiene 11 digitos");
        throw new AWValidationException("RUC[" + ruc + "] no tiene 11 digitos");
    }

    // digitos
    Character noDigito = findNonDigit(ruc);
    if (noDigito != null) {
        logger.info("RUC[" + ruc + "] tiene caracter no valido:'" + noDigito + "'");
        throw new AWValidationException("RUC[" + ruc + "] tiene caracter no valido:'" + noDigito + "'");
    }

    String rucPrefix = ruc.substring(0, 2);
    List rucSerieList = Arrays.asList(new String[] { "10", "15", "20", "17" });
    if (rucSerieList.indexOf(rucPrefix) < 0) {
        // ruc NO pertenece a la serie
    }
    int suma = 0, x = 6;
    for (int i = 0; i < 10; i++) {
        if (i == 4)
            x = 8;
        int digito = ruc.charAt(i) - '0';
        x--;

        //Nota esto hace lo mismo, pero esta asi en el SP, confirmar si hay error
        if (i == 0)
            suma += digito * x;
        else
            suma += digito * x;
    }
    int resto = suma % 11;
    resto = 11 - resto;
    if (resto >= 10)
        resto -= 10;

    int ultDigito = ruc.charAt(10) - '0';
    boolean rucOk = resto == ultDigito;
    if (!rucOk) {
        logger.info("RUC[" + ruc + "] digito de verificacion incorrecto calculado:'" + resto + "'");
        throw new AWValidationException(
                "RUC[" + ruc + "] digito de verificacion incorrecto calculado:'" + resto + "'");
    }
}

From source file:ch.oakmountain.tpa.solver.MacroscopicTopology.java

/**
 * Get the possible subroutes from {@code from} to {@code to} contained in routes {@code alongFrom} to {@code alongTo}.
 *
 * @param from/*www .jav  a  2 s .c o m*/
 * @param alongFrom
 * @param alongTo
 * @return
 */
public List<SystemNode> getSuccessors(SystemNode from, SystemNode alongFrom, SystemNode alongTo) {
    List<List<SystemNode>> alongRoutes = getRoutes(alongFrom, alongTo);
    List<SystemNode> successors = new LinkedList<>();
    for (List<SystemNode> route : alongRoutes) {
        int fromIndex = route.indexOf(from);
        if (fromIndex >= 0 && route.size() > fromIndex + 1) {
            SystemNode successor = route.get(fromIndex + 1);
            if (!successors.contains(successor)) {
                successors.add(successor);
            }
        }
    }
    return successors;
}

From source file:com.google.gdt.eclipse.designer.model.widgets.cell.AbstractCellTableInfo.java

@Override
protected void refresh_fetch() throws Exception {
    super.refresh_fetch();
    // calculate columns bounds
    {/*from  w ww.j a  va  2  s  .  com*/
        List<Rectangle> columnBounds = getColumnBoundsByBody();
        List<?> columnObjects = getColumnObjects();
        List<ColumnInfo> columns = getColumns();
        for (ColumnInfo column : columns) {
            int index = columnObjects.indexOf(column.getObject());
            column.setModelBounds(columnBounds.get(index));
        }
    }
}

From source file:fr.inria.atlanmod.neoemf.data.berkeleydb.store.DirectWriteBerkeleyDBListsStore.java

@Override
public int indexOf(InternalEObject object, EStructuralFeature feature, Object value) {
    int returnValue;
    PersistentEObject persistentEObject = PersistentEObject.from(object);
    List<Object> list = manyValueFrom(getFromMap(persistentEObject, feature));
    if (isNull(list)) {
        returnValue = NO_INDEX;/* w ww  .j  a va  2 s .  co  m*/
    } else if (feature instanceof EAttribute) {
        returnValue = list.indexOf(serializeToProperty((EAttribute) feature, value));
    } else {
        PersistentEObject childEObject = PersistentEObject.from(value);
        returnValue = list.indexOf(childEObject.id());
    }
    return returnValue;
}

From source file:hydrograph.server.execution.tracking.client.main.HydrographMain.java

/**
 * Gets the job id./*w  ww . j  a  v a2  s .  c om*/
 *
 * @param argumentList
 *            the argument list
 * @return the job id
 */
private String getJobId(List<String> argumentList) {
    if (argumentList.contains(Constants.JOBID_KEY)) {
        return argumentList.get(argumentList.indexOf(Constants.JOBID_KEY) + 1);
    }
    return null;
}

From source file:org.piwik.sdk.TestDispatcher.java

@Test
public void testSessionStartRaceCondition() throws Exception {
    for (int i = 0; i < 10; i++) {
        Log.d("RaceConditionTest", (10 - i) + " race-condition tests to go.");
        getPiwik().setDryRun(true);//from  w w w .  j  av a 2s  . c o  m
        final Tracker tracker = createTracker();
        tracker.setDispatchInterval(0);
        final int threadCount = 10;
        final int queryCount = 3;
        final List<String> createdEvents = Collections.synchronizedList(new ArrayList<String>());
        launchTestThreads(tracker, threadCount, queryCount, createdEvents);
        Thread.sleep(500);
        checkForMIAs(threadCount * queryCount, createdEvents, tracker.getDispatcher().getDryRunOutput());
        List<String> output = getFlattenedQueries(tracker.getDispatcher().getDryRunOutput());
        for (String out : output) {
            if (output.indexOf(out) == 0) {
                assertTrue(out.contains("lang"));
                assertTrue(out.contains("_idts"));
                assertTrue(out.contains("new_visit"));
            } else {
                assertFalse(out.contains("lang"));
                assertFalse(out.contains("_idts"));
                assertFalse(out.contains("new_visit"));
            }
        }
    }
}

From source file:com.thoughtworks.go.server.service.dd.DependencyFanInNode.java

private RevisionAlteration alterRevision(StageIdFaninScmMaterialPair revisionToSet, FanInGraphContext context) {
    if (currentRevision == revisionToSet.stageIdentifier) {
        return RevisionAlteration.SAME_AS_CURRENT_REVISION;
    }//from  w  ww .  j a  v a2s. c  o  m
    if (!stageIdentifierScmMaterial.get(currentRevision).contains(revisionToSet.faninScmMaterial)) {
        return RevisionAlteration.NOT_APPLICABLE;
    }
    List<StageIdentifier> stageIdentifiers = new ArrayList<>(stageIdentifierScmMaterial.keySet());
    int currentRevIndex = stageIdentifiers.indexOf(currentRevision);
    for (int i = currentRevIndex; i < stageIdentifiers.size(); i++) {
        final StageIdentifier key = stageIdentifiers.get(i);
        final List<FaninScmMaterial> materials = new ArrayList<>(stageIdentifierScmMaterial.get(key));
        final int index = materials.indexOf(revisionToSet.faninScmMaterial);
        if (index == -1) {
            return ALL_OPTIONS_EXHAUSTED;
        }
        final FaninScmMaterial faninScmMaterial = materials.get(index);
        if (faninScmMaterial.revision.equals(revisionToSet.faninScmMaterial.revision)) {
            currentRevision = key;
            return ALTERED_TO_CORRECT_REVISION;
        }
        if (faninScmMaterial.revision.lessThan(revisionToSet.faninScmMaterial.revision)) {
            currentRevision = key;
            return ALTERED_TO_CORRECT_REVISION;
        }
    }

    if (!hasMoreInstances()) {
        return ALL_OPTIONS_EXHAUSTED;
    }
    return NEED_MORE_REVISIONS;
}

From source file:architecture.ee.web.community.tag.DefaultTagManager.java

@Override
public void addTag(ContentTag tag, int objectType, long objectId) throws UnAuthorizedException {
    if (objectType < 0 || objectId < 0L)
        throw new IllegalStateException();
    synchronized (getLock(objectType, objectId)) {
        List<Long> tags = getTagIds(objectType, objectId);
        int index = tags.indexOf(Long.valueOf(tag.getTagId()));
        if (index < 0) {
            tags.add(Long.valueOf(tag.getTagId()));
            tagContentCache.put(new Element(getCacheKey(objectType, objectId), tags));
        }//from w  w  w. j a  v a  2s . c  o m
    }
    tagDao.addTag(tag.getTagId(), objectType, objectId);
    // event.. fire

}

From source file:com.evolveum.midpoint.web.component.assignment.ACAttributeValuePanel.java

private boolean isAddVisible() {
    ACValueConstructionDto dto = getModel().getObject();
    ACAttributeDto attributeDto = dto.getAttribute();
    PrismPropertyDefinition def = attributeDto.getDefinition();

    List<ACValueConstructionDto> values = attributeDto.getValues();
    if (def.getMaxOccurs() != -1 && values.size() >= def.getMaxOccurs()) {
        return false;
    }/*from  w ww .j  a  va2 s.  com*/

    //we want to show add on last item only
    if (values.indexOf(dto) + 1 != values.size()) {
        return false;
    }

    return true;
}