Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2010 JBoss Inc
   *
   * 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.
  */
 
 package org.drools.planner.core.localsearch.decider.selector;
 
 import java.util.List;
 
A CompositeSelector unions multiple Selectors.
 
 public class CompositeSelector extends AbstractSelector {
 
     protected List<SelectorselectorList;
 
     public void setSelectorList(List<SelectorselectorList) {
         this. = selectorList;
     }
 
     @Override
     public void setDecider(Decider decider) {
         super.setDecider(decider);
         for (Selector selector : ) {
             selector.setDecider(decider);
         }
     }
 
     // ************************************************************************
     // Worker methods
     // ************************************************************************
 
     @Override
     public void phaseStarted(LocalSearchSolverPhaseScope localSearchSolverPhaseScope) {
         for (Selector selector : ) {
             selector.phaseStarted(localSearchSolverPhaseScope);
         }
     }
 
     @Override
     public void beforeDeciding(LocalSearchStepScope localSearchStepScope) {
         for (Selector selector : ) {
             selector.beforeDeciding(localSearchStepScope);
         }
     }
 
     public Iterator<MovemoveIterator(LocalSearchStepScope localSearchStepScope) {
         List<Iterator<Move>> moveIteratorList = new ArrayList<Iterator<Move>>(.size());
         // TODO unoptimized code: use Selector.moveList(localSearchStepScope) instead
         for (Selector selector : ) {
             Iterator<MovemoveIterator = selector.moveIterator(localSearchStepScope);
             if (moveIterator.hasNext()) {
                 moveIteratorList.add(moveIterator);
             }
         }
         return new CompositeSelectorMoveIterator(localSearchStepScope.getWorkingRandom(), moveIteratorList);
     }
 
     @Override
     public void stepDecided(LocalSearchStepScope localSearchStepScope) {
         for (Selector selector : ) {
             selector.stepDecided(localSearchStepScope);
         }
     }
 
     @Override
     public void stepTaken(LocalSearchStepScope localSearchStepScope) {
         for (Selector selector : ) {
             selector.stepTaken(localSearchStepScope);
         }
     }
 
     @Override
     public void phaseEnded(LocalSearchSolverPhaseScope localSearchSolverPhaseScope) {
         for (Selector selector : ) {
             selector.phaseEnded(localSearchSolverPhaseScope);
         }
     }
 
     private static class CompositeSelectorMoveIterator implements Iterator<Move> {
        private final List<Iterator<Move>> moveIteratorList;
        private final Random workingRandom;
        public CompositeSelectorMoveIterator(Random workingRandomList<Iterator<Move>> moveIteratorList) {
            this. = moveIteratorList;
            this. = workingRandom;
        }
        public boolean hasNext() {
            return !.isEmpty();
        }
        public Move next() {
            int moveIteratorIndex = .nextInt(.size());
            Iterator<MovemoveIterator = .get(moveIteratorIndex);
            Move next = moveIterator.next();
            if (!moveIterator.hasNext()) {
                .remove(moveIteratorIndex);
            }
            return next;
        }
        public void remove() {
            throw new UnsupportedOperationException(
                    "The remove method is not supported on CompositeSelectorMoveIterator");
        }
    }
New to GrepCode? Check out our FAQ X