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

The following are Jave code examples for showing how to use lastIndexOf() 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.
Example 1
Project: JRediClients   File: RedissonListTest.java   Source Code and License Vote up 6 votes
@Test
public void testLastIndexOf2() {
    List<Integer> list = redisson.getList("list");
    list.add(1);
    list.add(2);
    list.add(3);
    list.add(4);
    list.add(5);
    list.add(0);
    list.add(7);
    list.add(8);
    list.add(0);
    list.add(10);

    int index = list.lastIndexOf(3);
    Assert.assertEquals(2, index);
}
 
Example 2
Project: JRediClients   File: RedissonListTest.java   Source Code and License Vote up 6 votes
@Test
public void testLastIndexOf1() {
    List<Integer> list = redisson.getList("list");
    list.add(1);
    list.add(2);
    list.add(3);
    list.add(4);
    list.add(5);
    list.add(3);
    list.add(7);
    list.add(8);
    list.add(0);
    list.add(10);

    int index = list.lastIndexOf(3);
    Assert.assertEquals(5, index);
}
 
Example 3
Project: JRediClients   File: RedissonListTest.java   Source Code and License Vote up 6 votes
@Test
public void testLastIndexOf() {
    List<Integer> list = redisson.getList("list");
    list.add(1);
    list.add(2);
    list.add(3);
    list.add(4);
    list.add(5);
    list.add(3);
    list.add(7);
    list.add(8);
    list.add(3);
    list.add(10);

    int index = list.lastIndexOf(3);
    Assert.assertEquals(8, index);
}
 
Example 4
Project: openjdk-jdk10   File: SubList.java   Source Code and License Vote up 5 votes
@Test(dataProvider = "modifiable",
      expectedExceptions = ConcurrentModificationException.class)
public void testModLastIndexOf(List<Integer> list, int from, int to) {
    List<Integer> subList = list.subList(from, to);
    list.add(42);
    subList.lastIndexOf(42);
}
 
Example 5
Project: vehicle-keyboard-android   File: InputView.java   Source Code and License Vote up 5 votes
private void performNextItemBy(Button cell) {
    final List<Button> buttons = streamOfShownItems()
            .collect(Collectors.<Button>toList());
    final int nextIndex = buttons.lastIndexOf(cell) + 1;
    final int clickIndex = Math.min(nextIndex, buttons.size() - 1);
    performItemSelected(buttons.get(clickIndex));
}
 
Example 6
Project: jmt   File: ModelConverter.java   Source Code and License Vote up 4 votes
/**
 * This method will return a reachability vector for given station and given class
 * @param stationKey search's key for given station
 * @param classKey search's key for given class
 * @param model model data structure
 * @param stations vector with ordered station keys (the same order is used in output array)
 * @param warnings vector Vector to store warnings found during computation
 * @return an array with probability to reach each other station starting from given station
 */
private static double[] getRoutingProbability(Object stationKey, Object classKey, CommonModel model, List<Object> stations, List<String> warnings) {
	double[] p = new double[stations.size()];
	RoutingStrategy strategy = (RoutingStrategy) model.getRoutingStrategy(stationKey, classKey);
	if (strategy instanceof ProbabilityRouting && !model.getStationType(stationKey).equals(CommonConstants.STATION_TYPE_FORK)) {
		Map<Object, Double> routingMap = strategy.getValues();
		Iterator<Object> it = routingMap.keySet().iterator();
		while (it.hasNext()) {
			Object dest = it.next();
			if (stations.lastIndexOf(dest) >= 0) {
				p[stations.lastIndexOf(dest)] = (routingMap.get(dest)).doubleValue();
			}
		}
	} else {
		if (model.getStationType(stationKey).equals(CommonConstants.STATION_TYPE_FORK)) {
			warnings.add("Fork-Join are not supported in JMVA. They are considered as routers.");
		} else if (!(strategy instanceof RandomRouting)) {
			warnings.add("\"" + strategy.getName() + "\" routing strategy in " + model.getClassName(classKey) + " for "
					+ model.getStationName(stationKey) + " is not allowed. This was considered as RandomRouting");
		}

		Vector<Object> links = model.getForwardConnections(stationKey);
		int linksNum = links.size();
		// Now ignores sinks for closed classes
		if (model.getClassType(classKey) == CommonConstants.CLASS_TYPE_CLOSED) {
			for (int i = 0; i < links.size(); i++) {
				if (model.getStationType(links.get(i)).equals(CommonConstants.STATION_TYPE_SINK)) {
					linksNum--;
				}
			}
		}

		double weight = 1.0 / linksNum;
		for (int i = 0; i < links.size(); i++) {
			if (stations.contains(links.get(i))) {
				p[stations.lastIndexOf(links.get(i))] = weight;
			}
		}
	}

	return p;
}
 
Example 7
Project: QN-ACTR-Release   File: ModelConverter.java   Source Code and License Vote up 4 votes
/**
 * This method will return a reachability vector for given station and given class
 * @param stationKey search's key for given station
 * @param classKey search's key for given class
 * @param model model data structure
 * @param stations vector with ordered station keys (the same order is used in output array)
 * @param warnings vector Vector to store warnings found during computation
 * @return an array with probability to reach each other station starting from given station
 */
private static double[] getRoutingProbability(Object stationKey, Object classKey, CommonModel model, List<Object> stations, List<String> warnings) {
	double[] p = new double[stations.size()];
	RoutingStrategy strategy = (RoutingStrategy) model.getRoutingStrategy(stationKey, classKey);
	if (strategy instanceof ProbabilityRouting && !model.getStationType(stationKey).equals(CommonConstants.STATION_TYPE_FORK)) {
		Map routingMap = strategy.getValues();
		Iterator it = routingMap.keySet().iterator();
		while (it.hasNext()) {
			Object dest = it.next();
			if (stations.lastIndexOf(dest) >= 0) {
				p[stations.lastIndexOf(dest)] = ((Double) routingMap.get(dest)).doubleValue();
			}
		}
	} else {
		if (model.getStationType(stationKey).equals(CommonConstants.STATION_TYPE_FORK)) {
			warnings.add("Fork-Join are not supported in JMVA. They are considered as routers.");
		} else if (!(strategy instanceof RandomRouting)) {
			warnings.add("\"" + strategy.getName() + "\" routing strategy in " + model.getClassName(classKey) + " for "
					+ model.getStationName(stationKey) + " is not allowed. This was considered as RandomRouting");
		}

		Vector<Object> links = model.getForwardConnections(stationKey);
		int linksNum = links.size();
		// Now ignores sinks for closed classes
		if (model.getClassType(classKey) == CommonConstants.CLASS_TYPE_CLOSED) {
			for (int i = 0; i < links.size(); i++) {
				if (model.getStationType(links.get(i)).equals(CommonConstants.STATION_TYPE_SINK)) {
					linksNum--;
				}
			}
		}

		double weight = 1.0 / linksNum;
		for (int i = 0; i < links.size(); i++) {
			if (stations.contains(links.get(i))) {
				p[stations.lastIndexOf(links.get(i))] = weight;
			}
		}
	}

	return p;
}
 
Example 8
Project: L2J-Global   File: GeoPathFinding.java   Source Code and License Vote up 4 votes
public List<AbstractNodeLoc> searchByClosest2(GeoNode start, GeoNode end)
{
	// Always continues checking from the closest to target non-blocked
	// node from to_visit list. There's extra length in path if needed
	// to go backwards/sideways but when moving generally forwards, this is extra fast
	// and accurate. And can reach insane distances (try it with 800 nodes..).
	// Minimum required node count would be around 300-400.
	// Generally returns a bit (only a bit) more intelligent looking routes than
	// the basic version. Not a true distance image (which would increase CPU
	// load) level of intelligence though.
	
	// List of Visited Nodes
	final List<GeoNode> visited = new ArrayList<>(550);
	
	// List of Nodes to Visit
	final LinkedList<GeoNode> to_visit = new LinkedList<>();
	to_visit.add(start);
	final int targetX = end.getLoc().getNodeX();
	final int targetY = end.getLoc().getNodeY();
	
	int dx, dy;
	boolean added;
	int i = 0;
	while (i < 550)
	{
		GeoNode node;
		try
		{
			node = to_visit.removeFirst();
		}
		catch (Exception e)
		{
			// No Path found
			return null;
		}
		if (node.equals(end))
		{
			return constructPath2(node);
		}
		
		i++;
		visited.add(node);
		node.attachNeighbors();
		final GeoNode[] neighbors = node.getNeighbors();
		if (neighbors == null)
		{
			continue;
		}
		for (GeoNode n : neighbors)
		{
			if ((visited.lastIndexOf(n) == -1) && !to_visit.contains(n))
			{
				added = false;
				n.setParent(node);
				dx = targetX - n.getLoc().getNodeX();
				dy = targetY - n.getLoc().getNodeY();
				n.setCost((dx * dx) + (dy * dy));
				for (int index = 0; index < to_visit.size(); index++)
				{
					// supposed to find it quite early..
					if (to_visit.get(index).getCost() > n.getCost())
					{
						to_visit.add(index, n);
						added = true;
						break;
					}
				}
				if (!added)
				{
					to_visit.addLast(n);
				}
			}
		}
	}
	// No Path found
	return null;
}
 
Example 9
Project: HCFCore   File: AbstractListValuedMap.java   Source Code and License Vote up 4 votes
@Override
public int lastIndexOf(Object o) {
    final List<V> list = ListUtils.emptyIfNull(getMapping());
    return list.lastIndexOf(o);
}
 
Example 10
Project: HCFCore   File: AbstractListValuedMap.java   Source Code and License Vote up 4 votes
@Override
public int lastIndexOf(Object o) {
    final List<V> list = ListUtils.emptyIfNull(getMapping());
    return list.lastIndexOf(o);
}