Java Code Examples for java.util.Collections.frequency()

The following are Jave code examples for showing how to use frequency() of the java.util.Collections class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: mycat-src-1.6.1-RELEASE   File: PartitionByMonth.java   View Source Code Vote up 7 votes
@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];
	}
}
 
Example 2
Project: Progetto-B   File: CardsPhase.java   View Source Code Vote up 7 votes
/**
 * 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;
}
 
Example 3
Project: guava-mock   File: AbstractIteratorTester.java   View Source Code Vote up 7 votes
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));
    }
  }
}
 
Example 4
Project: googles-monorepo-demo   File: AbstractIteratorTester.java   View Source Code Vote up 7 votes
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));
    }
  }
}
 
Example 5
Project: CS-436_580L_Introduction-to-Machine-Learning   File: LrModel.java   View Source Code Vote up 6 votes
@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;
}
 
Example 6
Project: CS-436_580L_Introduction-to-Machine-Learning   File: SimplePerceptrons.java   View Source Code Vote up 6 votes
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;
}
 
Example 7
Project: CS-436_580L_Introduction-to-Machine-Learning   File: PerceptronModel.java   View Source Code Vote up 6 votes
@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;
}
 
Example 8
Project: Progetto-B   File: BonusDeck.java   View Source Code Vote up 6 votes
/**
 * 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();
}
 
Example 9
Project: Progetto-B   File: Player.java   View Source Code Vote up 6 votes
/**
 * 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;
}
 
Example 10
Project: ja-micro   File: CircuitBreakerState.java   View Source Code Vote up 6 votes
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;
    }
}
 
Example 11
Project: candlelight   File: PomaMotivator.java   View Source Code Vote up 6 votes
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);
}
 
Example 12
Project: GitHub   File: TextUtils.java   View Source Code Vote up 5 votes
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;
}
 
Example 13
Project: rocketmq-rocketmq-all-4.1.0-incubating   File: ListDataCollectorImpl.java   View Source Code Vote up 5 votes
public boolean isRepeatedData(Object data) {
    return Collections.frequency(datas, data) == 1;
}
 
Example 14
Project: Reactive-Programming-With-Java-9   File: DemoImperative.java   View Source Code Vote up 5 votes
public int matchCount(List<String>names_input,String name)
{
	int count=Collections.frequency(names_input,name);
	return count;
}
 
Example 15
Project: rmq4note   File: ListDataCollectorImpl.java   View Source Code Vote up 5 votes
public boolean isRepeatedData(Object data) {
    return Collections.frequency(datas, data) == 1;
}