• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java Function类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中android.arch.core.util.Function的典型用法代码示例。如果您正苦于以下问题:Java Function类的具体用法?Java Function怎么用?Java Function使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Function类属于android.arch.core.util包,在下文中一共展示了Function类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: subscribeToDbChanges

import android.arch.core.util.Function; //导入依赖的package包/类
private void subscribeToDbChanges() {
    LiveData<List<LoanWithUserAndBook>> loans
            = mDb.loanModel().findLoansByNameAfter("Mike", getYesterdayDate());

    // Instead of exposing the list of Loans, we can apply a transformation and expose Strings.
    mLoansResult = Transformations.map(loans,
            new Function<List<LoanWithUserAndBook>, String>() {
        @Override
        public String apply(List<LoanWithUserAndBook> loansWithUserAndBook) {
            StringBuilder sb = new StringBuilder();
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm",
                    Locale.US);

            for (LoanWithUserAndBook loan : loansWithUserAndBook) {
                sb.append(String.format("%s\n  (Returned: %s)\n",
                        loan.bookTitle,
                        simpleDateFormat.format(loan.endTime)));
            }
            return sb.toString();
        }
    });
}
 
开发者ID:googlecodelabs,项目名称:android-persistence,代码行数:23,代码来源:CustomResultViewModel.java


示例2: subscribeToDbChanges

import android.arch.core.util.Function; //导入依赖的package包/类
private void subscribeToDbChanges() {
    // TODO: Modify this query to show only recent loans from specific user
    LiveData<List<LoanWithUserAndBook>> loans
            = mDb.loanModel().findAllWithUserAndBook();

    // Instead of exposing the list of Loans, we can apply a transformation and expose Strings.
    mLoansResult = Transformations.map(loans,
            new Function<List<LoanWithUserAndBook>, String>() {
        @Override
        public String apply(List<LoanWithUserAndBook> loansWithUserAndBook) {
            StringBuilder sb = new StringBuilder();
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm",
                    Locale.US);

            for (LoanWithUserAndBook loan : loansWithUserAndBook) {
                sb.append(String.format("%s\n  (Returned: %s)\n",
                        loan.bookTitle,
                        simpleDateFormat.format(loan.endTime)));
            }
            return sb.toString();
        }
    });
}
 
开发者ID:googlecodelabs,项目名称:android-persistence,代码行数:24,代码来源:CustomResultViewModel.java


示例3: DocListViewModel

import android.arch.core.util.Function; //导入依赖的package包/类
/**
 * Default constructor.
 * @param application
 */
public DocListViewModel(Application application) {
    super(application);

    // transform database created flag to live data.
    // if it is not created, it will return ABSENT field.
    // if it is created, it will return room live data.
    final DatabaseManager databaseManager = DatabaseManager.getInstance(application);
    LiveData<Boolean> databaseCreated = databaseManager.isDatabaseCreated();
    mObservableDocuments = Transformations.switchMap(databaseCreated,
            new Function<Boolean, LiveData<List<DocumentMetadata>>>() {
                @Override
                public LiveData<List<DocumentMetadata>> apply(Boolean isDbCreated) {
                    if (!Boolean.TRUE.equals(isDbCreated)) {
                        return ABSENT;
                    } else {
                        return databaseManager.getDatabase().documentDao().loadAllDocumentsMetadata();
                    }
                }
            });

    databaseManager.initDbAsync(this.getApplication());
}
 
开发者ID:nfdz,项目名称:foco,代码行数:27,代码来源:DocListViewModel.java


示例4: PostsListViewModel

import android.arch.core.util.Function; //导入依赖的package包/类
PostsListViewModel(@NonNull Application application, String slug, int postCount, Retrofit retrofit) {
    super(application);
    mSlug = slug;
    mPostCount = postCount;
    mRetrofit = retrofit;

    mIsLoading.setValue(true);
    mOffset.setValue(0);

    // 当 mOffset 的值发生改变,就会执行 apply
    mListLiveData = Transformations.switchMap(mOffset, new Function<Integer, LiveData<List<PostsListBean>>>() {
        @Override
        public LiveData<List<PostsListBean>> apply(Integer input) {
            return handleData(input);
        }
    });
}
 
开发者ID:iMeiji,项目名称:Daily,代码行数:18,代码来源:PostsListViewModel.java


示例5: FlexibleViewModel

import android.arch.core.util.Function; //导入依赖的package包/类
public FlexibleViewModel() {
    identifier = new MutableLiveData<>();
    liveItems = Transformations.switchMap(identifier, new Function<Identifier, LiveData<List<AdapterItem>>>() {
        @Override
        public LiveData<List<AdapterItem>> apply(Identifier input) {
            return Transformations.map(getSource(input), new Function<Source, List<AdapterItem>>() {
                @Override
                public List<AdapterItem> apply(Source source) {
                    if (isSourceValid(source)) {
                        return map(source);
                    } else {
                        return liveItems.getValue();
                    }
                }
            });
        }
    });
}
 
开发者ID:davideas,项目名称:FlexibleAdapter,代码行数:19,代码来源:FlexibleViewModel.java


示例6: map

import android.arch.core.util.Function; //导入依赖的package包/类
public static <E, R> List<R> map(List<E> list, Function<E, R> mapper) {
    final List<R> newList = new ArrayList<>(list.size());
    for (E el : list) {
        newList.add(mapper.apply(el));
    }
    return newList;
}
 
开发者ID:Vavassor,项目名称:Tusky,代码行数:8,代码来源:CollectionUtil.java


示例7: VideosViewModel

import android.arch.core.util.Function; //导入依赖的package包/类
@Inject
public VideosViewModel(Application application, VideosRepository repository) {
    super(application);

    mRepository = repository;

    mAllCategories = mRepository.getAllCategories();

    mSearchResults = Transformations.switchMap(
            mQuery, new Function<String, LiveData<List<VideoEntity>>>() {
                @Override
                public LiveData<List<VideoEntity>> apply(final String queryMessage) {
                    return mRepository.getSearchResult(queryMessage);
                }
            });


    mVideoById = Transformations.switchMap(
            mVideoId, new Function<Long, LiveData<VideoEntity>>() {
                @Override
                public LiveData<VideoEntity> apply(final Long videoId) {
                    return mRepository.getVideoById(videoId);
                }
            });

    /**
     * Using switch map function to react to the change of observed variable, the benefits of
     * this mapping method is we don't have to re-create the live data every time.
     */
    mAllVideosByCategory = Transformations.switchMap(mVideoCategory, new Function<String, LiveData<List<VideoEntity>>>() {
        @Override
        public LiveData<List<VideoEntity>> apply(String category) {
            return mRepository.getVideosInSameCategoryLiveData(category);
        }
    });
}
 
开发者ID:googlesamples,项目名称:leanback-showcase,代码行数:37,代码来源:VideosViewModel.java


示例8: PairedList

import android.arch.core.util.Function; //导入依赖的package包/类
/**
 * Construct new paired list. Main and supplementary lists will be empty.
 * @param mapper Function, which will be used to translate items from the main list to the
 *               supplementary one.
 */
public PairedList(Function<T, ? extends V> mapper) {
    this.mapper = mapper;
}
 
开发者ID:Vavassor,项目名称:Tusky,代码行数:9,代码来源:PairedList.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Element类代码示例发布时间:2022-05-23
下一篇:
Java VarInt类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap