Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 /*
  * Copyright 2011 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.domain.variable;
public class PlanningValueSorter {
    // TODO also keep PlanningEntityDescriptor and the valueRange descriptor?
    private Comparator<ObjectstrengthComparator = null;
    public PlanningValueSorter() {
    }
    public void setStrengthComparator(Comparator<ObjectstrengthComparator) {
        this. = strengthComparator;
    }
    public void setStrengthWeightFactory(PlanningValueStrengthWeightFactory strengthWeightFactory) {
        this. = strengthWeightFactory;
    }
    public boolean isSortStrengthSupported() {
        return  != null ||  != null;
    }
    public void sortStrengthAscending(Solution solutionList<ObjectplanningValueList) {
        if ( != null) {
            Collections.sort(planningValueList);
        } else if ( != null) {
            SortedMap<ComparableObjectplanningValueMap = new TreeMap<ComparableObject>();
            for (Object planningValue : planningValueList) {
                Comparable strengthWeight = .createStrengthWeight(solutionplanningValue);
                Object previous = planningValueMap.put(strengthWeightplanningValue);
                if (previous != null) {
                    throw new IllegalStateException("The planningValueList contains 2 times the same planningValue ("
                            + previous + ") and (" + planningValue + ").");
                }
            }
            planningValueList.clear();
            planningValueList.addAll(planningValueMap.values());
        } else {
            throw new IllegalStateException("Sorting on strength is impossible" +
                    " because strengthComparator and strengthWeightFactory are null.");
        }
    }
    public void sortStrengthDescending(Solution solutionList<ObjectplanningEntityList) {
        sortStrengthAscending(solutionplanningEntityList);
        Collections.reverse(planningEntityList);
    }
New to GrepCode? Check out our FAQ X