ArrayList

1. The structure of ArrayList

2. What is ArrayList?
  • An ArrayList is a data structure that behaves like a computerarray but also implements the ability todynamically grow the size of the array as needed. ArrayList structure can grow and shrink the size of the array in response to the addition or deletion of elements.
  • Using an ArrayList provides a program with the ability to access data objects with an index number instantly instead of having to walk through an entire sequence of data to find an address.
  • ArrayList is not thread-safe, it is used in single thread.
3. The definition of ArrayList

java.lang.Object --> java.util.AbstractCollection<E> --> java.util.AbstractList<E>  --> java.util.ArrayList<E>

public class ArrayList<E> extends AbstractList<E> implements List<E>, RandomAccess, Cloneable, java.io.Serializable

  • ArrayList extends AbstractList and implements List.
  • ArrayList implement RandomAccess(nothing), it support random access function.
  • ArrayList implement Cloneable(Object.clone), it can be clone.
  • ArrayList implement java.io.Serializable interface, which meansArrayList supportserialization.
4. Private property

private transient Object[] elementData;   // Array

private int size;         // The size of the ArrayList.

transient

             When JVM in its life cycle, object exist. Java Serialization make the object can be stored  after JVM stop running.

  • transient
  • transient variable value can not be saved after object serilized.
  • transient can only be used to restrict variable, not method and class. Local variable can not be defined as transient.
  • static variable can not be serialized no matter it is transient or not.

 1 public class UserInfo implements Serializable {
 2     private static final long serialVersionUID = 996890129747019948L;
 3     private String name;
 4     private transient String psw;
 5 
 6     public UserInfo(String name, String psw) {
 7         this.name = name;
 8         this.psw = psw;
 9     }
10 
11     public String toString() {
12         return "name=" + name + ", psw=" + psw;
13     }
14 }
15 
16 public class TestTransient {
17     public static void main(String[] args) {
18         UserInfo userInfo = new UserInfo("Jone", "123456");
19         System.out.println(userInfo);
20         try {
21             // Serialization,transient property can not be serialized
22             ObjectOutputStream o = new ObjectOutputStream(new FileOutputStream(
23                     "UserInfo.out"));
24             o.writeObject(userInfo);
25             o.close();
26         } catch (Exception e) {
27             // TODO: handle exception
28             e.printStackTrace();
29         }
30         try {
31             // read UserInfo.out
32             ObjectInputStream in = new ObjectInputStream(new FileInputStream(
33                     "UserInfo.out"));
34             UserInfo readUserInfo = (UserInfo) in.readObject();
35             // read psw is null
36             System.out.println(readUserInfo.toString());
37         } catch (Exception e) {
38             // TODO: handle exception
39             e.printStackTrace();
40         }
41     }
42 }

5. Constructor in ArrayList

ArrayList() // 10

ArrayList(int capacity)

ArrayList(Collection<? extends E> collection)

6.  Arrays.copyof()  vs  System.arraycopy()

public static <T,U> T[] copyOf(U[] original, int newLength, Class<? extends T[]> newType) {                                                                                                                             
      T[] copy = ((Object)newType == (Object)Object[].class)                                                                                                                                                                                               
        ? (T[]) new Object[newLength]                                                                                                                                                                                                                                       
          : (T[]) Array.newInstance(newType.getComponentType(), newLength);                                                                                                                                                                    
      System.arraycopy(original, 0, copy, 0,                                                                                                                                                                                                                              
                       Math.min(original.length, newLength));                                                                                                                                                                                                          
      return copy;                                                                                                                                                                                                                                                               
  }                                                                                                                                                                                                                                                                                      
 

Arrays.copyof() create a new Array with lengthnewLength, then callSystem.arraycopy(), copy the elements from the originalArrays to newArrays.

7. Functions in ArrayList

// Collection中定义的API
boolean             add(E object)
boolean             addAll(Collection<? extends E> collection)
void                     clear()
boolean             contains(Object object)
boolean             containsAll(Collection<?> collection)
boolean             equals(Object object)
int                        hashCode()
boolean             isEmpty()
Iterator<E>        iterator()
boolean             remove(Object object)
boolean             removeAll(Collection<?> collection)
boolean             retainAll(Collection<?> collection)
int                       size()
<T> T[]               toArray(T[] array)
Object[]              toArray()


// AbstractCollection中定义的API
void                add(int location, E object)
boolean        addAll(int location, Collection<? extends E> collection)
E                    get(int location)
int                  indexOf(Object object)
int                  lastIndexOf(Object object)
ListIterator<E>     listIterator(int location)
ListIterator<E>     listIterator()
E                   remove(int location)
E                   set(int location, E object)
List<E>        subList(int start, int end)



// ArrayList新增的API
Object             clone()
void                 ensureCapacity(int minimumCapacity)  // Every time add one element , the capacity will enlarge to (oldcapacity*3/2)+1
void                 trimToSize()
void                 removeRange(int fromIndex, int toIndex)



内容概要:本文详细介绍了如何利用Simulink进行自动代码生成,在STM32平台上实现带57次谐波抑制功能的霍尔场定向控制(FOC)。首先,文章讲解了所需的软件环境准备,包括MATLAB/Simulink及其硬件支持包的安装。接着,阐述了构建永磁同步电机(PMSM)霍尔FOC控制模型的具体步骤,涵盖电机模型、坐标变换模块(如Clark和Park变换)、PI调节器、SVPWM模块以及用于抑制特定谐波的陷波器的设计。随后,描述了硬件目标配置、代码生成过程中的注意事项,以及生成后的C代码结构。此外,还讨论了霍尔传感器的位置估算、谐波补偿器的实现细节、ADC配置技巧、PWM死区时间和换相逻辑的优化。最后,分享了一些实用的工程集成经验,并推荐了几篇有助于深入了解相关技术和优化控制效果的研究论文。 适合人群:从事电机控制系统开发的技术人员,尤其是那些希望掌握基于Simulink的自动代码生成技术,以提高开发效率和控制精度的专业人士。 使用场景及目标:适用于需要精确控制永磁同步电机的应用场合,特别是在面对高次谐波干扰导致的电流波形失真问题时。通过采用文中提供的解决方案,可以显著改善系统的稳定性和性能,降低噪声水平,提升用户体验。 其他说明:文中不仅提供了详细的理论解释和技术指导,还包括了许多实践经验教训,如霍尔传感器处理、谐波抑制策略的选择、代码生成配置等方面的实际案例。这对于初学者来说是非常宝贵的参考资料。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值