本文整理匯總了Java中java.util.Collections.frequency方法的典型用法代碼示例。如果您正苦於以下問題:Java Collections.frequency方法的具體用法?Java Collections.frequency怎麽用?Java Collections.frequency使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.util.Collections
的用法示例。
在下文中一共展示了Collections.frequency方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: calculateRange
import java.util.Collections; //導入方法依賴的package包/類
@Override
public Integer[] calculateRange(String beginValue, String endValue) {
try {
int startPartition, endPartition;
Calendar partitionTime = Calendar.getInstance();
SimpleDateFormat format = new SimpleDateFormat(dateFormat);
partitionTime.setTime(format.parse(beginValue));
startPartition = ((partitionTime.get(Calendar.YEAR) - beginDate.get(Calendar.YEAR))
* 12 + partitionTime.get(Calendar.MONTH)
- beginDate.get(Calendar.MONTH));
partitionTime.setTime(format.parse(endValue));
endPartition = ((partitionTime.get(Calendar.YEAR) - beginDate.get(Calendar.YEAR))
* 12 + partitionTime.get(Calendar.MONTH)
- beginDate.get(Calendar.MONTH));
List<Integer> list = new ArrayList<>();
while (startPartition <= endPartition) {
Integer nodeValue = reCalculatePartition(startPartition);
if (Collections.frequency(list, nodeValue) < 1)
list.add(nodeValue);
startPartition++;
}
int size = list.size();
return (list.toArray(new Integer[size]));
} catch (ParseException e) {
LOGGER.error(e);
return new Integer[0];
}
}
示例2: isAValidTris
import java.util.Collections; //導入方法依賴的package包/類
/**
* Checks if <code>chosenCards</code> is a valid tris.
*
* @param chosenCards
* @return
*/
public boolean isAValidTris(String[] chosenCards) {
for (Card[] validCardArray : deck.getTris().keySet()) {
boolean success = true;
for (Card card : validCardArray) {
/**
* The tris is valid if and only each cards appears the same
* number of times in <code>chosenCards</code> as it does in
* <code>validCardArray</code>.
*/
success = success && (Collections.frequency(Arrays.asList(deck.getCardsByNames(chosenCards)), card)) == (Collections.frequency(Arrays.asList(validCardArray), card));
}
if (success) {
return success;
}
}
return false;
}
示例3: compareResultsForThisListOfStimuli
import java.util.Collections; //導入方法依賴的package包/類
private void compareResultsForThisListOfStimuli() {
int removes = Collections.frequency(Arrays.asList(stimuli), remove);
if ((!features.contains(IteratorFeature.SUPPORTS_REMOVE) && removes > 1)
|| (stimuli.length >= 5 && removes > 2)) {
// removes are the most expensive thing to test, since they often throw exceptions with stack
// traces, so we test them a bit less aggressively
return;
}
MultiExceptionListIterator reference = new MultiExceptionListIterator(expectedElements);
I target = newTargetIterator();
for (int i = 0; i < stimuli.length; i++) {
try {
stimuli[i].executeAndCompare(reference, target);
verify(reference.getElements());
} catch (AssertionFailedError cause) {
Helpers.fail(cause, "failed with stimuli " + subListCopy(stimuli, i + 1));
}
}
}
示例4: test
import java.util.Collections; //導入方法依賴的package包/類
@Override
public int test(Document document) {
int x[] = new int[vocabulary.size()];
for (int i = 0; i < x.length; i++) {
x[i] = Collections.frequency(document.getTerms(), vocabulary.get(i));
}
double pr = weights[0];
for (int i = 1; i <= x.length; i++) {
pr += (weights[i] * x[i - 1]);
}
return (pr > 0) ? Document.Class.HAM : Document.Class.SPAM;
}
示例5: constructDataMatrix
import java.util.Collections; //導入方法依賴的package包/類
private int[][] constructDataMatrix(List<Document> trainingDataSet, List<String> vocabulary) {
int data[][] = new int[trainingDataSet.size()][vocabulary.size() + 2];
for (int i = 0; i < trainingDataSet.size(); i++) {
Document document = trainingDataSet.get(i);
data[i][0] = DUMMY_THRESHOLD;
for (int j = 1; j <= vocabulary.size(); j++) {
data[i][j] = Collections.frequency(document.getTerms(), vocabulary.get(j - 1));
}
data[i][vocabulary.size() + 1] = document.getDocumentClass();
}
return data;
}
開發者ID:MarkXLII,項目名稱:CS-436_580L_Introduction-to-Machine-Learning,代碼行數:13,代碼來源:SimplePerceptrons.java
示例6: test
import java.util.Collections; //導入方法依賴的package包/類
@Override
public int test(Document document) {
int x[] = new int[vocabulary.size()];
for (int i = 0; i < x.length; i++) {
x[i] = Collections.frequency(document.getTerms(), vocabulary.get(i));
}
double o = weights[0];
for (int i = 1; i < x.length; i++) {
o += (x[i - 1] * weights[i]);
}
return (o > 0) ? Document.Class.HAM : Document.Class.SPAM;
}
示例7: getBonusForTris
import java.util.Collections; //導入方法依賴的package包/類
/**
* Given a tris of cards it returns the corresponding bonus; if it doesn't
* find the tris it throws an excption.
*
* @param cards
* @return
*/
public int getBonusForTris(Card[] cards) throws TrisNotFoundException {
for (Card[] set : tris.keySet()) {
boolean success = true;
for (Card card : set) {
success = success && (Collections.frequency(Arrays.asList(set), card)) == (Collections.frequency(Arrays.asList(cards), card));
}
if (success) {
return tris.get(set);
}
}
throw new TrisNotFoundException();
}
示例8: canPlayThisTris
import java.util.Collections; //導入方法依賴的package包/類
/**
* Tells wheter the player has enough cards to play the tris
* <code>cards</code>.
*
* @param cards
* @return
*/
public boolean canPlayThisTris(Card[] cards) {
boolean success = true;
for (Card card : cards) {
success = success && (Collections.frequency(bonusCards, card)) >= (Collections.frequency(Arrays.asList(cards), card));
}
return success;
}
示例9: hasFailed
import java.util.Collections; //導入方法依賴的package包/類
private boolean hasFailed() {
int size = responseHistory.size();
if (size < HISTORY_SIZE) {
return false;
} else if (size > HISTORY_SIZE) {
logger.warn("Unexpected responseHistory size: {}", size);
return false;
} else {
int occurrences = Collections.frequency(responseHistory, Boolean.FALSE);
return occurrences >= HISTORY_SIZE;
}
}
示例10: waitForMotivation
import java.util.Collections; //導入方法依賴的package包/類
private static void waitForMotivation()
{
int i = SIR_RANDY.nextInt(NONDIMINISHING_RETURNS.size());
LITTLE_HOUSE_OF_INTS.add(i);
int ifreq = Collections.frequency(LITTLE_HOUSE_OF_INTS, i);
if (ifreq >= BOREDOM_CONSTANT)
{
i = findMoreMotivation();
LITTLE_HOUSE_OF_INTS.add(i);
}
Object cake = findRandomCake();
Consumer<Object> consumer = pick(NONDIMINISHING_RETURNS, i);
consumer.accept(cake);
}
示例11: toUniqueFieldNameVariable
import java.util.Collections; //導入方法依賴的package包/類
public static String toUniqueFieldNameVariable(String fieldName, List<String> processedFieldNames) {
fieldName = fieldName.replaceAll("[^a-zA-Z0-9]", "_");
int frequency = Collections.frequency(processedFieldNames, fieldName);
processedFieldNames.add(fieldName);
return (frequency > 0) ? fieldName + frequency : fieldName;
}
示例12: isRepeatedData
import java.util.Collections; //導入方法依賴的package包/類
public boolean isRepeatedData(Object data) {
return Collections.frequency(datas, data) == 1;
}
示例13: matchCount
import java.util.Collections; //導入方法依賴的package包/類
public int matchCount(List<String>names_input,String name)
{
int count=Collections.frequency(names_input,name);
return count;
}