All Downloads are FREE. Search and download functionalities are using the official Maven repository.

nl.vpro.domain.api.SearchResult Maven / Gradle / Ivy

Go to download

Contains the objects used by the Frontend API, like forms and result objects

There is a newer version: 8.3.3
Show newest version
package nl.vpro.domain.api;


import java.util.AbstractList;
import java.util.List;

import javax.xml.bind.annotation.*;

/**
 * @author Michiel Meeuwissen
 * @since 2.0
 */

@XmlType(name = "searchResultType")
@XmlSeeAlso({SearchResultItem.class})
@XmlAccessorType(XmlAccessType.FIELD)
public class SearchResult extends Result> {


    public SearchResult() {
    }

    public SearchResult(List> list, Long offset, Integer max, Total total) {
        super(list, offset, max, total);
    }

    public SearchResult(SearchResult copy) {
        super(copy);
    }

    /**
     * Returns a view on this SearchResult as a list of unwrapped objects (so not wrapped by {@link SearchResultItem}s
     */
    public List asList() {
        return new AbstractList() {
            @Override
            public S get(int index) {
                return SearchResult.this.getResult(index);
            }

            @Override
            public int size() {
                return SearchResult.this.getSize();
            }
        };
    }

    /**
     * @since 5.12
     * @throws IndexOutOfBoundsException  if the index is out of range (index < 0 || index >= size())
     */
    public S getResult(int i) {
        SearchResultItem  item =  get(i);
        return item == null ? null : item.getResult();
    }

    /**
     * Returns this SearchResult as a {@link #Result}, which means that all items are unwrapped, and the facet results are removed.
     */
    public Result asResult() {
        return new Result<>(asList(), getOffset(), getMax(), new Total(getTotal(), getTotalQualifier()));
    }
}