Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright (c) 2018 Comvai, s.r.o. All Rights Reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package org.ctoolkit.services.storage;
import com.fasterxml.jackson.core.type.TypeReference;
import com.google.common.base.Charsets;
import com.google.common.base.Strings;
import com.google.common.hash.Funnel;
import com.google.common.hash.Hasher;
import com.google.common.hash.Hashing;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* The contract to manage group of entity properties overall hashcode.
*
* List of supported types in the {@link Map} that will be included in to final hash code calculation
*
*
*
{@link String}
*
{@link Long}
*
{@link Integer}
*
{@link Double}
*
{@link Boolean}
*
{@link Date}
*
{@link Enum}
*
{@link Float}
*
{@link Character}
*
*
* @author Aurel Medvegy
*/
public interface PropertiesHasher
{
String DEFAULT = "default";
/**
* Calculates (in memory only) the hashcode based on the client selected properties.
* It does not affect the persisted hashcode.
*
* It's valid to return {@code null}, however then no hash code will be stored for specified hasher name.
*
* @return the final hash code
*/
default String calcPropsHashCode()
{
return calcPropsHashCode( DEFAULT );
}
/**
* Calculates (in memory only) the hashcode based on the client selected properties.
* It does not affect the persisted hashcode.
*
* In case there are more then one {@link #DEFAULT} hasher defined,
* use the param name to distinguish between them.
*
* @param name the hasher name to distinguish which hasher to be used for hash calculation
* @return the final hash code
*/
String calcPropsHashCode( @Nonnull String name );
/**
* Calculates (in memory only) the hashcode. It's based on the client provided map of the properties.
* It does not affect the persisted hashcode.
*
* @param propertiesMap the map of the key-value properties that might contain nested map (key - another map)
* @return the final hash code
*/
@SuppressWarnings( "UnstableApiUsage" )
default String calcPropsHashCode( @Nonnull Map propertiesMap )
{
checkNotNull( propertiesMap );
Funnel