好贷网好贷款

Code Fragment-通过位运算来表达状态

发布时间:2016-12-4 10:05:12 编辑:www.fx114.net 分享查询网我要评论
本篇文章主要介绍了"Code Fragment-通过位运算来表达状态",主要涉及到Code Fragment-通过位运算来表达状态方面的内容,对于Code Fragment-通过位运算来表达状态感兴趣的同学可以参考一下。

可以用位运算来标记不同的状态,使用不同的移位能够保证它们状态的不同如下, 本例子参考自Android code/frameworks/base/core/java/android/app/DownloadManager.java /** * Value of [email protected] #COLUMN_STATUS} when the download is waiting to start. */ public final static int STATUS_PENDING = 1 << 0; /** * Value of [email protected] #COLUMN_STATUS} when the download is currently running. */ public final static int STATUS_RUNNING = 1 << 1; /** * Value of [email protected] #COLUMN_STATUS} when the download is waiting to retry or resume. */ public final static int STATUS_PAUSED = 1 << 2; /** * Value of [email protected] #COLUMN_STATUS} when the download has successfully completed. */ public final static int STATUS_SUCCESSFUL = 1 << 3; /** * Value of [email protected] #COLUMN_STATUS} when the download has failed (and will not be retried). */ public final static int STATUS_FAILED = 1 << 4; 判断的时候,通过&运算,如下: if ((mStatusFlags & STATUS_PENDING) != 0) { parts.add(statusClause("=", Downloads.Impl.STATUS_PENDING)); } if ((mStatusFlags & STATUS_RUNNING) != 0) { parts.add(statusClause("=", Downloads.Impl.STATUS_RUNNING)); } if ((mStatusFlags & STATUS_PAUSED) != 0) { parts.add(statusClause("=", Downloads.Impl.STATUS_PAUSED_BY_APP)); parts.add(statusClause("=", Downloads.Impl.STATUS_WAITING_TO_RETRY)); parts.add(statusClause("=", Downloads.Impl.STATUS_WAITING_FOR_NETWORK)); parts.add(statusClause("=", Downloads.Impl.STATUS_QUEUED_FOR_WIFI)); } if ((mStatusFlags & STATUS_SUCCESSFUL) != 0) { parts.add(statusClause("=", Downloads.Impl.STATUS_SUCCESS)); } if ((mStatusFlags & STATUS_FAILED) != 0) { parts.add("(" + statusClause(">=", 400) + " AND " + statusClause("<", 600) + ")"); } 其他的优点,移位速度比较快,其他暂不清楚。

上一篇:leetcode解析回文子串拆分
下一篇:c#中进行读写配置文件的方法

相关文章

相关评论