jimu-decompiled/sources/com/ubt/jimu/controller/data/config/JockstickConfig.java
2025-05-13 19:24:51 +02:00

294 lines
9.0 KiB
Java

package com.ubt.jimu.controller.data.config;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamImplicit;
import com.thoughtworks.xstream.annotations.XStreamOmitField;
import com.ubt.jimu.base.data.CtrlMotionType;
import com.ubt.jimu.controller.data.widget.JockstickData;
import com.ubt.jimu.controller.data.widget.JockstickDataConverter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@XStreamAlias("JockstickConfig")
/* loaded from: classes.dex */
public class JockstickConfig extends WidgetConfig<JockstickData> {
private int index;
@XStreamOmitField
private Map<Integer, Wheel> mTempWheelMap;
private CtrlMotionType motionType;
private JockType type;
@XStreamImplicit(itemFieldName = JockstickDataConverter.WHEEL)
private List<Wheel> wheelList;
public enum JockType {
twoServo,
treeServo,
fourServo,
sixServo,
none
}
public JockstickConfig() {
this.type = JockType.twoServo;
this.motionType = CtrlMotionType.servo;
}
static /* synthetic */ int a(Wheel wheel, Wheel wheel2) {
if (wheel == null && wheel2 == null) {
return 0;
}
if (wheel == null) {
return -1;
}
if (wheel2 == null) {
return 1;
}
return wheel.getPosition() - wheel2.getPosition();
}
private boolean checkValid(int i) {
List<Wheel> list = this.wheelList;
if (list == null || list.size() < i) {
return false;
}
for (Wheel wheel : this.wheelList) {
if (wheel == null || wheel.getId() <= 0) {
return false;
}
}
return true;
}
private void copyList2Map(List<Wheel> list, Map<Integer, Wheel> map) {
for (Wheel wheel : list) {
if (wheel != null) {
map.put(Integer.valueOf(wheel.getPosition()), wheel);
}
}
}
private void sortWheelList(List<Wheel> list) {
Collections.sort(list, new Comparator() { // from class: com.ubt.jimu.controller.data.config.a
@Override // java.util.Comparator
public final int compare(Object obj, Object obj2) {
return JockstickConfig.a((Wheel) obj, (Wheel) obj2);
}
});
}
public void checkEngineExist(int i) {
List<Wheel> list;
if (i == 0 || (list = this.wheelList) == null || list.size() <= 0) {
return;
}
for (Wheel wheel : new ArrayList(this.wheelList)) {
if (wheel != null && wheel.getId() == i) {
this.wheelList.remove(wheel);
this.mTempWheelMap.remove(Integer.valueOf(wheel.getPosition()));
return;
}
}
}
public JockstickConfig cloneJockstickConfig() {
JockstickConfig jockstickConfig = new JockstickConfig();
List<Wheel> list = this.wheelList;
if (list != null && list.size() > 0) {
ArrayList arrayList = new ArrayList(this.wheelList.size());
Iterator<Wheel> it = this.wheelList.iterator();
while (it.hasNext()) {
arrayList.add(it.next());
}
jockstickConfig.setWheelList(arrayList);
}
jockstickConfig.setType(this.type);
jockstickConfig.setMotionType(this.motionType);
jockstickConfig.setIndex(this.index);
return jockstickConfig;
}
public void emptyWheelList() {
List<Wheel> list = this.wheelList;
if (list != null) {
list.clear();
}
Map<Integer, Wheel> map = this.mTempWheelMap;
if (map != null) {
map.clear();
}
}
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof JockstickConfig)) {
return false;
}
JockstickConfig jockstickConfig = (JockstickConfig) obj;
if (this.type != jockstickConfig.type || this.motionType != jockstickConfig.motionType) {
return false;
}
List<Wheel> list = this.wheelList;
if (list == null) {
return jockstickConfig.wheelList == null;
}
sortWheelList(list);
List<Wheel> list2 = jockstickConfig.wheelList;
if (list2 == null) {
return false;
}
sortWheelList(list2);
return this.wheelList.equals(jockstickConfig.wheelList);
}
public int getIndex() {
return this.index;
}
public CtrlMotionType getMotionType() {
return this.motionType;
}
public List<Integer> getServoList() {
ArrayList arrayList = new ArrayList();
List<Wheel> list = this.wheelList;
if (list != null && list.size() > 0) {
for (Wheel wheel : this.wheelList) {
if (wheel != null && wheel.getId() > 0) {
arrayList.add(Integer.valueOf(wheel.getId()));
}
}
}
return arrayList;
}
public JockType getType() {
return this.type;
}
public Wheel getWheel(int i) {
Map<Integer, Wheel> map;
List<Wheel> list;
if (this.mTempWheelMap == null && (list = this.wheelList) != null && list.size() > 0) {
this.mTempWheelMap = new HashMap(this.wheelList.size());
copyList2Map(this.wheelList, this.mTempWheelMap);
}
if (i <= 0 || (map = this.mTempWheelMap) == null) {
return null;
}
return map.get(Integer.valueOf(i));
}
public List<Wheel> getWheelList() {
return this.wheelList;
}
public int hashCode() {
JockType jockType = this.type;
int hashCode = (jockType != null ? jockType.hashCode() : 0) * 31;
CtrlMotionType ctrlMotionType = this.motionType;
int hashCode2 = (hashCode + (ctrlMotionType != null ? ctrlMotionType.hashCode() : 0)) * 31;
List<Wheel> list = this.wheelList;
return hashCode2 + (list != null ? list.hashCode() : 0);
}
public boolean isOK() {
JockType jockType = this.type;
if (jockType == JockType.none) {
return false;
}
if (jockType == JockType.twoServo) {
return checkValid(2);
}
if (jockType == JockType.fourServo) {
return checkValid(4);
}
if (jockType == JockType.sixServo) {
return checkValid(6);
}
return false;
}
public void putWheel(int i, Wheel wheel) {
if (this.mTempWheelMap == null) {
this.mTempWheelMap = new HashMap();
}
if (this.wheelList == null) {
this.wheelList = new ArrayList();
}
if (i > 0) {
this.mTempWheelMap.put(Integer.valueOf(i), wheel);
List<Wheel> list = this.wheelList;
if (list != null && list.size() > 0) {
for (Wheel wheel2 : new ArrayList(this.wheelList)) {
if (wheel2.getId() == wheel.getId() || wheel2.getPosition() == i) {
this.wheelList.remove(wheel2);
}
}
}
this.wheelList.add(wheel);
}
}
public void setIndex(int i) {
this.index = i;
}
public void setMotionType(CtrlMotionType ctrlMotionType) {
this.motionType = ctrlMotionType;
}
public void setType(JockType jockType) {
this.type = jockType;
}
public void setWheelList(List<Wheel> list) {
this.wheelList = list;
if (list == null || list.size() <= 0) {
Map<Integer, Wheel> map = this.mTempWheelMap;
if (map != null) {
map.clear();
return;
}
return;
}
if (this.mTempWheelMap == null) {
this.mTempWheelMap = new HashMap(list.size());
for (Wheel wheel : list) {
if (wheel != null) {
this.mTempWheelMap.put(Integer.valueOf(wheel.getPosition()), wheel);
}
}
}
}
@Override // com.ubt.jimu.controller.data.config.WidgetConfig
public String toString() {
return "JockstickConfig{type=" + this.type + ", motionType=" + this.motionType + ", index=" + this.index + ", wheelList=" + this.wheelList + "} " + super.toString();
}
/* JADX WARN: Can't rename method to resolve collision */
@Override // com.ubt.jimu.controller.data.config.WidgetConfig
public JockstickData encapData() {
JockstickData jockstickData = new JockstickData();
jockstickData.setConfig(this);
return jockstickData;
}
public JockstickConfig(String str, JockType jockType, CtrlMotionType ctrlMotionType) {
super(str);
this.type = JockType.twoServo;
this.motionType = CtrlMotionType.servo;
this.motionType = ctrlMotionType;
this.type = jockType;
}
}