001    /**
002     * Copyright (c) 2000-2011 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() {
028                    _k = 0;
029                    _b = 0;
030            }
031    
032            public void add(double k, double b) {
033                    _k = _k + k;
034                    _b = _b + b;
035            }
036    
037            public SocialEquityValue(double k, double b) {
038                    _k = k;
039                    _b = b;
040            }
041    
042            public void add(SocialEquityValue socialEquityValue) {
043                    _k = _k + socialEquityValue._k;
044                    _b = _b + socialEquityValue._b;
045            }
046    
047            public double getB() {
048                    return _b;
049            }
050    
051            public double getK() {
052                    return _k;
053            }
054    
055            public double getValue() {
056                    return getValue(getEquityDate());
057            }
058    
059            public double getValue(int equityDate) {
060                    return _k * equityDate + _b;
061            }
062    
063            public void setValue(double k, double b) {
064                    _k = k;
065                    _b = b;
066            }
067    
068            public void subtract(double k, double b) {
069                    _k = _k - k;
070                    _b = _b - b;
071            }
072    
073            public void subtract(SocialEquityValue socialEquityValue) {
074                    _k = _k - socialEquityValue._k;
075                    _b = _b - socialEquityValue._b;
076            }
077    
078            protected int getEquityDate() {
079                    long d = System.currentTimeMillis() - _BASE_TIME;
080    
081                    return (int)(d / Time.DAY);
082            }
083    
084            private static final long _BASE_TIME =
085                    new GregorianCalendar(2010, Calendar.JANUARY, 1).getTimeInMillis();
086    
087            private double _b;
088            private double _k;
089    
090    }