SortableMetadataField

  • SortableMetadataField is an interface for metadata fields that can be used to sort the results of file queries.

  • Implementations of this interface, like those in SortableField, can add sorting criteria to file or folder queries.

  • You can use SortableMetadataField to sort query results by fields such as creation date, as shown in the example filtering starred plain text files by creation date.

public interface SortableMetadataField implements MetadataField<T>

Interface for metadata fields that can be used to sort results of the file queries. Implementation of this interface (such as the static values in SortableField) can be add sorting criteria for the file or folder queries.

For example, the following code will find all files that are starred, have the MIME type type "text/plain" and list them in the order they were created:


 Filter starredFilter = Filters.eq(SearchableField.STARRED, true);
 Filter mimeTypeFilter = Filters.eq(SearchableField.MIME_TYPE, "text/plain");
 Query query = new Query.Builder()
                        .addFilters(starredFilter, mimeTypeFilter)
                        .addSortAscending(SortableField.CREATED_DATE)
                        .build();
 for (Metadata metadata : Drive.DriveApi.query(apiClient, query).await().getMetadataBuffer()) {
     System.out.println(metadata.getTitle());
 }