本文整理了Java中org.matsim.core.utils.collections.QuadTree.values
方法的一些代码示例,展示了QuadTree.values
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。QuadTree.values
方法的具体详情如下:
包路径:org.matsim.core.utils.collections.QuadTree
类名称:QuadTree
方法名:values
[英]A cache to store all values of the QuadTree so it does not have to be computed for every call to #values(). This is similar to TreeMap.java and AbstractMap.java
[中]一个缓存,用于存储四叉树的所有值,这样就不必为每次调用#values()计算它。这类似于TreeMap。java和AbstractMap。JAVA
代码示例来源:origin: matsim-org/matsim
/**
* retrieve all cells
* @return all cells of the grid
*/
public Collection<Cell<T>> getCells() {
return quadTree.values();
}
代码示例来源:origin: matsim-org/matsim
private static Map<Id<PtStop>, PtStop> convertQuadTree2HashMap(QuadTree<PtStop> qTree){
Iterator<PtStop> ptStopIterator = qTree.values().iterator();
Map<Id<PtStop>, PtStop> ptStopHashMap = new ConcurrentHashMap<>();
while(ptStopIterator.hasNext()){
PtStop ptStop = ptStopIterator.next();
ptStopHashMap.put(ptStop.getId(), ptStop);
}
return ptStopHashMap;
}
代码示例来源:origin: matsim-org/matsim
/**
* tests that also for a large number of entries, values() returns the correct result.
*/
@Test
public void testGetValues() {
double minX = -1000;
double minY = -5000;
double maxX = 20000;
double maxY = 12000;
Random r = new Random(20181017L);
List<String> expected = new ArrayList<>(1000);
QuadTree<String> qt = new QuadTree<>(minX, minY, maxX, maxY);
for (int i = 0; i < 1000; i++) {
double x = minX + r.nextDouble() * (maxX - minX);
double y = minY + r.nextDouble() * (maxY - minY);
String value = "ITEM_" + i;
qt.put(x, y, value);
expected.add(value);
}
List<String> items = new ArrayList<>(qt.values());
Assert.assertEquals(1000, items.size());
items.sort(String::compareTo);
expected.sort(String::compareTo);
for (int i = 0; i < 1000; i++) {
Assert.assertEquals(expected.get(i), items.get(i));
}
}
代码示例来源:origin: matsim-org/matsim
/**
* Tests that by serializing and de-serializing a QuadTree, all important attributes
* of the QuadTree are maintained. At the moment, this is essentially the size-attribute.
* @throws IOException
* @throws ClassNotFoundException
*/
@Test
public void testSerialization() throws IOException, ClassNotFoundException {
QuadTree<String> qt = getTestTree();
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(outStream);
out.writeObject(qt);
out.close();
ByteArrayInputStream inStream = new ByteArrayInputStream(outStream.toByteArray());
ObjectInputStream in = new ObjectInputStream(inStream);
QuadTree<String> qt2 = (QuadTree<String>)in.readObject();
in.close();
assertEquals(qt.size(), qt2.size());
valuesTester(qt2.size(), qt2.values());
}
代码示例来源:origin: matsim-org/matsim
@Test
public void testValuesIterator_ConcurrentModification() {
QuadTree<String> qt = getTestTree();
Iterator<String> iter = qt.values().iterator();
assertTrue(iter.hasNext());
assertNotNull(iter.next());
qt.put(39.0, 52.1, "39.0 52.1");
assertTrue(iter.hasNext()); // hasNext() should not yet provoke exception
try {
iter.next();
fail("missing exception.");
}
catch (ConcurrentModificationException e) {
log.info("catched expected exception: ", e);
}
}
代码示例来源:origin: matsim-org/matsim
Matrix originDestinationTravelDistanceMatrix = new Matrix("PtStopTravelDistanceMatrix", "Stop to stop origin destination travel distance matrix");
PtStop ptStopIds[] = ptStops.values().toArray( new PtStop[0] );
代码示例来源:origin: matsim-org/matsim
private Tuple<QuadTree<ActivityFacilityWithIndex>, ActivityFacilityImpl[]> getTuple(String activityType) {
TreesBuilder treesBuilder = new TreesBuilder(CollectionUtils.stringToSet(activityType), this.scenario.getNetwork(), this.dccg);
treesBuilder.setActTypeConverter(this.getConverter());
treesBuilder.createTrees(scenario.getActivityFacilities());
ActivityFacilityImpl[] facilities = treesBuilder.getFacilitiesOfType().get(activityType);
/*
* Create a copy of the treesBuilder.getQuadTreesOfType() outcome where the
* ActivityFacility objects are replaced by ActivityFacilityWithIndex objects.
* TODO: let the TreeBuilder use ActivityFacilityWithIndex objects directly?
*/
QuadTree<ActivityFacilityWithIndex> quadTree = null;
QuadTree<ActivityFacility> qt = treesBuilder.getQuadTreesOfType().get(activityType);
if (qt != null) {
double minX = qt.getMinEasting();
double maxX = qt.getMaxEasting();
double minY = qt.getMinNorthing();
double maxY = qt.getMaxNorthing();
quadTree = new QuadTree<ActivityFacilityWithIndex>(minX, minY, maxX, maxY);
for (ActivityFacility activityFacility : qt.values()) {
quadTree.put(activityFacility.getCoord().getX(), activityFacility.getCoord().getY(), this.faciliesWithIndexMap.get(activityFacility.getId()));
}
}
return new Tuple<QuadTree<ActivityFacilityWithIndex>, ActivityFacilityImpl[]>(quadTree, facilities);
}
代码示例来源:origin: matsim-org/matsim
/**
* Test {@link QuadTree#values()} that it returns the correct content.
*/
@Test
public void testValues() {
QuadTree<String> qt = getTestTree();
int size = qt.size();
assertEquals(6, size);
// generic test
valuesTester(qt.size(), qt.values());
// test that values() got updated after adding an object to the tree
qt.put(80.0, 80.0, "80.0, 80.0");
assertEquals(size + 1, qt.size());
valuesTester(qt.size(), qt.values());
// test that values() got updated after removing an object to the tree
assertTrue(qt.remove(80.0, 80.0, "80.0, 80.0"));
assertEquals(size, qt.size());
valuesTester(qt.size(), qt.values());
// and remove one more...
assertTrue(qt.remove(10.0, 10.0, "10.0, 10.0"));
assertEquals(size - 1, qt.size());
valuesTester(qt.size(), qt.values());
// test the iterator
Iterator<String> iter = qt.values().iterator();
iter.next();
try {
iter.remove();
fail("expected UnsupportedOperationException, got none.");
} catch (UnsupportedOperationException expected) {}
}
代码示例来源:origin: matsim-org/matsim
/**
* Test {@link QuadTree#clear()}.
*/
@Test
public void testClear() {
QuadTree<String> qt = getTestTree();
int size = qt.size();
assertTrue(size > 0); // it makes no sense to test clear() on an empty tree
qt.clear();
assertEquals(0, qt.size());
valuesTester(0, qt.values());
}
代码示例来源:origin: matsim-org/matsim
/**
* Tests that a once obtained values-collection is indeed a live view
* on the QuadTree, so when the QuadTree changes, the view is updated
* as well.
*/
@Test
public void testValues_isView() {
QuadTree<String> qt = getTestTree();
int size = qt.size();
Collection<String> values = qt.values();
valuesTester(qt.size(), values);
qt.put(80.0, 80.0, "80.0, 80.0");
assertEquals(size + 1, qt.size());
valuesTester(size + 1, values);
qt.put(75.0, 75.0, "75.0, 75.0");
assertEquals(size + 2, qt.size());
valuesTester(size + 2, values);
assertTrue(qt.remove(80.0, 80.0, "80.0, 80.0"));
assertEquals(size + 1, qt.size());
valuesTester(size + 1, values);
}
内容来源于网络,如有侵权,请联系作者删除!