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

The following examples show how to use java.util.Collections#frequency() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
public RescheduleTimerJobCmd(String timerJobId, String timeDate, String timeDuration, String timeCycle, String endDate, String calendarName) {
    if (timerJobId == null) {
        throw new FlowableIllegalArgumentException("The timer job id is mandatory, but 'null' has been provided.");
    }

    int timeValues = Collections.frequency(Arrays.asList(timeDate, timeDuration, timeCycle), null);
    if (timeValues == 0) {
        throw new FlowableIllegalArgumentException("A non-null value is required for one of timeDate, timeDuration, or timeCycle");
    } else if (timeValues != 2) {
        throw new FlowableIllegalArgumentException("At most one non-null value can be provided for timeDate, timeDuration, or timeCycle");
    }

    if (endDate != null && timeCycle == null) {
        throw new FlowableIllegalArgumentException("An end date can only be provided when rescheduling a timer using timeDuration.");
    }

    this.timerJobId = timerJobId;
    this.timeDate = timeDate;
    this.timeDuration = timeDuration;
    this.timeCycle = timeCycle;
    this.endDate = endDate;
    this.calendarName = calendarName;
}
 
Example 2
Source Project: triplea   File: TechPanel.java    License: GNU General Public License v3.0 6 votes vote down vote up
private static String getTechListToolTipText(final TechnologyFrontier techCategory) {
  final List<TechAdvance> techList = techCategory.getTechs();
  if (techList.size() <= 1) {
    return null;
  }
  final Collection<TechAdvance> listedAlready = new HashSet<>();
  final StringBuilder strTechCategory = new StringBuilder("Available Techs:  ");
  final Iterator<TechAdvance> iterTechList = techList.iterator();
  while (iterTechList.hasNext()) {
    final TechAdvance advance = iterTechList.next();
    if (listedAlready.contains(advance)) {
      continue;
    }
    listedAlready.add(advance);
    final int freq = Collections.frequency(techList, advance);
    strTechCategory
        .append(advance.getName())
        .append(freq > 1 ? " (" + freq + "/" + techList.size() + ")" : "");
    if (iterTechList.hasNext()) {
      strTechCategory.append(", ");
    }
  }
  return strTechCategory.toString();
}
 
Example 3
Source Project: majiang_algorithm   File: AIUtil.java    License: MIT License 6 votes vote down vote up
public static boolean chiAI(List<Integer> input, List<Integer> guiCard, int card, int card1, int card2)
{
	if (guiCard.contains(card) || guiCard.contains(card1) || guiCard.contains(card2))
	{
		return false;
	}

	if (Collections.frequency(input, card1) < 1 || Collections.frequency(input, card2) < 1)
	{
		return false;
	}

	double score = calc(input, guiCard);

	List<Integer> tmp = new ArrayList<>(input);
	tmp.remove((Integer) card1);
	tmp.remove((Integer) card2);
	double scoreNew = calc(tmp, guiCard);

	return scoreNew >= score;
}
 
Example 4
Source Project: xibalba   File: ItemHelpers.java    License: MIT License 6 votes vote down vote up
/**
 * Get the stone material for a crafted item.
 *
 * @param components List of components to look through
 * @return The most occurring stone material type among the components
 */
public ItemComponent.StoneMaterial materialFromComponents(ArrayList<Entity> components) {
  ArrayList<ItemComponent.StoneMaterial> materials = new ArrayList<>();

  for (Entity component : components) {
    ItemComponent componentDetails = ComponentMappers.item.get(component);

    if (componentDetails.stoneMaterial != null) {
      materials.add(componentDetails.stoneMaterial);
    }
  }

  int max = 0;
  ItemComponent.StoneMaterial highest = null;

  for (ItemComponent.StoneMaterial material : materials) {
    int frequency = Collections.frequency(materials, material);

    if (max < frequency) {
      max = frequency;
      highest = material;
    }
  }

  return highest;
}
 
Example 5
Source Project: estatio   File: Lease.java    License: Apache License 2.0 5 votes vote down vote up
@Programmatic
public LeaseStatus getEffectiveStatus() {
    List<LeaseItem> all = Lists.newArrayList(getItems());
    int itemCount = getItems().size();
    List<LeaseItemStatus> statusList = Lists.transform(all, leaseItem -> leaseItem.getStatus());
    int suspensionCount = Collections.frequency(statusList, LeaseItemStatus.SUSPENDED);
    if (suspensionCount > 0) {
        if (itemCount == suspensionCount) {
            return LeaseStatus.SUSPENDED;
        } else {
            return LeaseStatus.SUSPENDED_PARTIALLY;
        }
    }
    return null;
}
 
Example 6
/**
 * Adjusts the word frequencies to take account of a sentence. The frequency of each word in the
 * sentence is reduced by the number of times it appears in the sentence.
 *
 * @param topWeightedSentence The sentence used to adjust the word frequencies
 * @return a map between words and (adjusted) frequencies
 */
public Map<String, Integer> adjustWordFrequencies(String topWeightedSentence) {

  Map<String, Integer> newFrequencies = new HashMap<>(wordFrequencies);

  Collection<String> wordsInSentence = sentenceToWordsStringMap.get(topWeightedSentence);

  for (String word : wordsInSentence) {
    int numberOfTimesWordOccursInSentence = Collections.frequency(wordsInSentence, word);
    int newFrequency = wordFrequencies.get(word) - numberOfTimesWordOccursInSentence;
    newFrequencies.put(word, newFrequency);
  }

  return newFrequencies;
}
 
Example 7
@Override
public int[] calculateIndexRange(String beginValue, String endValue) {
  long beginDate = getTime(beginValue);
  long endDate = getTime(endValue);
  ArrayList<Integer> list = new ArrayList<>();
  while (beginDate <= endDate) {
    int nodeValue = innerCalculate(beginDate);
    if (Collections.frequency(list, nodeValue) < 1) {
      list.add(nodeValue);
    }
    beginDate += ONE_DAY;
  }
  return ints(list);
}
 
Example 8
Source Project: Thunder   File: UserEntity.java    License: Apache License 2.0 5 votes vote down vote up
public void setOperations(List<UserOperation> operations) {
    if (operations == null) {
        throw new IllegalArgumentException("Operations can't be null");
    }

    this.operations = new ArrayList<UserOperation>();

    for (UserOperation operation : operations) {
        if (Collections.frequency(this.operations, operation) < 1) {
            this.operations.add(operation);
        }
    }
}
 
Example 9
Source Project: JavaRush   File: Solution.java    License: MIT License 5 votes vote down vote up
public void run() {
  try {
    FileInputStream fileInputStream = new FileInputStream(fileName);
    ArrayList<Integer> list = new ArrayList<>();
    while (fileInputStream.available() > 0) {
      int data = fileInputStream.read();
      list.add(data);
    }
    fileInputStream.close();

    int max = 0;
    int id = 0;
    int count;

    for (int a = 0; a < list.size(); a++) {
      count = Collections.frequency(list, list.get(a));
      if (count > max) {
        max = count;
        id = list.get(a);
      }
    }

    resultMap.put(fileName, id);

  } catch (Exception ignored) {
  }
}
 
Example 10
public void run() throws XmppException {
    mXmppClient.connect();
    mXmppClient.login(mJid.getLocal(), mPassword, "ComplianceTester");
    preHook();
    for(Class<? extends AbstractTest> test : getTests()) {
        run(test);
    }
    postHook();
    mXmppClient.close();
    int passed = Collections.frequency(mTestResults.values(),Result.PASSED);
    System.out.println("passed "+passed+"/"+mTestResults.size());
}
 
Example 11
Source Project: fastquery   File: StructureFilter.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Element doFilter(String xmlName, Element element) {
	StringBuilder sb = new StringBuilder(xmlName);
	sb.append(", <query id=\"");
	sb.append(element.getAttribute("id"));
	sb.append("\">");
	List<String> elementNames = new ArrayList<>(); // 把query的子ELEMENT_NODE的name,全部存储起来
	NodeList partNodes = element.getChildNodes();
	for (int j = 0; j < partNodes.getLength(); j++) {
		Node partNode = partNodes.item(j);
		short nodeType = partNode.getNodeType();
		if (nodeType == Node.ELEMENT_NODE) {
			elementNames.add(partNode.getNodeName());
		}
	}

	// 统计value节点的个数
	if (Collections.frequency(elementNames, "value") > 1) {
		this.abortWith(sb.toString() + " 该节点下面所包裹的value节点最多只能出现一次");
	}

	if (Collections.frequency(elementNames, "countQuery") > 1) {
		this.abortWith(sb.toString() + " 该节点下面所包裹的countQuery节点最多只能出现一次");
	}

	if (Collections.frequency(elementNames, "parts") > 1) {
		this.abortWith(sb.toString() + " 该节点下面所包裹的parts节点最多只能出现一次");
	}

	if (!elementNames.isEmpty() && !elementNames.contains("value")) { // 如果不为空,且不包含value
		this.abortWith(sb.toString() + " 该节点下面所包裹的要么全部是文本内容,要么就必须存在value节点");
	}
	return element;
}
 
Example 12
Source Project: sundrio   File: FunctionFactory.java    License: Apache License 2.0 5 votes vote down vote up
public Y apply(X item) {
    Y result;
    synchronized (function) {
        ownStack.push(item);
        globalStack.push(item);
        try {
            result = cache != null ? cache.get(item) : null;
            if (result == null) {
                int recursionLevel = ownStack != null ? Collections.frequency(ownStack, item) : 0;
                int nestingDepth = globalStack.size();
                boolean recursionLevelExceeded = recursionLevel > maximumRecursionLevel && maximumRecursionLevel > 0;
                boolean nestringDeptExceeded =nestingDepth > maximumNestingDepth && maximumNestingDepth > 0;
                boolean predicateMatched = fallbackPredicate != null && fallbackPredicate.apply(item);
                if ((recursionLevelExceeded || nestringDeptExceeded || predicateMatched) && fallback != null) {
                    result = fallback.apply(item);
                }  else {
                    result = function.apply(item);
                    cacheIfEnabled(item, result);
                }
            }
        } finally {
            ownStack.pop();
            globalStack.pop();
        }
        return result;
    }
}
 
Example 13
/**
 * Flag the insertion position in a list of dimension definition based on the
 * location of the base dimension.
 *
 * @param dimensions List of dimension definition to be flagged.
 */
public static void flagInsertPosition(List<DimensionDefinition> dimensions) {
  int baseDimensionNb =
      Collections.frequency(dimensions, DimensionDefinition.BASE_DIMENSION);

  boolean hasMiddleInsertion = baseDimensionNb > 1;
  InsertionPosition crtPos = InsertionPosition.BEFORE;
  for(DimensionDefinition dim : dimensions) {
    if(dim == DimensionDefinition.BASE_DIMENSION) {
      crtPos = crtPos.getNext(hasMiddleInsertion);
    } else {
      dim.setInsertionPosition(crtPos);
    }
  }
}
 
Example 14
Source Project: DDMQ   File: ListDataCollectorImpl.java    License: Apache License 2.0 4 votes vote down vote up
public boolean isRepeatedData(Object data) {
    return Collections.frequency(datas, data) == 1;
}
 
Example 15
Source Project: tutorials   File: VerifyAllEqualListElements.java    License: MIT License 4 votes vote down vote up
public boolean verifyAllEqualUsingFrequency(List<String> list) {
    return list.isEmpty() || Collections.frequency(list, list.get(0)) == list.size();
}
 
Example 16
public Result result() {
    return Collections.frequency(mTestResults.values(),Result.FAILED) == 0 ? Result.PASSED : Result.FAILED;
}
 
Example 17
Source Project: rocketmq   File: ListDataCollectorImpl.java    License: Apache License 2.0 4 votes vote down vote up
public boolean isRepeatedData(Object data) {
    return Collections.frequency(datas, data) == 1;
}
 
Example 18
private static void showPresenceSelectionDialog(final Activity activity, final Contact contact, final String[] resourceArray, final OnFullJidSelected onFullJidSelected) {
    final Presences presences = contact.getPresences();
    AlertDialog.Builder builder = new AlertDialog.Builder(activity);
    builder.setTitle(activity.getString(R.string.choose_presence));
    Pair<Map<String, String>, Map<String, String>> typeAndName = presences.toTypeAndNameMap();
    final Map<String, String> resourceTypeMap = typeAndName.first;
    final Map<String, String> resourceNameMap = typeAndName.second;
    final String[] readableIdentities = new String[resourceArray.length];
    final AtomicInteger selectedResource = new AtomicInteger(0);
    for (int i = 0; i < resourceArray.length; ++i) {
        String resource = resourceArray[i];
        if (resource.equals(contact.getLastResource())) {
            selectedResource.set(i);
        }
        String type = resourceTypeMap.get(resource);
        String name = resourceNameMap.get(resource);
        if (type != null) {
            if (Collections.frequency(resourceTypeMap.values(), type) == 1) {
                readableIdentities[i] = translateType(activity, type);
            } else if (name != null) {
                if (Collections.frequency(resourceNameMap.values(), name) == 1
                        || CryptoHelper.UUID_PATTERN.matcher(resource).matches()) {
                    readableIdentities[i] = translateType(activity, type) + "  (" + name + ")";
                } else {
                    readableIdentities[i] = translateType(activity, type) + " (" + name + " / " + resource + ")";
                }
            } else {
                readableIdentities[i] = translateType(activity, type) + " (" + resource + ")";
            }
        } else {
            readableIdentities[i] = resource;
        }
    }
    builder.setSingleChoiceItems(readableIdentities,
            selectedResource.get(),
            (dialog, which) -> selectedResource.set(which));
    builder.setNegativeButton(R.string.cancel, null);
    builder.setPositiveButton(
            R.string.ok,
            (dialog, which) -> onFullJidSelected.onFullJidSelected(
                    getNextCounterpart(contact, resourceArray[selectedResource.get()])
            )
    );
    builder.create().show();
}
 
Example 19
Source Project: rocketmq   File: ListDataCollectorImpl.java    License: Apache License 2.0 4 votes vote down vote up
public boolean isRepeatedData(Object data) {
    return Collections.frequency(datas, data) == 1;
}
 
Example 20
Source Project: DDMQ   File: ListDataCollectorImpl.java    License: Apache License 2.0 4 votes vote down vote up
public boolean isRepeatedData(Object data) {
    return Collections.frequency(datas, data) == 1;
}