// Path: kraken_lib/src/main/java/com/github/marcosalis/kraken/utils/HashUtils.java
// public final class HashUtils {
// 
//     private static final HashFunction DEFAULT_HASH = Hashing.murmur3_128();
// 
//     private HashUtils() {
//         // hidden constructor, no instantiation needed
//     }
// 
//     /**
//      * Gets a String hash generated using the default hashing algorithm with the passed strings as
//      * input.
//      */
//     @NonNull
//     public static String getDefaultHash(@NonNull String... strings) {
//         return getHash(DEFAULT_HASH, strings);
//     }
// 
//     /**
//      * Gets a String hash generated using the MD5 hashing algorithm with the passed strings as
//      * input.
//      */
//     @NonNull
//     public static String getMD5Hash(@NonNull String... strings) {
//         return getHash(Hashing.md5(), strings);
//     }
// 
//     /**
//      * Gets a String hash generated using the passed hashing algorithm.
//      */
//     @NonNull
//     public static String getHash(@NonNull HashFunction hash, @NonNull String... strings) {
//         final Hasher hasher = hash.newHasher();
//         for (String input : strings) {
//             hasher.putString(input);
//         }
//         return hasher.hash().toString();
//     }
// 
//     /**
//      * Interface that represent any suitable object that can be used as a String cache key. The key
//      * itself retrieved by calling the hash() method.
//      *
//      * TODO: move this
//      */
//     public interface CacheKey {
// 
//         public String hash();
//     }
// 
// }


import android.os.Parcel;
import android.os.Parcelable;
import android.support.annotation.NonNull;
import com.github.marcosalis.kraken.utils.HashUtils;
import com.google.common.annotations.Beta;
import com.google.common.base.Preconditions;
import com.google.common.hash.HashFunction;
import com.google.common.hash.Hashing;
import javax.annotation.concurrent.Immutable;
/*
 * Copyright 2013 Luluvise Ltd
 * Copyright 2013 Marco Salis - fast3r(at)gmail.com
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.github.marcosalis.kraken.cache.keys;




/**
 * Simple class that holds either a URL string and generates a shorter file system friendly String
 * key to be used for memory and disk caches.
 *
 * Prefer to {@link URICacheUrlKey} when there is no URL parameter striping needed.
 *
 * It implements {@link Parcelable}, so that it can be passed into Bundles.
 *
 * @author Marco Salis
 * @since 1.0
 */
@Beta
@Immutable
public class SimpleCacheUrlKey implements CacheUrlKey {

    /**
     * Currently used hash function (murmur3 128 bit algorithm)
     */
    protected static final HashFunction HASH_FUNCTION = Hashing.murmur3_128();

    @NonNull
    private final String mKey;
    @NonNull
    private final String mUrl;

    /**
     * Generate a unique key from the passed URL, ignoring any query parameters or URL fragments.
     *
     * @param url The URL to be cached
     * @throws NullPointerException if the passed string URL is null
     */
    public SimpleCacheUrlKey(@NonNull String url) {
        Preconditions.checkNotNull(url);
        mUrl = url;
        // process URI
// Path: kraken_lib/src/main/java/com/github/marcosalis/kraken/utils/HashUtils.java
// public final class HashUtils {
// 
//     private static final HashFunction DEFAULT_HASH = Hashing.murmur3_128();
// 
//     private HashUtils() {
//         // hidden constructor, no instantiation needed
//     }
// 
//     /**
//      * Gets a String hash generated using the default hashing algorithm with the passed strings as
//      * input.
//      */
//     @NonNull
//     public static String getDefaultHash(@NonNull String... strings) {
//         return getHash(DEFAULT_HASH, strings);
//     }
// 
//     /**
//      * Gets a String hash generated using the MD5 hashing algorithm with the passed strings as
//      * input.
//      */
//     @NonNull
//     public static String getMD5Hash(@NonNull String... strings) {
//         return getHash(Hashing.md5(), strings);
//     }
// 
//     /**
//      * Gets a String hash generated using the passed hashing algorithm.
//      */
//     @NonNull
//     public static String getHash(@NonNull HashFunction hash, @NonNull String... strings) {
//         final Hasher hasher = hash.newHasher();
//         for (String input : strings) {
//             hasher.putString(input);
//         }
//         return hasher.hash().toString();
//     }
// 
//     /**
//      * Interface that represent any suitable object that can be used as a String cache key. The key
//      * itself retrieved by calling the hash() method.
//      *
//      * TODO: move this
//      */
//     public interface CacheKey {
// 
//         public String hash();
//     }
// 
// }


// Path: kraken_lib/src/main/java/com/github/marcosalis/kraken/cache/keys/SimpleCacheUrlKey.java
import android.os.Parcel;
import android.os.Parcelable;
import android.support.annotation.NonNull;
import com.github.marcosalis.kraken.utils.HashUtils;
import com.google.common.annotations.Beta;
import com.google.common.base.Preconditions;
import com.google.common.hash.HashFunction;
import com.google.common.hash.Hashing;
import javax.annotation.concurrent.Immutable;

/*
 * Copyright 2013 Luluvise Ltd
 * Copyright 2013 Marco Salis - fast3r(at)gmail.com
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.github.marcosalis.kraken.cache.keys;




/**
 * Simple class that holds either a URL string and generates a shorter file system friendly String
 * key to be used for memory and disk caches.
 *
 * Prefer to {@link URICacheUrlKey} when there is no URL parameter striping needed.
 *
 * It implements {@link Parcelable}, so that it can be passed into Bundles.
 *
 * @author Marco Salis
 * @since 1.0
 */
@Beta
@Immutable
public class SimpleCacheUrlKey implements CacheUrlKey {

    /**
     * Currently used hash function (murmur3 128 bit algorithm)
     */
    protected static final HashFunction HASH_FUNCTION = Hashing.murmur3_128();

    @NonNull
    private final String mKey;
    @NonNull
    private final String mUrl;

    /**
     * Generate a unique key from the passed URL, ignoring any query parameters or URL fragments.
     *
     * @param url The URL to be cached
     * @throws NullPointerException if the passed string URL is null
     */
    public SimpleCacheUrlKey(@NonNull String url) {
        Preconditions.checkNotNull(url);
        mUrl = url;
        // process URI
        mKey = HashUtils.getHash(HASH_FUNCTION, url);