001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
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    }