// Path: core/src/main/java/org/hashes/algorithm/HashAlgorithm.java
// public interface HashAlgorithm {
// 
//     /**
//      * Computes the hash code of the specified key.
//      * 
//      * @param key the key to compute the hash code
//      * @return the hash code
//      */
//     int hash(String key);
// 
// }
// 
// Path: core/src/main/java/org/hashes/progress/ProgressMonitor.java
// public interface ProgressMonitor {
// 
//     /**
//      * Updates the progress of the task.
//      * <p>
//      * The progress can be updated from several threads, so the incremental work is not assured.
//      * 
//      * @param work a non negative number of work units just completed.
//      */
//     void update(int work);
// 
//     /**
//      * Notifies that the work is done.
//      */
//     void done();
// 
// }


import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.hashes.algorithm.HashAlgorithm;
import org.hashes.progress.ProgressMonitor;
/**
 *    Copyright 2012 Pedro Ribeiro
 *
 *    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 org.hashes.collision;



/**
 * Base class of equivalent substrings hash collision generator.
 * 
 * @author ribeirux
 * @version $Revision$
 */
public abstract class AbstractEquivalentSubstringsGenerator extends AbstractCollisionGenerator {

    /**
     * Initializes the hash algorithm.
     * 
     * @param hashAlgorithm the hash algorithm
     */
    public AbstractEquivalentSubstringsGenerator(final HashAlgorithm hashAlgorithm) {
        super(hashAlgorithm);
    }

    @Override
    protected List<String> generateNewCollisions(final int numberOfKeys, final ProgressMonitor monitor) {
        final List<String> seed = this.buildSeed();

        final List<String> generatedKeys = new ArrayList<String>(numberOfKeys);

        // just don't update the progress, this is really fast! 
        if (numberOfKeys <= seed.size()) {
// Path: core/src/main/java/org/hashes/algorithm/HashAlgorithm.java
// public interface HashAlgorithm {
// 
//     /**
//      * Computes the hash code of the specified key.
//      * 
//      * @param key the key to compute the hash code
//      * @return the hash code
//      */
//     int hash(String key);
// 
// }
// 
// Path: core/src/main/java/org/hashes/progress/ProgressMonitor.java
// public interface ProgressMonitor {
// 
//     /**
//      * Updates the progress of the task.
//      * <p>
//      * The progress can be updated from several threads, so the incremental work is not assured.
//      * 
//      * @param work a non negative number of work units just completed.
//      */
//     void update(int work);
// 
//     /**
//      * Notifies that the work is done.
//      */
//     void done();
// 
// }


// Path: core/src/main/java/org/hashes/collision/AbstractEquivalentSubstringsGenerator.java
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.hashes.algorithm.HashAlgorithm;
import org.hashes.progress.ProgressMonitor;

/**
 *    Copyright 2012 Pedro Ribeiro
 *
 *    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 org.hashes.collision;



/**
 * Base class of equivalent substrings hash collision generator.
 * 
 * @author ribeirux
 * @version $Revision$
 */
public abstract class AbstractEquivalentSubstringsGenerator extends AbstractCollisionGenerator {

    /**
     * Initializes the hash algorithm.
     * 
     * @param hashAlgorithm the hash algorithm
     */
    public AbstractEquivalentSubstringsGenerator(final HashAlgorithm hashAlgorithm) {
        super(hashAlgorithm);
    }

    @Override
    protected List<String> generateNewCollisions(final int numberOfKeys, final ProgressMonitor monitor) {
        final List<String> seed = this.buildSeed();

        final List<String> generatedKeys = new ArrayList<String>(numberOfKeys);

        // just don't update the progress, this is really fast! 
        if (numberOfKeys <= seed.size()) {
            generatedKeys.addAll(seed.subList(0, numberOfKeys));