001 /* 002 * Copyright 2011 Christian Kumpe http://kumpe.de/christian/java 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 package de.kumpe.hadooptimizer.impl; 017 018 import java.util.Collection; 019 020 import de.kumpe.hadooptimizer.EsIndividual; 021 import de.kumpe.hadooptimizer.EvaluationResult; 022 import de.kumpe.hadooptimizer.Halter; 023 import de.kumpe.hadooptimizer.Stoppable; 024 025 /** 026 * A Wrapper that transforms an {@link Halter Halter<double[]>} into an 027 * {@link Halter Halter<EsIndividual>}. 028 * 029 * @author <a href="http://kumpe.de/christian/java">Christian Kumpe</a> 030 */ 031 public final class EsHalterWrapper extends 032 NeedsRandomWrapperBase<Halter<double[]>> implements 033 Halter<EsIndividual>, Stoppable { 034 private static final long serialVersionUID = 1L; 035 036 /** 037 * 038 * Creates a new {@link EsHalterWrapper}wrapping the specified 039 * {@link Halter Halter<double[]>}. 040 * 041 * @param delegate 042 * an {@link Halter Halter<double[]>} to wrap 043 */ 044 public EsHalterWrapper(final Halter<double[]> delegate) { 045 super(delegate); 046 } 047 048 @Override 049 public boolean halt( 050 final Collection<EvaluationResult<EsIndividual>> evaluationResults) { 051 return delegate 052 .halt(new UnmodifiableCollectionWrapper<EvaluationResult<double[]>, EvaluationResult<EsIndividual>>( 053 evaluationResults) { 054 @Override 055 protected EvaluationResult<double[]> wrap( 056 final EvaluationResult<EsIndividual> delegateElement) { 057 return new EvaluationResult<double[]>(delegateElement 058 .getIndividual().getIndividual(), 059 delegateElement.getEvaluation()); 060 } 061 }); 062 } 063 064 @Override 065 public void stop() { 066 if (delegate instanceof Stoppable) { 067 ((Stoppable) delegate).stop(); 068 } 069 } 070 }