当前位置: 首页>>代码示例>>Java>>正文


Java SparseArray类代码示例

本文整理汇总了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);
	}
}
 
开发者ID:LightSun,项目名称:Mvcs,代码行数:18,代码来源:SimpleController.java

示例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;
}
 
开发者ID:LightSun,项目名称:Mvcs,代码行数:19,代码来源:SimpleController.java

示例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();
}
 
开发者ID:LightSun,项目名称:Mvcs,代码行数:17,代码来源:StateGroup.java

示例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;
}
 
开发者ID:LightSun,项目名称:Mvcs,代码行数:19,代码来源:StateGroup.java

示例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;
}
 
开发者ID:LightSun,项目名称:Mvcs,代码行数:22,代码来源:StateGroup.java

示例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);
}
 
开发者ID:LightSun,项目名称:data-mediator,代码行数:25,代码来源:GsonSupport.java

示例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();
}
 
开发者ID:LightSun,项目名称:data-mediator,代码行数:22,代码来源:TypeHandler.java

示例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;
}
 
开发者ID:LightSun,项目名称:data-mediator,代码行数:27,代码来源:GsonSinceUntilAnnotationsExample.java

示例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();
     }
}
 
开发者ID:LightSun,项目名称:data-mediator,代码行数:28,代码来源:Property.java

示例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);
}
 
开发者ID:LightSun,项目名称:Mvcs,代码行数:29,代码来源:SimpleController.java

示例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;
}
 
开发者ID:LightSun,项目名称:Mvcs,代码行数:28,代码来源:SimpleController.java

示例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;
	}
}
 
开发者ID:LightSun,项目名称:Mvcs,代码行数:30,代码来源:StateGroup.java

示例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);
	}
}
 
开发者ID:LightSun,项目名称:Mvcs,代码行数:38,代码来源:StateGroup.java

示例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..."); }
		 */
}
 
开发者ID:LightSun,项目名称:Mvcs,代码行数:16,代码来源:StateGroup.java

示例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();
}
 
开发者ID:LightSun,项目名称:Mvcs,代码行数:14,代码来源:StateGroup.java


注:本文中的com.heaven7.java.base.util.SparseArray类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。