001    /**
002     * Copyright (c) 2000-present 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.fabric.netty.fileserver;
016    
017    import com.liferay.portal.kernel.util.HashUtil;
018    import com.liferay.portal.kernel.util.StringBundler;
019    
020    import java.io.Serializable;
021    
022    import java.nio.file.Path;
023    import java.nio.file.Paths;
024    
025    /**
026     * @author Shuyang Zhou
027     */
028    public class FileRequest implements Serializable {
029    
030            public FileRequest(
031                    Path path, long lastModifiedTime, boolean deleteAfterFetch) {
032    
033                    _path = String.valueOf(path.toAbsolutePath());
034                    _lastModifiedTime = lastModifiedTime;
035                    _deleteAfterFetch = deleteAfterFetch;
036            }
037    
038            @Override
039            public boolean equals(Object obj) {
040                    if (this == obj) {
041                            return true;
042                    }
043    
044                    if (!(obj instanceof FileRequest)) {
045                            return false;
046                    }
047    
048                    FileRequest fileRequest = (FileRequest)obj;
049    
050                    if ((_deleteAfterFetch == fileRequest._deleteAfterFetch) &&
051                            (_lastModifiedTime == fileRequest._lastModifiedTime) &&
052                            _path.equals(fileRequest._path)) {
053    
054                            return true;
055                    }
056    
057                    return false;
058            }
059    
060            public long getLastModifiedTime() {
061                    return _lastModifiedTime;
062            }
063    
064            public Path getPath() {
065                    return Paths.get(_path);
066            }
067    
068            @Override
069            public int hashCode() {
070                    int hash = HashUtil.hash(0, _deleteAfterFetch);
071    
072                    hash = HashUtil.hash(hash, _lastModifiedTime);
073                    hash = HashUtil.hash(hash, _path);
074    
075                    return hash;
076            }
077    
078            public boolean isDeleteAfterFetch() {
079                    return _deleteAfterFetch;
080            }
081    
082            @Override
083            public String toString() {
084                    StringBundler sb = new StringBundler(7);
085    
086                    sb.append("{deleteAfterFetch=");
087                    sb.append(_deleteAfterFetch);
088                    sb.append(", lastModifiedTime=");
089                    sb.append(_lastModifiedTime);
090                    sb.append(", path=");
091                    sb.append(_path);
092                    sb.append("}");
093    
094                    return sb.toString();
095            }
096    
097            private static final long serialVersionUID = 1L;
098    
099            private final boolean _deleteAfterFetch;
100            private final long _lastModifiedTime;
101            private final String _path;
102    
103    }