本文整理汇总了Java中io.realm.Sort类的典型用法代码示例。如果您正苦于以下问题:Java Sort类的具体用法?Java Sort怎么用?Java Sort使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Sort类属于io.realm包,在下文中一共展示了Sort类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: loadNewsFeed
import io.realm.Sort; //导入依赖的package包/类
/**
* Loads the news feed as well as all future updates.
*/
@UiThread
public Flowable<RealmResults<NYTimesStory>> loadNewsFeed(@NonNull String sectionKey, boolean forceReload) {
// Start loading data from the network if needed
// It will put all data into Realm
if (forceReload || timeSinceLastNetworkRequest(sectionKey) > MINIMUM_NETWORK_WAIT_SEC) {
dataLoader.loadData(sectionKey, apiKey, realm, networkLoading);
lastNetworkRequest.put(sectionKey, System.currentTimeMillis());
}
// Return the data in Realm. The query result will be automatically updated when the network requests
// save data in Realm
return realm.where(NYTimesStory.class)
.equalTo(NYTimesStory.API_SECTION, sectionKey)
.findAllSortedAsync(NYTimesStory.PUBLISHED_DATE, Sort.DESCENDING)
.asFlowable();
}
示例2: getInstance
import io.realm.Sort; //导入依赖的package包/类
private static SortDescriptor getInstance(
FieldDescriptor.SchemaProxy proxy,
Table table,
String[] fieldDescriptions,
@Nullable Sort[] sortOrders,
Set<RealmFieldType> legalInternalTypes,
Set<RealmFieldType> legalTerminalTypes,
String message) {
//noinspection ConstantConditions
if (fieldDescriptions == null || fieldDescriptions.length == 0) {
throw new IllegalArgumentException("You must provide at least one field name.");
}
long[][] columnIndices = new long[fieldDescriptions.length][];
// Force aggressive parsing of the FieldDescriptors, so that only valid SortDescriptor objects are created.
for (int i = 0; i < fieldDescriptions.length; i++) {
FieldDescriptor descriptor = FieldDescriptor.createFieldDescriptor(proxy, table, fieldDescriptions[i], legalInternalTypes, null);
checkFieldType(descriptor, legalTerminalTypes, message, fieldDescriptions[i]);
columnIndices[i] = descriptor.getColumnIndices();
}
return new SortDescriptor(table, columnIndices, sortOrders);
}
示例3: getInstanceForSort_multipleFields
import io.realm.Sort; //导入依赖的package包/类
@Test
public void getInstanceForSort_multipleFields() {
RealmFieldType stringType = RealmFieldType.STRING;
long stringColumn = table.addColumn(stringType, stringType.name());
RealmFieldType intType = RealmFieldType.INTEGER;
long intColumn = table.addColumn(intType, intType.name());
SortDescriptor sortDescriptor = SortDescriptor.getInstanceForSort(null, table, new String[] {
stringType.name(), intType.name()}, new Sort[] {Sort.ASCENDING, Sort.DESCENDING});
assertEquals(2, sortDescriptor.getAscendings().length);
assertEquals(2, sortDescriptor.getColumnIndices().length);
assertEquals(1, sortDescriptor.getColumnIndices()[0].length);
assertEquals(stringColumn, sortDescriptor.getColumnIndices()[0][0]);
assertTrue(sortDescriptor.getAscendings()[0]);
assertEquals(1, sortDescriptor.getColumnIndices()[1].length);
assertEquals(intColumn, sortDescriptor.getColumnIndices()[1][0]);
assertFalse(sortDescriptor.getAscendings()[1]);
}
示例4: getData
import io.realm.Sort; //导入依赖的package包/类
private void getData() {
if (showID != -1) {
result = realm.where(RealmEpisode.class)
.equalTo("showID", showID)
.equalTo("watched", false)
.notEqualTo("seasonNumber", 0)
.findAllSortedAsync("details", Sort.ASCENDING);
result.addChangeListener(callback);
} else {
singleEpisode = realm.where(RealmEpisode.class)
.equalTo("episodeID", episodeID)
.findFirstAsync();
singleEpisode.addChangeListener(singleEpisodeCallback);
}
}
示例5: getResults
import io.realm.Sort; //导入依赖的package包/类
private RealmResults<Album> getResults() {
RealmResults<Album> results = null;
switch (Media.getSortType()) {
case ALPHABETICAL: {
if (Media.isShowHidden()) {
results = realm.where(Album.class).findAll().sort("name", Media.isSortAscending() ? Sort.ASCENDING : Sort.DESCENDING);
break;
} else {
results = realm.where(Album.class).equalTo("hidden", false).findAll().sort("name", Media.isSortAscending() ? Sort.ASCENDING : Sort.DESCENDING);
break;
}
}
case SIZE: {
if (Media.isShowHidden()) {
results = realm.where(Album.class).findAll().sort("size", Media.isSortAscending() ? Sort.ASCENDING : Sort.DESCENDING);
break;
} else {
results = realm.where(Album.class).equalTo("hidden", false).findAll().sort("size", Media.isSortAscending() ? Sort.ASCENDING : Sort.DESCENDING);
break;
}
}
}
return results;
}
示例6: updateCoverPhotos
import io.realm.Sort; //导入依赖的package包/类
public static void updateCoverPhotos() {
long time = System.currentTimeMillis();
Realm realm = Realm.getDefaultInstance();
realm.beginTransaction();
for (Album a : realm.where(Album.class).findAll()) {
switch (Media.getMediaSortType()) {
case ALPHABETICAL: {
a.setCoverPath(a.getMedia().sort("name", Media.isMediaSortAscending() ? Sort.ASCENDING : Sort.DESCENDING).first().getPath());
break;
}
case DATE: {
a.setCoverPath(a.getMedia().sort("date", Media.isMediaSortAscending() ? Sort.ASCENDING : Sort.DESCENDING).first().getPath());
break;
}
}
}
realm.commitTransaction();
realm.close();
Log.d(Util.LOG_TAG, "Reloading all cover photos took " + (System.currentTimeMillis() - time));
}
示例7: updateSingleCover
import io.realm.Sort; //导入依赖的package包/类
public static void updateSingleCover(String key) {
long time = System.currentTimeMillis();
Realm realm = Realm.getDefaultInstance();
realm.beginTransaction();
Album a = realm.where(Album.class).equalTo("path",key).findFirst();
switch (Media.getMediaSortType()) {
case ALPHABETICAL: {
a.setCoverPath(a.getMedia().sort("name", Media.isMediaSortAscending() ? Sort.ASCENDING : Sort.DESCENDING).first().getPath());
break;
}
case DATE: {
a.setCoverPath(a.getMedia().sort("date", Media.isMediaSortAscending() ? Sort.ASCENDING : Sort.DESCENDING).first().getPath());
break;
}
}
realm.commitTransaction();
realm.close();
Log.d(Util.LOG_TAG, "Reloading all cover photos took " + (System.currentTimeMillis() - time));
}
示例8: searchCompanies
import io.realm.Sort; //导入依赖的package包/类
@Override
public Observable<List<Company>> searchCompanies(@NonNull String keyWords) {
Realm rlm = RealmHelper.newRealmInstance();
List<Company> results = rlm.copyFromRealm(
rlm.where(Company.class)
.like("name","*" + keyWords + "*", Case.INSENSITIVE)
.or()
.like("tel", "*" + keyWords + "*", Case.INSENSITIVE)
.or()
.like("website", "*" + keyWords + "*", Case.INSENSITIVE)
.or()
.like("alphabet", "*" + keyWords + "*", Case.INSENSITIVE)
.findAllSorted("alphabet", Sort.ASCENDING));
return Observable.fromIterable(results)
.toList()
.toObservable();
}
示例9: findAllProfil
import io.realm.Sort; //导入依赖的package包/类
/**
* method mencari semua Profil
*/
public ArrayList<ProfilModel> findAllProfil(){
ArrayList<ProfilModel> data = new ArrayList<>();
realmResultProfil = realm.where(Profil.class).findAll();
realmResultProfil.sort("id", Sort.DESCENDING);
if (realmResultProfil.size() > 0){
showLog("Size : " + realmResultProfil.size());
for (int i = 0; i < realmResultProfil.size(); i++) {
String nama, email, instansi;
int id = realmResultProfil.get(i).getId();
nama = realmResultProfil.get(i).getNama();
email = realmResultProfil.get(i).getEmail();
instansi = realmResultProfil.get(i).getInstansi();
data.add(new ProfilModel(id, nama, email, instansi));
}
} else {
showLog("Size : 0");
}
return data;
}
示例10: findAllLainnya
import io.realm.Sort; //导入依赖的package包/类
/**
* method mencari semua Lainnya
*/
public ArrayList<LainnyaModel> findAllLainnya(){
ArrayList<LainnyaModel> data = new ArrayList<>();
realmResultLainnya = realm.where(Lainnya.class).findAll();
realmResultLainnya.sort("id", Sort.DESCENDING);
if (realmResultLainnya.size() > 0){
showLog("Size : " + realmResultLainnya.size());
for (int i = 0; i < realmResultLainnya.size(); i++) {
String judul, jenis, deadline, deskripsi, done;
int id = realmResultLainnya.get(i).getId();
judul = realmResultLainnya.get(i).getJudul();
deadline = realmResultLainnya.get(i).getDeadline();
deskripsi = realmResultLainnya.get(i).getDeskripsi();
done = realmResultLainnya.get(i).getDone();
data.add(new LainnyaModel(id, judul, deadline, deskripsi, done));
}
} else {
showLog("Size : 0");
}
return data;
}
示例11: getAll
import io.realm.Sort; //导入依赖的package包/类
@Override
public Iterable<Preview> getAll(ItemsPerPreview itemsPerPreview) {
Realm realm = Realm.getInstance(configuration);
RealmResults<TodoListDAO> allTodoListDAO = realm.where(TodoListDAO.class).findAllSorted("position", Sort.DESCENDING);
RealmResults<NoteDAO> allNoteDAO = realm.where(NoteDAO.class).findAllSorted("position", Sort.DESCENDING);
List<Preview> previews = new ArrayList<>(allTodoListDAO.size() + allNoteDAO.size());
for (TodoListDAO todoListDAO : allTodoListDAO) {
previews.add(constructPreview(realm, todoListDAO, itemsPerPreview));
}
for (NoteDAO noteDAO : allNoteDAO) {
previews.add(new NotePreview(RealmConverter.convert(noteDAO)));
}
realm.close();
return previews;
}
示例12: getItemPreviewOfHeader
import io.realm.Sort; //导入依赖的package包/类
private List<TodoListItem> getItemPreviewOfHeader(Realm realm, TodoListHeader header, ItemsPerPreview itemsPerPreview) {
if (header == null || itemsPerPreview.areZero()) return new ArrayList<>(0);
RealmResults<TodoListItemDAO> itemDAOs = realm.where(TodoListItemDAO.class)
.equalTo("parentTodoListUuid", header.getParentTodoListUuid())
.equalTo("parentHeaderUuid", header.getUuid())
.findAllSorted("position", Sort.DESCENDING);
int size = Math.min(itemDAOs.size(), itemsPerPreview.getCount());
List<TodoListItem> items = new ArrayList<>(size);
if (size > 0) {
for (TodoListItemDAO itemDAO : itemDAOs.subList(0, size)) {
items.add(RealmConverter.convert(itemDAO));
}
}
return items;
}
示例13: parseRawData
import io.realm.Sort; //导入依赖的package包/类
static void parseRawData() {
Realm realmRawData = Realm.getInstance(realmConfigRawData);
Realm realmProcessedData = Realm.getInstance(realmConfigProcessedData);
// if processed data realm is empty
if (realmProcessedData.isEmpty() && !realmRawData.isEmpty()) {
// parse data from raw realm into processed data realm
Log.i(LOG_ID, "Parsing data raw_data realm to processed_data realm.");
realmProcessedData.beginTransaction();
for (RawTagData rawTagData : realmRawData.where(RawTagData.class)
.findAllSorted(RawTagData.DATE, Sort.ASCENDING)) {
realmProcessedData.copyToRealmOrUpdate(new ReadingData(rawTagData));
}
realmProcessedData.commitTransaction();
}
realmProcessedData.close();
realmRawData.close();
}
示例14: onCreateView
import io.realm.Sort; //导入依赖的package包/类
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_log_list, container, false);
// Set the adapter
if (view instanceof RecyclerView) {
Context context = view.getContext();
RecyclerView recyclerView = (RecyclerView) view;
recyclerView.setLayoutManager(new LinearLayoutManager(context));
recyclerView.setAdapter(new LogRecyclerViewAdapter(this,
mRealmProcessedData
.where(ReadingData.class)
.isNotEmpty(ReadingData.TREND)
.findAllSortedAsync(ReadingData.DATE, Sort.DESCENDING)
));
recyclerView.setHasFixedSize(true);
recyclerView.addItemDecoration(
new DividerItemDecoration(this.getContext(), DividerItemDecoration.VERTICAL_LIST)
);
registerForContextMenu(recyclerView);
}
return view;
}
示例15: getLatestNewsFromDB
import io.realm.Sort; //导入依赖的package包/类
Observable<LatestNews> getLatestNewsFromDB() {
return Observable.fromCallable(new Callable<LatestNews>() {
@Override
public LatestNews call() throws Exception {
Realm realm = Realm.getDefaultInstance();
RealmResults<LatestNewsDB> result;
LatestNews latestNews;
try {
result = realm.where(LatestNewsDB.class).findAll();
result = result.sort("date", Sort.DESCENDING);
if (result.size() < 1) {
return null;
}
latestNews = Mapper.getLatestNews(result);
return latestNews;
} finally {
if (realm != null) {
realm.close();
}
}
}
});
}