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:it.geosolutions.geoserver.jms.impl.handlers.configuration.JMSServiceHandler.java

/**
 * get local object searching by name if name is changed (remotely), search is performed using the old one
 * /* www .  ja v a2  s  .  c o  m*/
 * @param geoServer
 * @param ev
 * @return
 */
public static ServiceInfo getLocalService(final GeoServer geoServer, final JMSServiceModifyEvent ev) {

    final ServiceInfo service = ev.getSource();
    if (service == null) {
        throw new IllegalArgumentException("passed service is null");
    }

    // localize service
    final ServiceInfo localObject;

    // check if name is changed
    final List<String> props = ev.getPropertyNames();
    final int index = props.indexOf("name");
    if (index != -1) {

        final List<Object> oldValues = ev.getOldValues();
        // search the Service using the old name
        localObject = geoServer.getServiceByName(oldValues.get(index).toString(), ServiceInfo.class);
    } else {
        localObject = geoServer.getServiceByName(service.getName(), ServiceInfo.class);
    }

    return localObject;

}

From source file:Main.java

public static <ELEMENT> List<ELEMENT> moveElementToIndex(List<ELEMENT> list, ELEMENT fromElement,
        ELEMENT toElement) {//from w  w w . j a  v  a 2s.  co m
    assertObjectNotNull("list", list);
    final int fromIndex = list.indexOf(fromElement);
    final int toIndex = list.indexOf(toElement);
    return moveElementToIndex(list, fromIndex, toIndex);
}

From source file:Main.java

public static <T> List<T> subListOn(List<T> list, Predicate<T> predicate) {
    Optional<T> first = list.stream().filter(predicate).findFirst();
    if (!first.isPresent())
        return list;
    return list.subList(0, list.indexOf(first.get()));
}

From source file:Main.java

public static <T> void sortWithIndexesComparator(final List<T> list, final Comparator<Integer> comparator) {
    Collections.sort(list, new Comparator<T>() {
        @Override//from w w  w.jav a2s .c  o  m
        public int compare(T lhs, T rhs) {
            return comparator.compare(list.indexOf(lhs), list.indexOf(rhs));
        }
    });
}

From source file:edu.uci.ics.jung.algorithms.metrics.TriadicCensus.java

/**
 * Make sure we have a canonical ordering: Returns true if u < w, or v < w <
 * u and v doesn't link to w/*w  ww. ja v a 2  s. c om*/
 * 
 * @param id
 * @param u
 * @param v
 * @param w
 * @return true if u < w, or if v < w < u and v doesn't link to w; false otherwise
 */
protected static <V, E> boolean shouldCount(Graph<V, E> g, List<V> id, V u, V v, V w) {
    int i_u = id.indexOf(u);
    int i_w = id.indexOf(w);
    if (i_u < i_w)
        return true;
    int i_v = id.indexOf(v);
    if ((i_v < i_w) && (i_w < i_u) && (!g.isNeighbor(w, v)))
        return true;
    return false;
}

From source file:cpcc.vvrte.services.task.AcoTspSimple.java

/**
 * @param index the index number to be first in the resulting array.
 * @param path the path to fix.//from  w  w w  .ja  v a2  s. c o m
 */
public static void fixPath(int index, List<Integer> path) {
    int shift = path.indexOf(index);

    if (shift <= 0) {
        return;
    }

    while (shift-- > 0) {
        Integer v = path.remove(0);
        path.add(v);
    }
}

From source file:com.raulexposito.alarife.upgrader.DatabaseUpgrader.java

/**
 * Recovers the next version of the current version
 * <br>//from   w ww .  j  av a 2 s . c om
 * <strong>This method is PROTECTED to allow testing</strong>
 * <br>
 * @param currentVersion the current version
 * @param versionList the list with all versions
 * @return the next version of the current version
 */
public static Version getNextVersion(final Version currentVersion, final List<Version> versionList) {
    final int currentPosition = versionList.indexOf(currentVersion);

    return versionList.get(currentPosition + 1);
}

From source file:Main.java

/**
 * Move a single entry (indicated by its key) up or down by one step inside an insert sorted map (e.g. a {@link LinkedHashMap}).
 * //from  ww  w .  j  ava  2 s . co  m
 * @param <K>
 *            type of the map's keys
 * @param <V>
 *            type of the map's values
 * @param insertSortedMap
 *            map containing the entry to be moved; should be a map implementation preserving the insert order (e.g. a {@link LinkedHashMap})
 * @param entryKey
 *            key of the entry to be moved up/down by one step
 * @param increaseIndexByOne
 *            if the entry's index should be increased by one (i.e. moved down); otherwise decrease the entry's index by one (i.e. moved up)
 * @throws IllegalArgumentException
 *             <ul>
 *             <li>if the given map does not contain the specified key,</li>
 *             <li>if the specified entry is the first in the map and cannot be moved further up, or</li>
 *             <li>if the specified entry is the last in the map and cannot be moved further down</li>
 *             </ul>
 */
public static <K, V> void moveEntryInInsertSortedMap(final Map<K, V> insertSortedMap, final K entryKey,
        final boolean increaseIndexByOne) {
    // #1 create a copy of the original key order as list (to make it accessible via index)
    final List<K> keyList = new ArrayList<K>(insertSortedMap.keySet());
    // #2 determine the designated entry's current position
    final int index = keyList.indexOf(entryKey);
    // #3 determine the entry's new position
    final int indexToSwitchWith;
    if (increaseIndexByOne) {
        indexToSwitchWith = index + 1;
    } else {
        indexToSwitchWith = index - 1;
    }
    final int totalEntryCount = keyList.size();
    if (index == -1 || indexToSwitchWith == -1 || indexToSwitchWith == totalEntryCount) {
        // the entry cannot be moved as indicated
        throw new IllegalArgumentException();
    }
    // #4 create a copy of the unchanged relation template groups map
    final Map<K, V> groupsCopy = new LinkedHashMap<K, V>(insertSortedMap);
    // #5 remove all mapping from the original relation template groups map, starting at the affected groups' indices
    insertSortedMap.keySet().retainAll(keyList.subList(0, Math.min(index, indexToSwitchWith)));
    final K entryToSwitchWith = keyList.get(indexToSwitchWith);
    // #6 re-insert the two affected groups in their new (inverse) order
    if (increaseIndexByOne) {
        insertSortedMap.put(entryToSwitchWith, groupsCopy.get(entryToSwitchWith));
        insertSortedMap.put(entryKey, groupsCopy.get(entryKey));
    } else {
        insertSortedMap.put(entryKey, groupsCopy.get(entryKey));
        insertSortedMap.put(entryToSwitchWith, groupsCopy.get(entryToSwitchWith));
    }
    // #7 re-insert all groups that are following the affected two relation tempate groups
    final int firstTrailingRetainedIndex = Math.max(index, indexToSwitchWith) + 1;
    if (firstTrailingRetainedIndex < totalEntryCount) {
        // there is at least one more value behind the affected two entries that needs to be re-inserted
        groupsCopy.keySet().retainAll(keyList.subList(firstTrailingRetainedIndex, totalEntryCount));
        insertSortedMap.putAll(groupsCopy);
    }
}

From source file:Main.java

public static void removeListPrefItems(ListPreference listPref, String[] labels, String[] values,
        List<String> items) {

    List<String> labelsList = new ArrayList<String>(Arrays.asList(labels));
    List<String> valuesList = new ArrayList<String>(Arrays.asList(values));

    Iterator<String> it = valuesList.iterator();
    while (it.hasNext()) {
        String value = it.next();
        if (items.contains(value)) {
            labelsList.remove(valuesList.indexOf(value));
            it.remove();//from  w w  w. j a va  2s. c  om
        }
    }

    listPref.setEntries(labelsList.toArray(new String[1]));
    listPref.setEntryValues(valuesList.toArray(new String[1]));

}

From source file:com.quest.access.useraccess.services.OpenDataService.java

public static String getSetting(String key) {
    if (busSettings == null) {
        return "_notexist_";
    }// w  ww .ja  v a 2 s .  co m
    List keys = busSettings.optJSONArray("CONF_KEY").toList();
    List values = busSettings.optJSONArray("CONF_VALUE").toList();
    int index = keys.indexOf(key);
    return index == -1 ? "_notexist_" : values.get(index).toString();
}