001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portlet.social.model;
016    
017    import com.liferay.portal.kernel.util.Time;
018    
019    import java.util.Calendar;
020    import java.util.GregorianCalendar;
021    
022    /**
023     * @author Zsolt Berentey
024     */
025    public class SocialEquityValue {
026    
027            public SocialEquityValue(double k, double b) {
028                    _k = k;
029                    _b = b;
030            }
031    
032            public void add(SocialEquityValue socialEquityValue) {
033                    _k = _k + socialEquityValue._k;
034                    _b = _b + socialEquityValue._b;
035            }
036    
037            public double getB() {
038                    return _b;
039            }
040    
041            public double getK() {
042                    return _k;
043            }
044    
045            public double getValue() {
046                    return getValue(getEquityDate());
047            }
048    
049            public double getValue(int equityDate) {
050                    return _k * equityDate + _b;
051            }
052    
053            public void subtract(SocialEquityValue socialEquityValue) {
054                    _k = _k - socialEquityValue._k;
055                    _b = _b - socialEquityValue._b;
056            }
057    
058            protected int getEquityDate() {
059                    long d = System.currentTimeMillis() - _BASE_TIME;
060    
061                    return (int)(d / Time.DAY);
062            }
063    
064            private static final long _BASE_TIME =
065                    new GregorianCalendar(2010, Calendar.JANUARY, 1).getTimeInMillis();
066    
067            private double _b;
068            private double _k;
069    
070    }