📄 wakeupindexedlist.java
字号:
Object data[] = (Object[])java.lang.reflect.Array.newInstance(componentType, s); System.arraycopy(elementData, idx, data, 0, s); return data; } /** * Trims the capacity of this <tt>ArrayList</tt> instance to be the * list's current size. An application can use this operation to minimize * the storage of an <tt>ArrayList</tt> instance. */ synchronized final void trimToSize() { if (elementData.length > size) { Object oldData[] = elementData; elementData = (WakeupCondition[])java.lang.reflect.Array.newInstance( componentType, size); System.arraycopy(oldData, 0, elementData, 0, size); } } // Positional Access Operations /** * Returns the element at the specified position in this list. * * @param index index of element to return. * @return the element at the specified position in this list. * @throws IndexOutOfBoundsException if index is out of range <tt>(index * < 0 || index >= size())</tt>. */ synchronized final Object get(int index) { return elementData[index]; } /** * Replaces the element at the specified position in this list with * the specified element. * * @param index index of element to replace. * @param o element to be stored at the specified position. * @return the element previously at the specified position. * @throws IndexOutOfBoundsException if index out of range * <tt>(index < 0 || index >= size())</tt>. */ synchronized final void set(int index, WakeupCondition o) { WakeupCondition oldElm = elementData[index]; if (oldElm != null) { oldElm.listIdx[oldElm.behav.getIdxUsed(univ)][listType] = -1; } elementData[index] = o; int univIdx = o.behav.getIdxUsed(univ); if (debug) { if (o.listIdx[univIdx][listType] != -1) { System.err.println("Illegal use of UnorderIndexedList idx in set " + o.listIdx[univIdx][listType]); Thread.dumpStack(); } } o.listIdx[univIdx][listType] = index; isDirty = true; } /** * Appends the specified element to the end of this list. * It is the user responsible to ensure that the element add is of * the same type as array componentType. * * @param o element to be appended to this list. */ synchronized final void add(WakeupCondition o) { if (elementData.length == size) { WakeupCondition oldData[] = elementData; elementData = (WakeupCondition[])java.lang.reflect.Array.newInstance( componentType, (size << 1)); System.arraycopy(oldData, 0, elementData, 0, size); } int univIdx = o.behav.getIdxUsed(univ); // System.err.println(this + " add " + o + " univ " + univIdx); if (debug) { int idx = o.listIdx[univIdx][listType]; if (idx >= 0) { if (elementData[idx] != o) { System.err.println("Illegal use of UnorderIndexedList idx in add " + idx); Thread.dumpStack(); } } } int idx = size++; elementData[idx] = o; o.listIdx[univIdx][listType] = idx; isDirty = true; } /** * Removes the element at the specified position in this list. * Replace the removed element by the last one. * * @param index the index of the element to removed. * @throws IndexOutOfBoundsException if index out of range <tt>(index * < 0 || index >= size())</tt>. */ synchronized final void remove(int index) { WakeupCondition elm = elementData[index]; int univIdx = elm.behav.getIdxUsed(univ); if (debug) { if (elm.listIdx[univIdx][listType] != index) { System.err.println("Inconsistent idx in remove, expect " + index + " actual " + elm.listIdx[univIdx][listType]); Thread.dumpStack(); } } elm.listIdx[univIdx][listType] = -1; size--; if (index != size) { elm = elementData[size]; elm.listIdx[univIdx][listType] = index; elementData[index] = elm; } elementData[size] = null; isDirty = true; /* if ((cloneData != null) && (index < cloneData.length)) { cloneData[index] = null; // for gc } */ } /** * Removes the element at the last position in this list. * @return The element remove * @throws IndexOutOfBoundsException if array is empty */ synchronized final Object removeLastElement() { WakeupCondition elm = elementData[--size]; elementData[size] = null; elm.listIdx[elm.behav.getIdxUsed(univ)][listType] = -1; isDirty = true; /* if ((cloneData != null) && (size < cloneData.length)) { cloneData[size] = null; // for gc } */ return elm; } /** * Removes the specified element in this list. * Replace the removed element by the last one. * * @param o the element to removed. * @return true if object remove * @throws IndexOutOfBoundsException if index out of range <tt>(index * < 0 || index >= size())</tt>. */ synchronized final boolean remove(WakeupCondition o) { int univIdx = o.behav.getIdxUsed(univ); int idx = o.listIdx[univIdx][listType]; // System.err.println(this + " remove " + o + " univ " + univIdx); if (idx >= 0) { // Object in the container if (debug) { if (o != elementData[idx]) { System.err.println(" Illegal use of UnorderIndexedList in remove expect " + o + " actual " + elementData[idx] + " idx = " + idx); Thread.dumpStack(); } } size--; if (idx != size) { WakeupCondition elm = elementData[size]; elementData[idx] = elm; elm.listIdx[elm.behav.getIdxUsed(univ)][listType] = idx; } elementData[size] = null; o.listIdx[univIdx][listType] = -1; isDirty = true; return true; } return false; } /** * Removes all of the elements from this list. The list will * be empty after this call returns. */ synchronized final void clear() { WakeupCondition o; for (int i = size-1; i >= 0; i--) { o = elementData[i]; o.listIdx[o.behav.getIdxUsed(univ)][listType] = -1; elementData[i] = null; // Let gc do its work } size = 0; isDirty = true; } synchronized final void clearMirror() { if (cloneData != null) { for (int i = cloneData.length-1; i >= 0; i--) { // don't set index to -1 since the original // copy is using this. cloneData[i] = null; // Let gc do its work } } cloneSize = 0; isDirty = true; } final Class getComponentType() { return componentType; } synchronized public String toString() { StringBuffer sb = new StringBuffer(hashCode() + " Size = " + size + "["); int len = size-1; Object obj; for (int i=0; i < size; i++) { obj = elementData[i]; if (obj != null) { sb.append(elementData[i].toString()); } else { sb.append("NULL"); } if (i != len) { sb.append(", "); } } sb.append("]"); return sb.toString(); } /** * Save the state of the <tt>ArrayList</tt> instance to a stream (that * is, serialize it). * * @serialData The length of the array backing the <tt>ArrayList</tt> * instance is emitted (int), followed by all of its elements * (each an <tt>Object</tt>) in the proper order. */ private synchronized void writeObject(java.io.ObjectOutputStream s) throws java.io.IOException{ // Write out element count, and any hidden stuff s.defaultWriteObject(); // Write out array length s.writeInt(elementData.length); // Write out all elements in the proper order. for (int i=0; i<size; i++) s.writeObject(elementData[i]); } /** * Reconstitute the <tt>ArrayList</tt> instance from a stream (that is, * deserialize it). */ private synchronized void readObject(java.io.ObjectInputStream s) throws java.io.IOException, ClassNotFoundException { // Read in size, and any hidden stuff s.defaultReadObject(); // Read in array length and allocate array int arrayLength = s.readInt(); elementData = (WakeupCondition[])java.lang.reflect.Array.newInstance( componentType, arrayLength); // Read in all elements in the proper order. for (int i=0; i<size; i++) elementData[i] = (WakeupCondition) s.readObject(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -