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

The following are Jave code examples for showing how to use indexOf() of the java.util.List class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: incubator-netbeans   File: LayeredGraph.java   View Source Code Vote up 6 votes
/**
 *
 *
 */
public boolean[][] computeAdjacencyMatrix(int upperLayerIndex) {
    List<Vertex> upperLayer = layers.get(upperLayerIndex);
    List<Vertex> lowerLayer = layers.get(upperLayerIndex+1);
    int upperLayerSize = upperLayer.size();
    int lowerLayerSize = lowerLayer.size();
    
    boolean[][] matrix = new boolean[upperLayerSize][lowerLayerSize];
    
    for (int j = 0; j < upperLayerSize; j++) {
        Vertex v = upperLayer.get(j);
        if (v != null) {
            Collection<Vertex> vertices = v.getLowerNeighbors();
            for (Vertex nv : vertices) {
                int k = lowerLayer.indexOf(nv);
                
                if (k > -1) {
                    matrix[j][k] = true;
                    //System.out.println(j + "," + k + " is set");
                }
            }
        }
    }
    
    return matrix;
}
 
Example 2
Project: Neuronizer   File: DisplayPreviewPresenterImpl.java   View Source Code Vote up 6 votes
@Override
public void syncPreviews(List<PreviewViewModel> previews) {
    List<PreviewViewModel> reversedPreviews = Lists.reverse(Optional
                    .fromNullable(previews)
                    .or(new ArrayList<PreviewViewModel>(0)));

    for (PreviewViewModel vm : reversedPreviews) {
        EditTodoListInteractor interactor = new EditTodoListInteractorImpl(
                mExecutor,
                mMainThread,
                this,
                repository,
                vm.getUuid(),
                vm.getTitle(),
                reversedPreviews.indexOf(vm)
        );
        interactor.execute();
    }
}
 
Example 3
Project: Warzone   File: TDMModule.java   View Source Code Vote up 6 votes
@EventHandler
public void onScoreboardInit(ScoreboardInitEvent event) {
    List<MatchTeam> teams = TGM.get().getModule(TeamManagerModule.class).getTeams();

    SimpleScoreboard simpleScoreboard = event.getSimpleScoreboard();

    int i = 0;
    for (MatchTeam matchTeam : teams) {
        if (matchTeam.isSpectator()) continue;
        simpleScoreboard.add(matchTeam.getColor() + getTeamScoreLine(matchTeam), i);
        teamScoreboardLines.put(matchTeam, i++);
        simpleScoreboard.add(matchTeam.getColor() + matchTeam.getAlias(), i++);
        if (teams.indexOf(matchTeam) < teams.size() - 1) {
            simpleScoreboard.add(matchTeam.getColor() + " ", i++);
        }
    }
}
 
Example 4
Project: FreeCol   File: UnitWas.java   View Source Code Vote up 6 votes
/**
 * {@inheritDoc}
 */
@Override
public int compareTo(UnitWas uw) {
    // Order by decreasing capacity of the location the unit is to
    // be moved to, so that if we traverse a sorted list of
    // UnitWas we minimize the chance of a unit being moved to a
    // full location.
    //
    // Unfortunately this also tends to move units that need
    // equipment first, leading to failures to rearm, so it is
    // best to make two passes anyway.  See revertAll().  However
    // we can still try our best by using the amount of equipment
    // the unit needs as a secondary criterion (favouring the
    // least equipped).
    List<Role> roles = this.unit.getAvailableRolesList(null);
    int cmp = ((UnitLocation)uw.loc).getUnitCapacity()
        - ((UnitLocation)this.loc).getUnitCapacity();
    if (cmp == 0) {
        cmp = roles.indexOf(this.role) - roles.indexOf(uw.role);
    }
    return cmp;
}
 
Example 5
Project: convertigo-engine   File: UIComponent.java   View Source Code Vote up 6 votes
private void insertOrderedComponent(UIComponent component, Long after) {
	List<Long> ordered = orderedComponents.get(0);
	int size = ordered.size();
	
	if (ordered.contains(component.priority))
		return;
	
	if (after == null) {
		after = new Long(0);
		if (size>0)
			after = ordered.get(ordered.size()-1);
	}
	
	int order = ordered.indexOf(after);
	ordered.add(order+1, component.priority);
	hasChanged = true;
}
 
Example 6
Project: stvs   File: AdvancedTextFieldTableCell.java   View Source Code Vote up 6 votes
/**
 * getNextColumn: get the next (previous) Column relative to this TableCell.
 *
 * @param forward should it return the next or previous Column?
 * @return next (previous) TableColumn or null if none exists in this row
 */
private TableColumn<S, ?> getNextColumn(boolean forward) {
  List<TableColumn<S, ?>> columns = new ArrayList<>();
  columns.addAll(getTableView().getColumns());

  // There is no other column that supports editing.
  if (columns.size() < 2) {
    return null;
  }
  int currentIndex = columns.indexOf(getTableColumn());
  int nextIndex = currentIndex;
  if (forward) {
    nextIndex++;
    if (nextIndex > columns.size() - 1) {
      return null;
    }
  } else {
    nextIndex--;
    //assumes, that the first column is not editable
    if (nextIndex < 1) {
      return null;
    }
  }
  return columns.get(nextIndex);
}
 
Example 7
Project: ukubuka-core   File: UkubukaTransformer.java   View Source Code Vote up 6 votes
/**
 * Perform Delete Operation
 * 
 * @param columnNames
 * @param source
 * @param rowData
 */
private void doDelete(List<String> fileHeader, List<FileRecord> fileRecords,
        final String source) {
    LOGGER.info("Performing Delete Operation - Source: {} | Header: {}",
            source, fileHeader);

    /* Get Index */
    int index = fileHeader.indexOf(source);

    /* Remove Header Entry */
    fileHeader.remove(index);

    /* Remove Records */
    for (final FileRecord fileRecord : fileRecords) {
        fileRecord.getData().remove(index);
    }
}
 
Example 8
Project: ramus   File: Util.java   View Source Code Vote up 5 votes
public void addAttributes(List<Attribute> sources, Eval eval,
                          List<Attribute> attributes) {
    String[] values = eval.getValues();
    for (Attribute attribute : attributes) {
        if (sources.indexOf(attribute) < 0) {
            for (String value : values) {
                if (getAttributeEId(attribute.getId()).equals(value)) {
                    sources.add(attribute);
                    break;
                }
            }
        }
    }
}
 
Example 9
Project: alfresco-core   File: CollectionUtils.java   View Source Code Vote up 5 votes
/**
 * This method does the same as {@link #moveLeft(int, Object, List)} but it moves the specified element
 * to the right instead of the left.
 */
public static <T> List<T> moveRight(int offset, T element, List<T> list)
{
    final int elementIndex = list.indexOf(element);
    
    if (elementIndex == -1) { throw new NoSuchElementException("Element not found in provided list."); }
    
    if (offset == 0)
    {
        return list;
    }
    else
    {
        int newElementIndex = elementIndex + offset;
        
        // Ensure that the element will not move off the end of the list.
        if      (newElementIndex >= list.size()) { newElementIndex = list.size() - 1; }
        else if (newElementIndex < 0)            { newElementIndex = 0; }
        
        List<T> result = new ArrayList<>(list);
        result.remove(element);
        
        result.add(newElementIndex, element);
        
        return result;
    }
}
 
Example 10
Project: ureport   File: PdfProducer.java   View Source Code Vote up 5 votes
private int buildCellHeight(Cell cell,List<Row> rows){
	int height=cell.getRow().getRealHeight();
	int rowSpan=cell.getPageRowSpan();
	if(rowSpan>0){
		int pos=rows.indexOf(cell.getRow());
		int start=pos+1,end=start+rowSpan-1;
		for(int i=start;i<end;i++){
			height+=rows.get(i).getRealHeight();
		}
	}
	return height;
}
 
Example 11
Project: convertigo-engine   File: StepWithExpressions.java   View Source Code Vote up 5 votes
/**
 * Get representation of order for quick sort of a given database object.
 */
@Override
public Object getOrder(Object object) throws EngineException	{
    if (object instanceof Step) {
    	List<Long> ordered = orderedSteps.get(0);
    	long time = ((Step)object).priority;
    	if (ordered.contains(time))
    		return (long)ordered.indexOf(time);
    	else throw new EngineException("Corrupted step for StepWithExpressions \""+ getName() +"\". Step \""+ ((Step)object).getName() +"\" with priority \""+ time +"\" isn't referenced anymore.");
    } else return super.getOrder(object);
}
 
Example 12
Project: neoscada   File: ToolBarNavigator.java   View Source Code Vote up 5 votes
public int calculateToolbarIndex ( final ViewInstanceDescriptor descriptor )
{
    if ( !isMain ( descriptor ) )
    {
        logger.debug ( "Has parent: {}", descriptor );
        return -1;
    }

    final List<ViewInstanceDescriptor> data = new ArrayList<ViewInstanceDescriptor> ( this.visibleDescriptors );

    // remove all views with a parent
    final Iterator<ViewInstanceDescriptor> i = data.iterator ();
    while ( i.hasNext () )
    {
        if ( !isMain ( i.next () ) )
        {
            logger.debug ( "{} has parent, remove: ", descriptor );
            i.remove ();
        }
    }

    data.add ( descriptor );
    Collections.sort ( data, ViewInstanceDescriptor.DESCRIPTOR_ORDER_COMPARATOR );

    logger.debug ( "Sort order: {}", data );

    final int result = data.indexOf ( descriptor );
    logger.debug ( "Index is: {}", result );
    return result;
}
 
Example 13
Project: convertigo-engine   File: TestCase.java   View Source Code Vote up 5 votes
/**
    * Get representation of order for quick sort of a given database object.
    */
@Override
   public Object getOrder(Object object) throws EngineException	{
       if (object instanceof Variable) {
       	List<Long> ordered = orderedVariables.get(0);
       	long time = ((Variable)object).priority;
       	if (ordered.contains(time))
       		return (long)ordered.indexOf(time);
       	else throw new EngineException("Corrupted variable for test case \""+ getName() +"\". Variable \""+ ((Variable)object).getName() +"\" with priority \""+ time +"\" isn't referenced anymore.");
       }
       else return super.getOrder(object);
   }
 
Example 14
Project: rocketmq-rocketmq-all-4.1.0-incubating   File: AllocateMessageQueueByMachineRoom.java   View Source Code Vote up 5 votes
@Override
public List<MessageQueue> allocate(String consumerGroup, String currentCID, List<MessageQueue> mqAll,
    List<String> cidAll) {
    List<MessageQueue> result = new ArrayList<MessageQueue>();
    int currentIndex = cidAll.indexOf(currentCID);
    if (currentIndex < 0) {
        return result;
    }
    List<MessageQueue> premqAll = new ArrayList<MessageQueue>();
    for (MessageQueue mq : mqAll) {
        String[] temp = mq.getBrokerName().split("@");
        if (temp.length == 2 && consumeridcs.contains(temp[0])) {
            premqAll.add(mq);
        }
    }

    int mod = premqAll.size() / cidAll.size();
    int rem = premqAll.size() % cidAll.size();
    int startIndex = mod * currentIndex;
    int endIndex = startIndex + mod;
    for (int i = startIndex; i < endIndex; i++) {
        result.add(mqAll.get(i));
    }
    if (rem > currentIndex) {
        result.add(premqAll.get(currentIndex + mod * cidAll.size()));
    }
    return result;
}
 
Example 15
Project: Backmemed   File: ResourcePackListEntry.java   View Source Code Vote up 4 votes
protected boolean canMoveDown()
{
    List<ResourcePackListEntry> list = this.resourcePacksGUI.getListContaining(this);
    int i = list.indexOf(this);
    return i >= 0 && i < list.size() - 1 && ((ResourcePackListEntry)list.get(i + 1)).showHoverOverlay();
}
 
Example 16
Project: Mzip-Android   File: RarVM.java   View Source Code Vote up 4 votes
private void optimize(VMPreparedProgram prg) {
    List<VMPreparedCommand> commands = prg.getCmd();

    for (VMPreparedCommand cmd : commands) {
        switch (cmd.getOpCode()) {
            case VM_MOV:
                cmd.setOpCode(cmd.isByteMode() ? VMCommands.VM_MOVB
                        : VMCommands.VM_MOVD);
                continue;
            case VM_CMP:
                cmd.setOpCode(cmd.isByteMode() ? VMCommands.VM_CMPB
                        : VMCommands.VM_CMPD);
                continue;
        }
        if ((VMCmdFlags.VM_CmdFlags[cmd.getOpCode().getVMCommand()] & VMCmdFlags.VMCF_CHFLAGS) == 0) {
            continue;
        }
        boolean flagsRequired = false;

        for (int i = commands.indexOf(cmd) + 1; i < commands.size(); i++) {
            int flags = VMCmdFlags.VM_CmdFlags[commands.get(i).getOpCode()
                    .getVMCommand()];
            if ((flags & (VMCmdFlags.VMCF_JUMP | VMCmdFlags.VMCF_PROC | VMCmdFlags.VMCF_USEFLAGS)) != 0) {
                flagsRequired = true;
                break;
            }
            if ((flags & VMCmdFlags.VMCF_CHFLAGS) != 0) {
                break;
            }
        }
        if (flagsRequired) {
            continue;
        }
        switch (cmd.getOpCode()) {
            case VM_ADD:
                cmd.setOpCode(cmd.isByteMode() ? VMCommands.VM_ADDB
                        : VMCommands.VM_ADDD);
                continue;
            case VM_SUB:
                cmd.setOpCode(cmd.isByteMode() ? VMCommands.VM_SUBB
                        : VMCommands.VM_SUBD);
                continue;
            case VM_INC:
                cmd.setOpCode(cmd.isByteMode() ? VMCommands.VM_INCB
                        : VMCommands.VM_INCD);
                continue;
            case VM_DEC:
                cmd.setOpCode(cmd.isByteMode() ? VMCommands.VM_DECB
                        : VMCommands.VM_DECD);
                continue;
            case VM_NEG:
                cmd.setOpCode(cmd.isByteMode() ? VMCommands.VM_NEGB
                        : VMCommands.VM_NEGD);
                continue;
        }
    }

}
 
Example 17
Project: incubator-netbeans   File: IssuePanel.java   View Source Code Vote up 4 votes
private void initStatusCombo(String currentStatus) {
    // Init statusCombo - allowed transitions (heuristics):
    // Open -> Open-Unconfirmed-Reopened+Resolved
    // Resolved -> Reopened+Close
    // Close-Resolved -> Reopened+Resolved+(Close with higher index)
    BugzillaRepository repository = issue.getRepository();
    BugzillaConfiguration bc = repository.getConfiguration();
    if(bc == null || !bc.isValid()) {
        // XXX nice error msg?
        return;
    }
    List<String> allStatuses = bc.getStatusValues();
    List<String> openStatuses = bc.getOpenStatusValues();
    List<String> statuses = new LinkedList<>();
    boolean oldRepository = (issue.getRepository().getConfiguration().getInstalledVersion().compareMajorMinorOnly(BugzillaVersion.BUGZILLA_3_2) < 0);
    String nev = "NEW"; // NOI18N
    String unconfirmed = "UNCONFIRMED"; // NOI18N
    String reopened = "REOPENED"; // NOI18N
    String resolved = "RESOLVED"; // NOI18N
    if (currentStatus != null) {
        currentStatus = currentStatus.trim();
    }
    String status = issue.getLastSeenFieldValue(IssueField.STATUS);
    if (status.isEmpty()) {
        status = currentStatus;
    }
    if (openStatuses.contains(status)) {
        statuses.addAll(openStatuses);
        if (!unconfirmed.equals(status)) {
            statuses.remove(unconfirmed);
        }
        if (!reopened.equals(status)) {
            statuses.remove(reopened);
        }
        if (oldRepository && !nev.equals(status)) {
            statuses.remove(nev);
        }
        statuses.add(resolved);
    } else {
        if (allStatuses.contains(reopened)) {
            statuses.add(reopened);
        } else {
            // Pure guess
            statuses.addAll(openStatuses);
            statuses.remove(unconfirmed);
            if (oldRepository) {
                statuses.remove(nev);
            }
        }
        if (resolved.equals(status)) {
            List<String> closedStatuses = new LinkedList<>(allStatuses);
            closedStatuses.removeAll(openStatuses);
            statuses.addAll(closedStatuses);
        } else {
            if (!oldRepository) {
                statuses.add(resolved);
            }
            if (allStatuses.contains(status)) {
                if (!"".equals(status)) {
                    for (int i = allStatuses.indexOf(status); i < allStatuses.size(); i++) {
                        String s = allStatuses.get(i);
                        if (!openStatuses.contains(s)) {
                            statuses.add(s);
                        }
                    }
                }
            } else {
                Bugzilla.LOG.log(Level.WARNING, "status value {0} not between all statuses: {1}", new Object[]{status, allStatuses}); // NOI18N
            }
        }
    }
    resolvedIndex = statuses.indexOf(resolved);
    statusCombo.setModel(toComboModel(statuses));
    statusCombo.setSelectedItem(currentStatus);
}
 
Example 18
Project: jdbacl   File: DatabaseTreeModel.java   View Source Code Vote up 4 votes
@Override
public int getIndexOfChild(DBObject parent, DBObject child) {
	List<?> components = ((CompositeDBObject<?>) parent).getComponents();
	return components.indexOf(child);
}
 
Example 19
Project: elasticsearch_my   File: ClusterRerouteIT.java   View Source Code Vote up 4 votes
public void testClusterRerouteWithBlocks() throws Exception {
    List<String> nodesIds = internalCluster().startNodes(2);

    logger.info("--> create an index with 1 shard and 0 replicas");
    assertAcked(prepareCreate("test-blocks").setSettings(Settings.builder().put("index.number_of_shards", 1).put("index.number_of_replicas", 0)));
    ensureGreen("test-blocks");

    logger.info("--> check that the index has 1 shard");
    ClusterState state = client().admin().cluster().prepareState().execute().actionGet().getState();
    List<ShardRouting> shards = state.routingTable().allShards("test-blocks");
    assertThat(shards, hasSize(1));

    logger.info("--> check that the shard is allocated");
    ShardRouting shard = shards.get(0);
    assertThat(shard.assignedToNode(), equalTo(true));

    logger.info("--> retrieve the node where the shard is allocated");
    DiscoveryNode node = state.nodes().resolveNode(shard.currentNodeId());
    assertNotNull(node);

    // toggle is used to mve the shard from one node to another
    int toggle = nodesIds.indexOf(node.getName());

    // Rerouting shards is not blocked
    for (String blockSetting : Arrays.asList(SETTING_BLOCKS_READ, SETTING_BLOCKS_WRITE, SETTING_READ_ONLY, SETTING_BLOCKS_METADATA)) {
        try {
            enableIndexBlock("test-blocks", blockSetting);
            assertAcked(client().admin().cluster().prepareReroute()
                    .add(new MoveAllocationCommand("test-blocks", 0, nodesIds.get(toggle % 2), nodesIds.get(++toggle % 2))));

            ClusterHealthResponse healthResponse = client().admin().cluster().prepareHealth().setWaitForYellowStatus().setWaitForNoRelocatingShards(true).execute().actionGet();
            assertThat(healthResponse.isTimedOut(), equalTo(false));
        } finally {
            disableIndexBlock("test-blocks", blockSetting);
        }
    }

    // Rerouting shards is blocked when the cluster is read only
    try {
        setClusterReadOnly(true);
        assertBlocked(client().admin().cluster().prepareReroute()
                .add(new MoveAllocationCommand("test-blocks", 1, nodesIds.get(toggle % 2), nodesIds.get(++toggle % 2))));
    } finally {
        setClusterReadOnly(false);
    }
}
 
Example 20
Project: n4js   File: AssignWorkingSetsAction.java   View Source Code Vote up 3 votes
/**
 * Replaces a possibly out-dated version of the given working set in the given list of working sets.
 *
 * Note that this depends on the equality-property of two different WorkingSet instances with the same id.
 *
 * @param list
 *            The list of working sets
 * @param workingSet
 *            The new state of the working set to replace
 */
private boolean replaceWorkingSet(List<WorkingSet> list, WorkingSet workingSet) {
	int replaceIndex = list.indexOf(workingSet);
	if (replaceIndex != -1) {
		list.set(replaceIndex, workingSet);
		return true;
	} else {
		return false;
	}
}