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