Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* #%L
* *********************************************************************************************************************
*
* These Foolish Things - Miscellaneous utilities
* http://thesefoolishthings.tidalwave.it - git clone [email protected]:tidalwave/thesefoolishthings-src.git
* %%
* Copyright (C) 2009 - 2016 Tidalwave s.a.s. (http://tidalwave.it)
* %%
* *********************************************************************************************************************
*
* 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.
*
* *********************************************************************************************************************
*
* $Id$
*
* *********************************************************************************************************************
* #L%
*/
package it.tidalwave.util.spi;
import javax.annotation.Nonnegative;
import javax.annotation.Nonnull;
import java.lang.reflect.Constructor;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import it.tidalwave.util.Finder;
import it.tidalwave.util.Finder.FilterSortCriterion;
import it.tidalwave.util.Finder.SortCriterion;
import it.tidalwave.util.Finder.SortDirection;
import it.tidalwave.util.NotFoundException;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.ToString;
import lombok.extern.slf4j.Slf4j;
/***********************************************************************************************************************
*
* A support class for implementing a {@link Finder}. Subclasses only need to implement the {@link #computeResults()}
* method where raw results are retrieved (with raw we mean that they shouldn't be filtered or sorted, as
* post-processing will be performed by this class) and a clone constructor.
*
* If you don't need to extend the {@link Finder} with extra methods, please use the simplified
* {@link SimpleFinderSupport}.
*
* @author Fabrizio Giudici
* @version $Id$
* @it.tidalwave.javadoc.draft
*
**********************************************************************************************************************/
@Slf4j @AllArgsConstructor(access = AccessLevel.PRIVATE) @ToString
public class FinderSupport> implements Finder, Cloneable
{
static class Sorter
{
private final FilterSortCriterion sortCriterion;
private final SortDirection sortDirection;
public Sorter (final @Nonnull FilterSortCriterion sortCriterion,
final @Nonnull SortDirection sortDirection)
{
this.sortCriterion = sortCriterion;
this.sortDirection = sortDirection;
}
public void sort (final @Nonnull List extends Type> results)
{
sortCriterion.sort(results, sortDirection);
}
}
private final static String MESSAGE =
"Since version 2.0, Implementations of Finder must have a clone constructor such as "
+ "MyFinder(MyFinder other, Object override). This means that they can't be implemented by anonymous or inner, "
+ "non static classes. See the javadoc for further information. Could not find constructor: ";
@Nonnull
private final String name;
@Nonnegative
private final int firstResult;
@Nonnegative
private final int maxResults;
@Nonnull @Getter(AccessLevel.PROTECTED)
private final List