DataSetObservable,Observable<T>,DataSetObserver源码注释翻译
来源:互联网 发布:批图软件下载 编辑:程序博客网 时间:2024/06/06 07:31
类结构图:
/* * Copyright (C) 2007 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package android.database;/** * Receives call backs when a data set has been changed, or made invalid. The typically data sets * that are observed are {@link Cursor}s or {@link android.widget.Adapter}s. * DataSetObserver must be implemented by objects which are added to a DataSetObservable. */public abstract class DataSetObserver { /** * This method is called when the entire data set has changed, * most likely through a call to {@link Cursor#requery()} on a {@link Cursor}. * 当数据改变时调用 */ public void onChanged() { // Do nothing } /** * This method is called when the entire data becomes invalid, * most likely through a call to {@link Cursor#deactivate()} or {@link Cursor#close()} on a * {@link Cursor}. * 数据失效时调用 */ public void onInvalidated() { // Do nothing }}
/* * Copyright (C) 2007 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package android.database;/** * A specialization of {@link Observable} for {@link DataSetObserver} * that provides methods for sending notifications to a list of * {@link DataSetObserver} objects. */public class DataSetObservable extends Observable<DataSetObserver> { /** * Invokes {@link DataSetObserver#onChanged} on each observer. * Called when the contents of the data set have changed. The recipient * will obtain the new contents the next time it queries the data set. * 当数据内容改变时调用。 */ public void notifyChanged() { synchronized(mObservers) { // since onChanged() is implemented by the app, it could do anything, including // removing itself from {@link mObservers} - and that could cause problems if // an iterator is used on the ArrayList {@link mObservers}. // to avoid such problems, just march thru the list in the reverse order. for (int i = mObservers.size() - 1; i >= 0; i--) { mObservers.get(i).onChanged(); } } } /** * Invokes {@link DataSetObserver#onInvalidated} on each observer. * Called when the data set is no longer valid and cannot be queried again, * such as when the data set has been closed. * 数据集不再有效并且不能被获取时调用,例如数据集被关闭 */ public void notifyInvalidated() { synchronized (mObservers) { for (int i = mObservers.size() - 1; i >= 0; i--) { mObservers.get(i).onInvalidated(); } } }}
/* * Copyright (C) 2007 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package android.database;import java.util.ArrayList;/** * Provides methods for registering or unregistering arbitrary observers in an {@link ArrayList}. * 在ArrayList中,为任意observers通过注册和解除注册的方法 * This abstract class is intended to be subclassed and specialized to maintain * a registry of observers of specific types and dispatch notifications to them. * * @param T The observer type. */public abstract class Observable<T> { /** * The list of observers. An observer can be in the list at most * once and will never be null. * observers队列。一个observer最多只能出现一次,并且永远不会被填满。 */ protected final ArrayList<T> mObservers = new ArrayList<T>(); /** * Adds an observer to the list. The observer cannot be null and it must not already * be registered. * 添加observer,observer不能为null,并且不能已经被注册 * @param observer the observer to register * @throws IllegalArgumentException the observer is null * @throws IllegalStateException the observer is already registered */ public void registerObserver(T observer) { if (observer == null) { throw new IllegalArgumentException("The observer is null."); } synchronized(mObservers) { if (mObservers.contains(observer)) { throw new IllegalStateException("Observer " + observer + " is already registered."); } mObservers.add(observer); } } /** * Removes a previously registered observer. The observer must not be null and it * must already have been registered. * 解除observer的注册 * @param observer the observer to unregister * @throws IllegalArgumentException the observer is null * @throws IllegalStateException the observer is not yet registered */ public void unregisterObserver(T observer) { if (observer == null) { throw new IllegalArgumentException("The observer is null."); } synchronized(mObservers) { int index = mObservers.indexOf(observer); if (index == -1) { throw new IllegalStateException("Observer " + observer + " was not registered."); } mObservers.remove(index); } } /** * Remove all registered observers. * 解除注册队列 */ public void unregisterAll() { synchronized(mObservers) { mObservers.clear(); } }}
0 0
- DataSetObservable,Observable<T>,DataSetObserver源码注释翻译
- Android中的观察者DataSetObservable和DataSetObserver
- Android中的观察者DataSetObservable和DataSetObserver
- Android——Observable——源码注释翻译:Observable类的官方解释——秒懂
- DataSetObservable,ContentObservable源码分析
- tasklet源码注释翻译
- DataSetObserver
- Android源码之Observable
- ansi.h的源码及注释翻译
- Spring源码阅读-BeanFactory注释翻译
- Hashtable类注释翻译、源码分析
- ArrayList类注释翻译、源码分析
- LinkedList类注释翻译、源码分析
- Spring源码系列--BeanFactory接口注释翻译
- @Qualifier、@Named、Provider<T>源码翻译
- Android之观察者模式源码分析(DataSetObserver)
- Android源码IInterface.IBinder,Parcelable的注释翻译
- Spring源码阅读-DefaultListableBeanFactory的属性注释翻译
- HDU 1032.The 3n + 1 problem【注意细节】【估计数据不强】【8月21】
- eclipse导出可执行的jar包
- spmio 内网源部署(二)
- 小孩报数-约瑟夫问题数组链表
- JAVA12个最重要的J2EE最佳实践
- DataSetObservable,Observable<T>,DataSetObserver源码注释翻译
- POJ_2559_Largest Rectangle in a Histogram(栈)
- img下图形必须刷新才显示最新数据的问题
- Spring AOP原理
- js流程控制语句(判断语句)
- UFLDL教程(四)---深度网络
- js倒计时
- java中常用io流 BufferedInputStream和BufferedOutputStream
- ZOJ 3529 A Game Between Alice and Bob