本文整理汇总了Java中com.heaven7.java.base.util.SparseArray类的典型用法代码示例。如果您正苦于以下问题:Java SparseArray类的具体用法?Java SparseArray怎么用?Java SparseArray使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SparseArray类属于com.heaven7.java.base.util包,在下文中一共展示了SparseArray类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addMutexState
import com.heaven7.java.base.util.SparseArray; //导入依赖的package包/类
@Override
public final void addMutexState(int[] groupState) {
if (groupState == null || groupState.length == 0) {
throw new IllegalArgumentException();
}
if (mMutexMap == null) {
mMutexMap = new SparseArray<int[]>(4);
}
int key = 0;
for (int s : groupState) {
key |= s;
}
final int[] val = mMutexMap.get(key);
if (val == null) {
mMutexMap.put(key, groupState);
}
}
示例2: getTargetStates
import com.heaven7.java.base.util.SparseArray; //导入依赖的package包/类
@Override
public final List<S> getTargetStates(int states, List<S> outStates) {
if (outStates == null) {
outStates = new ArrayList<S>();
}
final SparseArray<S> map = this.mStateMap;
int maxKey;
S s;
for (; states > 0;) {
maxKey = max2K(states);
s = map.get(maxKey);
if (s != null) {
outStates.add(s);
}
states -= maxKey;
}
return outStates;
}
示例3: exit0
import com.heaven7.java.base.util.SparseArray; //导入依赖的package包/类
private void exit0(int singleState, boolean byMutex) {
final SparseArray<S> stateMap = getStateMap();
S state = stateMap.get(singleState);
// no cache ? remove from cache
if (!isStateCacheEnabled()) {
stateMap.remove(singleState);
mCachedState &= ~singleState;
} else {
mCachedState |= singleState;
}
final P p = getMerger().merge(state.getStateParameter(), getStateParameter());
state.setStateParameter(p);
state.exit(byMutex ? AbstractState.FLAG_MUTEX : 0);
dispatchStateCallback(ACTION_EXIT, singleState, state, null);
state.onDetach();
}
示例4: dispose
import com.heaven7.java.base.util.SparseArray; //导入依赖的package包/类
public void dispose() {
final SparseArray<S> map = getStateMap();
getFlagsInternal(mCurrentStates, sTempFlags);
for(int state : sTempFlags){
final S s = map.get(state);
//TODO should destroy foreground state.?
s.exit(0);
s.onDetach();
s.dispose();
map.remove(state);
// System.out.println("dispose : " + s.toString());
}
sTempFlags.clear();
this.mCurrentStates = 0;
this.mCachedState = 0;
this.mParam = null;
}
示例5: getTargetStates
import com.heaven7.java.base.util.SparseArray; //导入依赖的package包/类
private List<S> getTargetStates(int targetStates, List<S> outStates) {
if (targetStates == 0) {
return null;
}
if(outStates == null){
outStates = new ArrayList<S>();
}
final SparseArray<S> stateMap = getStateMap();
getFlagsInternal(targetStates, sTempFlags);
for(int state : sTempFlags){
S s = stateMap.get(state);
if(s != null){
s.setId(state);
outStates.add(s);
}else{
System.err.println("[WARN] StateGroup >>> called [ getTargetStates()] : state not exit. state =" + state);
}
}
sTempFlags.clear();
return outStates;
}
示例6: toJson
import com.heaven7.java.base.util.SparseArray; //导入依赖的package包/类
/**
* convert the target object to json. currently support simple object, array , list. SparseArray
* @param t the object. must have annotation {@linkplain JsonAdapter}
* @return the json string.
* @see SparseArray
*/
public static String toJson(Object t) {
GsonBuilder builder = new GsonBuilder()
.setVersion(GlobalSetting.getDefault().getGsonVersion());
if(t instanceof SparseArray){
SparseArray sa = (SparseArray) t;
if(sa.size() == 0){
return "{}";
}
Class<?> clazz = sa.valueAt(0).getClass();
/* builder.registerTypeAdapter(
TypeToken.getParameterized(SparseArray.class, clazz).getType(),
new SparseArrayTypeAdapter<>(TypeHandler.getTypeAdapter(clazz)));*/
builder.registerTypeAdapter(SparseArray.class,
new SparseArrayTypeAdapter<>(TypeHandler.getTypeAdapter(clazz)));
}
return builder.create().toJson(t);
}
示例7: write
import com.heaven7.java.base.util.SparseArray; //导入依赖的package包/类
@Override
public void write(JsonWriter out, GsonProperty property, Object value) throws IOException {
final Class<?> simpleType = property.getType();
out.beginObject();
if(value != null) {
final SparseArray sa = (SparseArray) value;
if(simpleType.isPrimitive() || isBoxedClass(simpleType)){
for (int size = sa.size(), i = size - 1; i >= 0; i--) {
out.name(sa.keyAt(i) + "");
writePrimitiveOrItsBox(out, simpleType, sa.valueAt(i));
}
}else {
TypeAdapter adapter = getTypeAdapter(simpleType);
for (int size = sa.size(), i = size - 1; i >= 0; i--) {
out.name(sa.keyAt(i) + "");
adapter.write(out, sa.valueAt(i));
}
}
}
out.endObject();
}
示例8: newTestGsonBean
import com.heaven7.java.base.util.SparseArray; //导入依赖的package包/类
private static TestGsonBean newTestGsonBean() {
List<Car3> list = new ArrayList<>();
SparseArray<Car3> map = new SparseArray<>();
Car3[] arr = new Car3[3];
for(int i = 0 ; i < 3 ; i++){
Car3 car = new Car3();
car.setMark("AUDI");
car.setModel(2014); //2,1
car.setType("DIESEL");
car.setMaker("AUDI GERMANY");
car.setCost(i * 100);
car.getColors().add("GREY");
car.getColors().add("BLACK");
car.getColors().add("WHITE");
list.add(car);
map.put(i, car);
arr[i] = car;
}
TestGsonBean tl = new TestGsonBean();
tl.setList(list);
tl.setCarMap(map); //null时,map不参与序列化输出
tl.setCarsArr(arr);
tl.setCar(arr[0]);
return tl;
}
示例9: TestBean
import com.heaven7.java.base.util.SparseArray; //导入依赖的package包/类
/**
* get the actual type .no matter is array, list or primitive .
* <p>if you use reflect to set property. you should care, here is a demo:</p>
* <code><pre>
TestBean bean = new TestBean(null);
Method setArray = TestBean.class.getMethod("setArray",
Array.newInstance(String.class,0).getClass());
setArray.invoke(bean, (Object)new String[]{"123", "456"});
* </pre></code>
* @return the actual type.
* @since 1.0.7
*/
public Class<?> getActualType(){
switch (getComplexType()){
case FieldFlags.COMPLEX_ARRAY:
return Array.newInstance(getType(), 0).getClass();
case FieldFlags.COMPLEX_LIST:
return List.class;
case FieldFlags.COMPLEX_SPARSE_ARRAY:
return SparseArray.class;
default:
return getType();
}
}
示例10: SimpleController
import com.heaven7.java.base.util.SparseArray; //导入依赖的package包/类
public SimpleController() {
this.mStateMap = new SparseArray<S>();
this.mCallback = new StateGroup.Callback<S, P>() {
@Override
public ParameterMerger<P> getMerger() {
return mMerger;
}
@Override
public StateFactory<S, P> getStateFactory() {
return mFactory;
}
@Override
public SparseArray<S> getStateMap() {
return mStateMap;
}
@Override
public List<S> ensureAndGetTempList() {
if (mTempStates == null) {
mTempStates = new ArrayList<>(8);
}
return mTempStates;
}
};
this.mGroup = new StateGroup<S, P>(this, mCallback);
}
示例11: dispose
import com.heaven7.java.base.util.SparseArray; //导入依赖的package包/类
@Override
public final void dispose() {
// destroy foreground states.
if (mGlobalGroup != null) {
mGlobalGroup.dispose();
}
mGroup.dispose();
// destroy back/cache state. and clear
final SparseArray<S> map = this.mStateMap;
for (int size = map.size(), i = size - 1; i >= 0; i--) {
map.valueAt(i).dispose();
}
map.clear();
synchronized (this) {
if (mDelayMessages != null) {
for (MessageInfo info : mDelayMessages) {
info.msg.recycleUnchecked();
}
mDelayMessages.clear();
}
}
// clean up controller
this.mOwner = null;
}
示例12: removeForgroundStateFromTeam
import com.heaven7.java.base.util.SparseArray; //导入依赖的package包/类
public void removeForgroundStateFromTeam(int states, P teamP){
final int share = mCurrentStates & states;
if(share == 0){
return ;
}
final boolean cacheEnabled = isStateCacheEnabled();
//handle state exit
final SparseArray<S> stateMap = getStateMap();
final List<S> tempList = mCallback.ensureAndGetTempList();
getForegroundStates(share, tempList);
for (S s : tempList) {
s.setTeamParameter(teamP);
s.exit(AbstractState.FLAG_TEAM);
s.clearOnceFlags();
s.onDetach();
//remove state instance if need
if(!cacheEnabled){
stateMap.remove(s.getId());
}
}
tempList.clear();
//handle current state and cache state.
mCurrentStates &= ~ share;
if(cacheEnabled){
mCachedState |= share;
}else{
mCachedState &= ~share;
}
}
示例13: enter0
import com.heaven7.java.base.util.SparseArray; //导入依赖的package包/类
private void enter0(int singleState, S state) {
if (state == null) {
throw new IllegalStateException("create state failed. Are you forget to create State " + "for state_flag = "
+ singleState + " by StateFactory? ");
}
// cache state
mCachedState &= ~singleState;
getStateMap().put(singleState, state);
final P p = getMerger().merge(state.getStateParameter(), getStateParameter());
state.setStateParameter(p);
state.onAttach(getController());
state.setId(singleState);
state.enter(0);
//dispatch callback
dispatchStateCallback(ACTION_ENTER, singleState, state, null);
state.clearOnceFlags();
// handle mutex states
int[] mutexStates = getController().getMutexState(singleState);
if (mutexStates != null) {
final SparseArray<S> stateMap = getStateMap();
int oppositeState = 0;
for (int s : mutexStates) {
// state is not the main state.
if (s != singleState && stateMap.get(s) != null) {
oppositeState |= s;
exit0(s, true);
}
}
this.mCurrentStates &= ~oppositeState;
// System.out.println("mutex state occurs. Main state : " +
// singleState + " , Mutex states : "+
// Arrays.toString(mutexStates));
// System.out.println("mutex state occurs. after adjust current
// state : " + mCurrentStates);
}
}
示例14: destroyStateCache
import com.heaven7.java.base.util.SparseArray; //导入依赖的package包/类
/** destroy state cache without current states. */
public void destroyStateCache() {
if (mCachedState > 0) {
final SparseArray<S> map = getStateMap();
getFlagsInternal(mCachedState, sTempFlags);
for(int state : sTempFlags){
map.remove(state);
// System.out.println("destroy state = " + state);
}
sTempFlags.clear();
mCachedState = 0;
} /*
* else{ System.out.println("no state cache..."); }
*/
}
示例15: clearStateParameter
import com.heaven7.java.base.util.SparseArray; //导入依赖的package包/类
/**
* clear state parameter
* @param includeCachedState true to include cached state.
* @since 1.1.5
*/
public void clearStateParameter(boolean includeCachedState) {
final SparseArray<S> map = getStateMap();
getFlagsInternal(includeCachedState ? mCurrentStates | mCachedState : mCurrentStates, sTempFlags);
for(int state : sTempFlags){
map.get(state).setStateParameter(null);
}
sTempFlags.clear();
}