001    /**
002     * Copyright (c) 2000-2013 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.portal.kernel.servlet;
016    
017    import com.liferay.portal.kernel.util.StringBundler;
018    import com.liferay.portal.kernel.util.StringPool;
019    
020    /**
021     * @author Juan Gonz??lez
022     */
023    public class Range {
024    
025            public Range(long start, long end, long total) {
026                    _start = start;
027                    _end = end;
028                    _length = end - start + 1;
029                    _total = total;
030            }
031    
032            @Override
033            public boolean equals(Object obj) {
034                    if (this == obj) {
035                            return true;
036                    }
037    
038                    if (!(obj instanceof Range)) {
039                            return false;
040                    }
041    
042                    Range range = (Range)obj;
043    
044                    if ((_end == range._end) && (_length == range._length) &&
045                            (_start == range._start) && (_total == range._total)) {
046    
047                            return true;
048                    }
049    
050                    return false;
051            }
052    
053            public String getContentRange() {
054                    StringBundler sb = new StringBundler(6);
055    
056                    sb.append("bytes ");
057                    sb.append(getStart());
058                    sb.append(StringPool.DASH);
059                    sb.append(getEnd());
060                    sb.append(StringPool.SLASH);
061                    sb.append(getTotal());
062    
063                    return sb.toString();
064            }
065    
066            public long getEnd() {
067                    return _end;
068            }
069    
070            public long getLength() {
071                    return _length;
072            }
073    
074            public long getStart() {
075                    return _start;
076            }
077    
078            public long getTotal() {
079                    return _total;
080            }
081    
082            @Override
083            public int hashCode() {
084                    int result = 1;
085    
086                    result = _PRIME * result + (int) (_end ^ (_end >>> 32));
087                    result = _PRIME * result + (int) (_length ^ (_length >>> 32));
088                    result = _PRIME * result + (int) (_start ^ (_start >>> 32));
089                    result = _PRIME * result + (int) (_total ^ (_total >>> 32));
090    
091                    return result;
092            }
093    
094            public void setEnd(long end) {
095                    _end = end;
096            }
097    
098            public void setLength(long length) {
099                    _length = length;
100            }
101    
102            public void setStart(long start) {
103                    _start = start;
104            }
105    
106            public void setTotal(long total) {
107                    _total = total;
108            }
109    
110            private static final int _PRIME = 31;
111    
112            private long _end;
113            private long _length;
114            private long _start;
115            private long _total;
116    
117    }