001/* 002 * Copyright 2020 Anyware Services 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.ametys.plugins.calendar.icsreader; 017 018import java.util.Date; 019import java.util.Objects; 020 021import org.ametys.plugins.calendar.events.EventsFilterHelper; 022 023/** 024 * A key class used for the events cache 025 */ 026public class CacheKey 027{ 028 private String _url; 029 private Long _nbEvents; 030 private Date _startDate; 031 private Date _endDate; 032 private Long _maxFileSize; 033 034 /** 035 * The value needed to create a key (so if there are many services with the same url but different parameters, we will use another cache) 036 * @param url ics url 037 * @param dateRange date range used to return data 038 * @param nbEvents max number of events to fetch 039 * @param maxFileSize max ics file size (in bytes) 040 */ 041 public CacheKey(String url, EventsFilterHelper.DateRange dateRange, Long nbEvents, Long maxFileSize) 042 { 043 _url = url; 044 _nbEvents = nbEvents; 045 if (dateRange != null) 046 { 047 _startDate = dateRange.getStartDate(); 048 _endDate = dateRange.getEndDate(); 049 } 050 _maxFileSize = maxFileSize; 051 } 052 053 @Override 054 public int hashCode() 055 { 056 return Objects.hash(_endDate, _maxFileSize, _nbEvents, _startDate, _url); 057 } 058 059 @Override 060 public boolean equals(Object obj) 061 { 062 if (this == obj) 063 { 064 return true; 065 } 066 if (obj == null) 067 { 068 return false; 069 } 070 if (getClass() != obj.getClass()) 071 { 072 return false; 073 } 074 CacheKey other = (CacheKey) obj; 075 return Objects.equals(_endDate, other._endDate) && Objects.equals(_maxFileSize, other._maxFileSize) && Objects.equals(_nbEvents, other._nbEvents) 076 && Objects.equals(_startDate, other._startDate) && Objects.equals(_url, other._url); 077 } 078 079}