本文整理了Java中us.ihmc.robotics.lists.YoPreallocatedList
类的一些代码示例,展示了YoPreallocatedList
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。YoPreallocatedList
类的具体详情如下:
包路径:us.ihmc.robotics.lists.YoPreallocatedList
类名称:YoPreallocatedList
[英]YoVariablized version of the PreallocatedList from ihmc-commons
[中]ihmc commons预分配列表的变量化版本
代码示例来源:origin: us.ihmc/ihmc-robotics-toolkit
/**
* Returns the first element of this list. If the list is empty, it returns {@code null}.
*
* @return the first element of this list.
*/
public T getFirst()
{
if (isEmpty())
{
return null;
}
else
{
return values[0];
}
}
代码示例来源:origin: us.ihmc/ihmc-robotics-toolkit
/**
* Returns {@code true} if this list contains no elements.
*
* @return {@code true} if this list contains no elements.
*/
@Override
public boolean isEmpty()
{
return size() == 0;
}
代码示例来源:origin: us.ihmc/ihmc-robotics-toolkit
/**
* @return the remaining space in this sequence (capacity() - size())
*/
public int remaining()
{
return capacity() - size();
}
代码示例来源:origin: us.ihmc/ihmc-robotics-toolkit-test
YoPreallocatedList<YoDouble> list = new YoPreallocatedList<>(YoDouble.class, "Test", 20, new YoVariableRegistry("Test"));
ArrayList<YoDouble> expectedList = new ArrayList<>();
YoDouble lastObject = list.add();
expectedList.add(lastObject);
assertFalse(list.isEmpty());
assertTrue(list.size() == finalSize);
for (int i = 0; i < finalSize; i++)
assertTrue(list.get(i) == expectedList.get(i));
assertTrue(list.getLast() == expectedList.get(finalSize - 1));
list.get(finalSize);
fail();
list.clear();
expectedList.clear();
assertTrue(list.getLast() == null);
YoDouble lastObject = list.add();
expectedList.add(lastObject);
assertFalse(list.isEmpty());
assertTrue(list.size() == finalSize);
for (int i = 0; i < finalSize; i++)
assertTrue(list.get(i) == expectedList.get(i));
代码示例来源:origin: us.ihmc/ihmc-robotics-toolkit-test
@Test(timeout = 30000)
public void testRemove()
YoPreallocatedList<YoInteger> list = new YoPreallocatedList<>(YoInteger.class, "Test", 10, new YoVariableRegistry("Test"));
int currentSize = 10;
while (list.size() < currentSize)
list.add().set(10 + list.size());
expectedList.add(list.get(i));
list.remove(indexOfRemovedObject);
expectedList.remove(indexOfRemovedObject);
currentSize--;
assertTrue(list.size() == currentSize);
assertTrue(list.get(i) == expectedList.get(i));
list.remove(indexOfRemovedObject);
expectedList.remove(indexOfRemovedObject);
currentSize--;
assertTrue(list.size() == currentSize);
assertTrue(list.get(i) == expectedList.get(i));
list.remove(currentSize);
fail();
代码示例来源:origin: us.ihmc/ihmc-robotics-toolkit-test
YoPreallocatedList<YoDouble> list = new YoPreallocatedList<>(YoDouble.class, "Test", 10, testRegistry);
for (int i = 0; i < size; i++)
list.add().set(i);
list.set(0, testDouble);
fail();
list.add(testDouble);
fail();
list.add(0, testDouble);
fail();
list.addAll(new HashSet<>());
fail();
list.replaceAll(UnaryOperator.identity());
fail();
list.iterator();
fail();
list.listIterator();
fail();
list.listIterator(0);
fail();
代码示例来源:origin: us.ihmc/ihmc-robotics-toolkit-test
@Test(timeout = 30000)
public void testConstructor()
{
YoPreallocatedList<YoDouble> list = new YoPreallocatedList<>(YoDouble.class, "Test", 10, new YoVariableRegistry("Test"));
assertTrue(list.isEmpty());
assertTrue(list.size() == 0);
assertTrue(list.getLast() == null);
}
代码示例来源:origin: us.ihmc/ihmc-robotics-toolkit-test
YoPreallocatedList<YoInteger> list = new YoPreallocatedList<>(YoInteger.class, "Test", 10, new YoVariableRegistry("Test"));
int currentSize = 10;
while (list.size() < currentSize)
list.add().set(10 + list.size());
expectedList.add(list.get(i));
list.swap(indexA, indexB);
Collections.swap(expectedList, indexA, indexB);
assertTrue(list.size() == currentSize);
assertTrue(list.get(i) == expectedList.get(i));
list.swap(0, currentSize);
fail();
list.swap(currentSize, 0);
fail();
代码示例来源:origin: us.ihmc/ihmc-robotics-toolkit-test
@Test(timeout = 30000)
public void testSort()
{
YoPreallocatedList<YoInteger> list = new YoPreallocatedList<>(YoInteger.class, "Test", 10, new YoVariableRegistry("Test"));
list.add().set(-3);
list.add().set(20);
list.add().set(-10);
list.add().set(19);
list.add().set(50);
list.sort((o1, o2) -> NumberUtils.compare(o1.getIntegerValue(), o2.getIntegerValue()));
assertTrue(list.get(0).getValue() == -10);
assertTrue(list.get(1).getValue() == -3);
assertTrue(list.get(2).getValue() == 19);
assertTrue(list.get(3).getValue() == 20);
assertTrue(list.get(4).getValue() == 50);
}
代码示例来源:origin: us.ihmc/ihmc-robotics-toolkit
/**
* Removes the element at the specified position in this list.
* Shifts any subsequent elements to the left (subtracts one from their
* indices).
*
* @param i the index of the element to be removed
*/
@Override
public T remove(int i)
{
if (i == position.getIntegerValue())
{
remove();
return values[i];
}
rangeCheck(i);
T t = values[i];
while (i < position.getIntegerValue())
{
values[i] = values[++i];
}
// Do not throw away the removed element, put it at the end of the list instead.
values[position.getIntegerValue()] = t;
position.decrement();
return t;
}
代码示例来源:origin: us.ihmc/ihmc-robotics-toolkit
/** {@inheritDoc} */
@Override
public boolean containsAll(Collection<?> c)
{
for (Object o : c)
{
if (!contains(o))
return false;
}
return true;
}
代码示例来源:origin: us.ihmc/ihmc-robotics-toolkit-test
@Test(timeout = 30000)
public void testRemoveIndex()
{
int size = 10;
YoPreallocatedList<YoInteger> list = new YoPreallocatedList<>(YoInteger.class, "Test", size, new YoVariableRegistry("Test"));
for (int i = 0; i < size; i++)
{
list.add().set(i);
}
assertTrue(list.remove(8).getValue() == 8);
assertTrue(list.size() == size - 1);
assertTrue(list.remove(4).getValue() == 4);
assertTrue(list.size() == size - 2);
assertTrue(list.remove(2).getValue() == 2);
assertTrue(list.size() == size - 3);
assertTrue(list.remove(size - 4).getValue() == size - 1);
assertTrue(list.size() == size - 4);
}
代码示例来源:origin: us.ihmc/ihmc-robotics-toolkit
/**
* Sorts the array in place using {@link Arrays::sort}
* @param comparator to determine element ordering
*/
@Override
public void sort(Comparator<? super T> comparator)
{
if(size() == 0)
return;
Arrays.sort(values, 0, size(), comparator);
}
代码示例来源:origin: us.ihmc/ihmc-robotics-toolkit
/**
* Returns the last element of this list. If the list is empty, it returns {@code null}.
*
* @return the last element of this list.
*/
public T getLast()
{
if (isEmpty())
{
return null;
}
else
{
return values[position.getIntegerValue()];
}
}
代码示例来源:origin: us.ihmc/ihmc-robotics-toolkit
/** {@inheritDoc} */
@Override
public boolean contains(Object o)
{
for (int i = 0; i < size(); i++)
{
if(values[i].equals(o))
{
return true;
}
}
return false;
}
代码示例来源:origin: us.ihmc/ihmc-robotics-toolkit
/**
* Returns the elements in this list as array
*
* This method allocates a new array
*
* @return new array of length size();
*/
@Override
public T[] toArray()
{
@SuppressWarnings("unchecked")
T[] array = (T[]) Array.newInstance(clazz, size());
System.arraycopy(values, 0, array, 0, size());
return array;
}
代码示例来源:origin: us.ihmc/ihmc-robotics-toolkit
/** {@inheritDoc} */
@Override
public boolean equals(Object obj)
{
if (this == obj)
return true;
if (!(obj instanceof List))
return false;
List<?> other = (List<?>) obj;
if (size() != other.size())
return false;
for (int i = 0; i < size(); i++)
{
if (!values[i].equals(other.get(i)))
return false;
}
return true;
}
代码示例来源:origin: us.ihmc/ihmc-robotics-toolkit
/** {@inheritDoc} */
@Override
@SuppressWarnings("unchecked")
public <S> S[] toArray(S[] dest)
{
int size = size();
if (dest.length < size)
{
return (S[]) Arrays.copyOf(values, size, dest.getClass());
}
System.arraycopy(values, 0, dest, 0, size);
if (dest.length > size)
dest[size] = null;
return dest;
}
代码示例来源:origin: us.ihmc/ihmc-robotics-toolkit
private void rangeCheck(int index)
{
if(index < 0 || index > this.position.getIntegerValue())
{
throw new ArrayIndexOutOfBoundsException("Position is not valid in the list, size is " + size() + ", requested element is " + index);
}
}
代码示例来源:origin: us.ihmc/ihmc-robotics-toolkit
@Override
public String toString()
{
String s = "";
s += clazz.getSimpleName();
s += " pos: " + position.getIntegerValue();
s += " [";
for (int i = 0; i < size(); i++)
{
if (i > 0)
s += ", ";
s += values[i].toString();
}
s += "]";
return s;
}
内容来源于网络,如有侵权,请联系作者删除!