// Copyright 2012 Georg-August-Universität Göttingen, Germany // // 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 de.ugoe.cs.autoquest.coverage; import java.util.Collection; import java.util.LinkedHashMap; import java.util.LinkedHashSet; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Set; import de.ugoe.cs.autoquest.eventcore.Event; import de.ugoe.cs.autoquest.usageprofiles.IStochasticProcess; /** *
* This class gathers some helper functions to work with sequences. *
* * @author Steffen Herbold * @version 1.0 */ public class SequenceTools { /** ** Private constructor to prevent initializing of the class. *
*/ private SequenceTools() { } /** ** Calculates the weights for all sequences passed to this function as defined by the stochastic * process and stores them in a {@link Map}. The weights are normalized, i.e., the sum of all * weights contained in this map is 1. *
* * @param process * process used for weight calculation * @param sequences * sequences for which the weights are calculated * @return {@link Map} of weights */ public static Map* Calculates the number of all existing sequences of a given length, regardless whether they * are possible or not. *
* * @param process * stochastic process whose symbols are the basis for this calculation * @param length * lenght of the sequences * @return numStates^length * @throws IllegalArgumentException * thrown if length less or equal to 0 */ public static long numSequences(IStochasticProcess process, int length) { if (length <= 0) { throw new IllegalArgumentException("length must be a positive integer"); } long result = 0; if (process != null) { result = (long) Math.pow(process.getNumSymbols(), length); } return result; } /** ** Creates a {@link Set} of all subsequences of a given length that are contained in a sequence * collection. *
* * @param sequences * sequences from which the subsequences are extracted * @param length * length of the subsequences * @return {@link Set} of all subsequences * @throws IllegalArgumentException * thrown if length less or equal to 0 */ public static Set