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:com.google.gdt.eclipse.designer.gxt.databinding.model.bindings.FieldBindingInfo.java

@Override
public void move(List<BindingInfo> bindings) {
    if (m_parentBinding != null) {
        m_parentBinding.getFieldBindings().remove(this);
        int index = bindings.indexOf(this) - bindings.indexOf(m_parentBinding) - 1;
        m_parentBinding.getFieldBindings().add(index, this);
    }//  ww w .  j a va2s . c o  m
}

From source file:de.bbe_consulting.mavento.ui.generation.MagentoArchetypeSelector.java

private Map.Entry<String, Archetype> findArchetype(Map<String, List<Archetype>> archetypes, String groupId,
        String artifactId) {//from   w  w  w  . j a  va  2s . co  m
    Archetype example = new Archetype();
    example.setGroupId(groupId);
    example.setArtifactId(artifactId);

    for (Map.Entry<String, List<Archetype>> entry : archetypes.entrySet()) {
        List<Archetype> catalog = entry.getValue();

        if (catalog.contains(example)) {
            Archetype archetype = catalog.get(catalog.indexOf(example));

            return newMapEntry(entry.getKey(), archetype);
        }
    }

    return null;
}

From source file:com.newmainsoftech.spray.slingong.datastore.Slim3PlatformTransactionManagerTest2.java

protected void verify3rdBookEntities() {
    logGlobalTransactionStatus();//w  w  w .j av a2 s .co m

    List<Key> author3GroupKeyList = Datastore.query(author3.getKey()).asKeyList();
    Assert.assertTrue(author3GroupKeyList.contains(author3.getKey()));
    Assert.assertTrue(author3GroupKeyList.contains(book3.getKey()));

    logGlobalTransactionStatus();

    Book book3Copy = Datastore.get(Book.class, book3.getKey());
    List<AuthorBook> authorBookList = book3Copy.getAuthorBookListRef().getModelList();
    Assert.assertEquals(1, authorBookList.size());
    Assert.assertEquals(a2, authorBookList.get(0).getAuthorRef().getModel());

    logGlobalTransactionStatus();

    List<Chapter> chapterList = book3Copy.getChapterList();
    Assert.assertTrue(chapterList.contains(book3Chapter1));
    List<AuthorChapter> authorChapterList = chapterList.get(chapterList.indexOf(book3Chapter1))
            .getAuthorChapterListRef().getModelList();
    Assert.assertEquals(1, authorChapterList.size());
    Assert.assertEquals(author3, authorChapterList.get(0).getAuthorRef().getModel());

    logGlobalTransactionStatus();
}

From source file:com.dshue.web.WebConfiguration.java

@Bean
ViewInjectingReturnValueHandler viewInjectingReturnValueHandler() {
    List<HandlerMethodReturnValueHandler> handlers = new ArrayList<>(
            this.requestMappingHandlerAdapter.getReturnValueHandlers().getHandlers());

    for (HandlerMethodReturnValueHandler handler : handlers) {
        if (handler instanceof RequestResponseBodyMethodProcessor) {
            ViewInjectingReturnValueHandler decorator = new ViewInjectingReturnValueHandler(handler);
            int index = handlers.indexOf(handler);
            handlers.set(index, decorator);

            this.requestMappingHandlerAdapter.setReturnValueHandlers(handlers);
            return decorator;
        }//from w ww .  ja  v a  2s  .  c  o m
    }

    return null;
}

From source file:fi.helsinki.opintoni.service.favorite.FavoriteService.java

private void orderFavorites(final Long userId, final List<Long> orderedFavoriteIds, final boolean portfolio) {
    favoriteRepository.findByUserIdOrderByOrderIndexAsc(userId).stream()
            .filter(f -> f.isPortfolio() == portfolio).filter(f -> orderedFavoriteIds.contains(f.id))
            .forEach(f -> f.orderIndex = orderedFavoriteIds.indexOf(f.id));
}

From source file:cl.b9.socialNetwork.jung.SNPajekNetWriter.java

/**
 * Writes <code>graph</code> to <code>w</code>.  Labels for vertices may
 * be supplied by <code>vs</code> (defaults to no labels if null), 
 * edge weights may be specified by <code>nev</code>
 * (defaults to weights of 1.0 if null), 
 * and vertex locations may be specified by <code>vld</code> (defaults
 * to no locations if null). //from w w w  . j  ava  2  s  .com
 */
@SuppressWarnings("unchecked")
public void save(Graph<V, E> graph, Writer w, Transformer<V, String> vs, Transformer<E, Number> nev,
        Transformer<V, Point2D> vld, Transformer<V, String> shape) throws IOException {
    /*
     * TODO: Changes we might want to make:
     * - optionally writing out in list form
     */

    BufferedWriter writer = new BufferedWriter(w);
    if (nev == null)
        nev = new Transformer<E, Number>() {
            public Number transform(E e) {
                return 1;
            }
        };
    writer.write("*Vertices " + graph.getVertexCount());
    writer.newLine();

    List<V> id = new ArrayList<V>(graph.getVertices());//Indexer.getIndexer(graph);
    for (V currentVertex : graph.getVertices()) {
        // convert from 0-based to 1-based index
        int v_id = id.indexOf(currentVertex) + 1;
        writer.write("" + v_id);
        if (vs != null) {
            String label = vs.transform(currentVertex);
            if (label != null)
                writer.write(" \"" + label + "\"");
        }
        if (vld != null) {
            Point2D location = vld.transform(currentVertex);
            if (location != null)
                writer.write(" " + location.getX() + " " + location.getY());
        }
        if (shape != null) {
            writer.write(" " + shape.transform(currentVertex) + " x_fact 1");
        }
        writer.newLine();
    }

    Collection<E> d_set = new HashSet<E>();
    Collection<E> u_set = new HashSet<E>();

    boolean directed = graph instanceof DirectedGraph;

    boolean undirected = graph instanceof UndirectedGraph;

    // if it's strictly one or the other, no need to create extra sets
    if (directed)
        d_set.addAll(graph.getEdges());
    if (undirected)
        u_set.addAll(graph.getEdges());
    if (!directed && !undirected) // mixed-mode graph
    {
        u_set.addAll(graph.getEdges());
        d_set.addAll(graph.getEdges());
        for (E e : graph.getEdges()) {
            if (graph.getEdgeType(e) == EdgeType.UNDIRECTED) {
                d_set.remove(e);
            } else {
                u_set.remove(e);
            }
        }
    }

    // write out directed edges
    if (!d_set.isEmpty()) {
        writer.write("*Arcs");
        writer.newLine();
    }
    for (E e : d_set) {
        int source_id = id.indexOf(graph.getEndpoints(e).getFirst()) + 1;
        int target_id = id.indexOf(graph.getEndpoints(e).getSecond()) + 1;
        //            float weight = nev.get(e).floatValue();
        float weight = nev.transform(e).floatValue();
        writer.write(source_id + " " + target_id + " " + weight);
        writer.newLine();
    }

    // write out undirected edges
    if (!u_set.isEmpty()) {
        writer.write("*Edges");
        writer.newLine();
    }
    for (E e : u_set) {
        Pair<V> endpoints = graph.getEndpoints(e);
        int v1_id = id.indexOf(endpoints.getFirst()) + 1;
        int v2_id = id.indexOf(endpoints.getSecond()) + 1;
        //            float weight = nev.get(e).floatValue();
        float weight = nev.transform(e).floatValue();
        writer.write(v1_id + " " + v2_id + " " + weight);
        writer.newLine();
    }
    writer.close();
}

From source file:io.hops.transaction.context.BlockInfoContext.java

private void updateInodeBlocks(BlockInfoContiguous newBlock) {
    if (newBlock == null)
        return;/*from   www  .j  av a  2 s .c o  m*/

    List<BlockInfoContiguous> blockList = inodeBlocks.get(newBlock.getInodeId());

    if (blockList != null) {
        int idx = blockList.indexOf(newBlock);
        if (idx != -1) {
            blockList.set(idx, newBlock);
        } else {
            blockList.add(newBlock);
        }
    } else {
        List<BlockInfoContiguous> list = new ArrayList<>(DEFAULT_NUM_BLOCKS_PER_INODE);
        list.add(newBlock);
        inodeBlocks.put(newBlock.getInodeId(), list);
    }
}

From source file:edu.uci.ics.jung.io.CustomPajekNetWriter.java

/**
 * Writes <code>graph</code> to <code>w</code>. Labels for vertices may be
 * supplied by <code>vs</code> (defaults to no labels if null), edge weights
 * may be specified by <code>nev</code> (defaults to weights of 1.0 if
 * null), and vertex locations may be specified by <code>vld</code>
 * (defaults to no locations if null)./*from  www.  java 2  s  . co m*/
 */
public void save(MyGraph<V, E> graph, Writer w, Transformer<V, String> vs, Transformer<E, Number> nev,
        Transformer<V, Point2D> vld) throws IOException {
    /*
     * TODO: Changes we might want to make:
     * - optionally writing out in list form
     */

    BufferedWriter writer = new BufferedWriter(w);
    if (nev == null) {
        nev = new Transformer<E, Number>() {
            public Number transform(E e) {
                return 1;
            }
        };
    }
    writer.write("*Colors " + graph.getLayoutParameters().getBackgroundColorRgb() + ","
            + graph.getLayoutParameters().getEdgeColorRgb());
    writer.newLine();
    writer.write(
            "*Vertices " + graph.getVertexCount() + "," + graph.getLayoutParameters().areNodeIconsAllowed());
    writer.newLine();

    List<V> id = new ArrayList<V>(graph.getVertices());//Indexer.getIndexer(graph);
    for (V currentVertex : graph.getVertices()) {
        // convert from 0-based to 1-based index
        int v_id = id.indexOf(currentVertex) + 1;
        writer.write("" + v_id);
        if (vs != null) {
            String label = vs.transform(currentVertex);
            if (label != null) {
                writer.write(" \"" + label + "\"");
            }
        }
        if (vld != null) {
            Point2D location = vld.transform(currentVertex);
            if (location != null) {
                writer.write(" " + location.getX() + " " + location.getY() + " 0.0");
            }
        }
        writer.newLine();
    }

    Collection<E> d_set = new HashSet<E>();
    Collection<E> u_set = new HashSet<E>();

    boolean directed = graph instanceof DirectedGraph;

    boolean undirected = graph instanceof UndirectedGraph;

    // if it's strictly one or the other, no need to create extra sets
    if (directed) {
        d_set.addAll(graph.getEdges());
    }
    if (undirected) {
        u_set.addAll(graph.getEdges());
    }
    if (!directed && !undirected) // mixed-mode graph
    {
        u_set.addAll(graph.getEdges());
        d_set.addAll(graph.getEdges());
        for (E e : graph.getEdges()) {
            if (graph.getEdgeType(e) == EdgeType.UNDIRECTED) {
                d_set.remove(e);
            } else {
                u_set.remove(e);
            }
        }
    }

    // write out directed edges
    if (!d_set.isEmpty()) {
        writer.write("*Arcs");
        writer.newLine();
    }
    for (E e : d_set) {
        int source_id = id.indexOf(graph.getEndpoints(e).getFirst()) + 1;
        int target_id = id.indexOf(graph.getEndpoints(e).getSecond()) + 1;
        float weight = nev.transform(e).floatValue();
        writer.write(source_id + " " + target_id + " " + weight);
        writer.newLine();
    }

    // write out undirected edges
    if (!u_set.isEmpty()) {
        writer.write("*Edges");
        writer.newLine();
    }
    for (E e : u_set) {
        Pair<V> endpoints = graph.getEndpoints(e);
        int v1_id = id.indexOf(endpoints.getFirst()) + 1;
        int v2_id = id.indexOf(endpoints.getSecond()) + 1;
        float weight = nev.transform(e).floatValue();
        writer.write(v1_id + " " + v2_id + " " + weight);
        writer.newLine();
    }
    writer.close();
}

From source file:com.jaspersoft.studio.server.editor.JRSRepositoryService.java

private void setupConnection(IConnection conn) {
    c = conn;//from   w  ww  .j  a va 2  s.  co m
    try {
        rpath = msp.getTmpDir(new NullProgressMonitor()).getRawLocation().toOSString();
        List<RepositoryService> servs = parent.getRepositoryServices();
        if (repService != null)
            servs.remove(repService);
        repService = new FileRepositoryService(jConfig, rpath, true);
        int ind = servs.indexOf(JRSRepositoryService.this);
        servs.add(Math.max(0, Math.max(ind - 2, ind - 1)), repService);
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        isConnecting = false;
    }
}

From source file:io.fabric8.maven.plugin.ManifestIndexMojo.java

protected void addManifestInfo(Map<String, ManifestInfo> manifests, ArtifactDTO artifact) {
    List<String> ec = artifact.getEc();
    if (ec != null && ec.indexOf("-openshift.yml") >= 0 && ec.indexOf("-openshift.yml") >= 0) {
        // lets create the latest manifest
        ManifestInfo latest = new ManifestInfo(mavenRepoUrl, artifact);
        String key = artifact.createKey();
        manifests.put(key, latest);/* www  .  j a v a  2  s  . c o  m*/
    }
}