/*
 * LensKit, an open source recommender systems toolkit.
 * Copyright 2010-2012 Regents of the University of Minnesota and contributors
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 * details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program; if not, write to the Free Software Foundation, Inc., 51
 * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */
package org.grouplens.lenskit.svd;

import java.io.Serializable;

import org.grouplens.lenskit.params.MaxRating;
import org.grouplens.lenskit.params.MinRating;
import org.grouplens.lenskit.util.DoubleFunction;

public final class RatingRangeClamp implements DoubleFunction, Serializable {

    private static final long serialVersionUID = 1012447846494918355L;
    private final double minRating, maxRating;

    public RatingRangeClamp() {
        this(1, 5);
    }

    public RatingRangeClamp(@MinRating double min, @MaxRating double max) {
        minRating = min;
        maxRating = max;
    }

    /**
     * @return the minRating
     */
    public double getMinRating() {
        return minRating;
    }

    /**
     * @return the maxRating
     */
    public double getMaxRating() {
        return maxRating;
    }

        @Override
    public double apply(double v) {
        if (v < minRating) return minRating;
        else if (v > maxRating) return maxRating;
        else return v;
    }

}

@@ -911,123 +911,56 @@
 ort 
-java.io.Serializable;%0A%0Aimport org.grouplens.lenskit.params.MaxRating;%0Aimport org.grouplens.lenskit.params.MinRat
+org.grouplens.lenskit.data.pref.PreferenceDoma
 in
-g
 ;%0Aim
@@ -1008,16 +1008,46 @@
 ction;%0A%0A
+import java.io.Serializable;%0A%0A
 public f
@@ -1204,41 +1204,31 @@
 ate 
-final double minRating, maxRat
+PreferenceDomain doma
 in
-g
 ;%0A%0A 
@@ -1258,30 +1258,52 @@
 amp(
-) %7B%0A        this(1, 5)
+PreferenceDomain dom) %7B%0A        domain = dom
 ;%0A  
@@ -1339,19 +1339,8 @@
 amp(
-@MinRating 
 doub
@@ -1350,19 +1350,8 @@
 min,
- @MaxRating
  dou
@@ -1373,48 +1373,44 @@
     
-minRating = min;%0A        maxRating =
+this(new PreferenceDomain(min,
  max
+))
 ;%0A  
@@ -1505,33 +1505,43 @@
      return 
-minRating
+domain.getMinimum()
 ;%0A    %7D%0A%0A   
@@ -1628,33 +1628,43 @@
      return 
-maxRating
+domain.getMaximum()
 ;%0A    %7D%0A%0A   
@@ -1660,20 +1660,16 @@
 %0A    %7D%0A%0A
-    
     @Ove
@@ -1718,16 +1718,100 @@
         
+double min = domain.getMinimum();%0A        double max = domain.getMaximum();%0A        
 if (v %3C 
@@ -1811,24 +1811,18 @@
 f (v %3C m
-inRat
 in
-g
 ) return
@@ -1825,22 +1825,16 @@
 turn min
-Rating
 ;%0A      
@@ -1851,22 +1851,16 @@
 (v %3E max
-Rating
 ) return
@@ -1863,22 +1863,16 @@
 turn max
-Rating
 ;%0A      
@@ -1894,11 +1894,10 @@
 ;%0A    %7D%0A
-%0A
 %7D%0A

Make RatingRangeClamp use PreferenceDomain (refs #163)