create outer class for repository type predicator

This commit is contained in:
Sebastian Sdorra
2012-05-29 09:48:19 +02:00
parent 5d09e5844a
commit 05c78c984b
2 changed files with 79 additions and 46 deletions

View File

@@ -0,0 +1,77 @@
/**
* Copyright (c) 2010, Sebastian Sdorra All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer. 2. Redistributions in
* binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution. 3. Neither the name of SCM-Manager;
* nor the names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* http://bitbucket.org/sdorra/scm-manager
*
*/
package sonia.scm.repository;
//~--- non-JDK imports --------------------------------------------------------
import com.google.common.base.Predicate;
/**
*
* @author Sebastian Sdorra
* @since 1.16
*/
public class RepositoryTypePredicate implements Predicate<Repository>
{
/**
* Constructs ...
*
*
* @param type
*/
public RepositoryTypePredicate(String type)
{
this.type = type;
}
//~--- methods --------------------------------------------------------------
/**
* Method description
*
*
* @param repository
*
* @return
*/
@Override
public boolean apply(Repository repository)
{
return type.equalsIgnoreCase(repository.getType());
}
//~--- fields ---------------------------------------------------------------
/** Field description */
private String type;
}

View File

@@ -34,7 +34,6 @@ package sonia.scm.api.rest.resources;
//~--- non-JDK imports -------------------------------------------------------- //~--- non-JDK imports --------------------------------------------------------
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.collect.Collections2; import com.google.common.collect.Collections2;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import com.google.common.collect.Ordering; import com.google.common.collect.Ordering;
@@ -43,6 +42,7 @@ import com.google.inject.Inject;
import sonia.scm.config.ScmConfiguration; import sonia.scm.config.ScmConfiguration;
import sonia.scm.repository.Repository; import sonia.scm.repository.Repository;
import sonia.scm.repository.RepositoryManager; import sonia.scm.repository.RepositoryManager;
import sonia.scm.repository.RepositoryTypePredicate;
import sonia.scm.template.TemplateHandler; import sonia.scm.template.TemplateHandler;
import sonia.scm.url.UrlProvider; import sonia.scm.url.UrlProvider;
import sonia.scm.url.UrlProviderFactory; import sonia.scm.url.UrlProviderFactory;
@@ -119,7 +119,7 @@ public class RepositoryRootResource
Collection<RepositoryTemplateElement> unsortedRepositories = Collection<RepositoryTemplateElement> unsortedRepositories =
Collections2.transform( Collections2.transform(
Collections2.filter( Collections2.filter(
repositoryManager.getAll(), new TypePredicate(type)) repositoryManager.getAll(), new RepositoryTypePredicate(type))
, new RepositoryTransformFunction(uiUrlProvider) , new RepositoryTransformFunction(uiUrlProvider)
); );
@@ -319,50 +319,6 @@ public class RepositoryRootResource
} }
/**
* Class description
*
*
* @version Enter version here..., 12/05/28
* @author Enter your name here...
*/
private static class TypePredicate implements Predicate<Repository>
{
/**
* Constructs ...
*
*
* @param type
*/
public TypePredicate(String type)
{
this.type = type;
}
//~--- methods ------------------------------------------------------------
/**
* Method description
*
*
* @param repository
*
* @return
*/
@Override
public boolean apply(Repository repository)
{
return type.equalsIgnoreCase(repository.getType());
}
//~--- fields -------------------------------------------------------------
/** Field description */
private String type;
}
//~--- fields --------------------------------------------------------------- //~--- fields ---------------------------------------------------------------
/** Field description */ /** Field description */