本文整理匯總了Java中java.util.HashMap.containsKey方法的典型用法代碼示例。如果您正苦於以下問題:Java HashMap.containsKey方法的具體用法?Java HashMap.containsKey怎麽用?Java HashMap.containsKey使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.util.HashMap
的用法示例。
在下文中一共展示了HashMap.containsKey方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getCachedAuditTrailLogModel
import java.util.HashMap; //導入方法依賴的package包/類
public static EcrfFieldValueAuditTrailLogEagerModel getCachedAuditTrailLogModel(ProbandListEntryOutVO listEntry,
HashMap<Long, EcrfFieldValueAuditTrailLogEagerModel> auditTrailLogModelCache) {
EcrfFieldValueAuditTrailLogEagerModel model;
if (listEntry != null && auditTrailLogModelCache != null) {
long listEntryId = listEntry.getId();
if (auditTrailLogModelCache.containsKey(listEntryId)) {
model = auditTrailLogModelCache.get(listEntryId);
} else {
model = new EcrfFieldValueAuditTrailLogEagerModel();
model.setListEntryId(listEntryId);
auditTrailLogModelCache.put(listEntryId, model);
}
} else {
model = new EcrfFieldValueAuditTrailLogEagerModel();
}
return model;
}
示例2: extractUniqueLocationIdCounts
import java.util.HashMap; //導入方法依賴的package包/類
/**
* This methods returns a unique location Id number list using given trace list.
* @param traces trace list
* @return unique ids in a list
*/
public HashMap<Long,Integer> extractUniqueLocationIdCounts(
List<ExtendedLocationTrace> traces) {
HashMap<Long,Integer> idMap = new HashMap<Long, Integer>();
for(ExtendedLocationTrace aTrace: traces){
// all location ids start from 1. if there is a lower number, it is likely that DBSCAN assigned noise to that visit
if(aTrace.getLocationId()>0){
int count = 0;
if (idMap.containsKey(aTrace.getLocationId()) == true){
count = idMap.get(aTrace.getLocationId());
}
count++;
idMap.put(aTrace.getLocationId(), count);
}
}
return idMap ;
}
示例3: getCachedCollidingVisitScheduleItemModel
import java.util.HashMap; //導入方法依賴的package包/類
public static CollidingVisitScheduleItemEagerModel getCachedCollidingVisitScheduleItemModel(ProbandStatusEntryOutVO statusEntry, boolean allProbandGroups,
HashMap<Long, CollidingVisitScheduleItemEagerModel> collidingVisitScheduleItemModelCache) {
CollidingVisitScheduleItemEagerModel model;
if (statusEntry != null && collidingVisitScheduleItemModelCache != null) {
long probandStatusEntryId = statusEntry.getId();
if (collidingVisitScheduleItemModelCache.containsKey(probandStatusEntryId)) {
model = collidingVisitScheduleItemModelCache.get(probandStatusEntryId);
} else {
model = new CollidingVisitScheduleItemEagerModel(probandStatusEntryId, allProbandGroups);
collidingVisitScheduleItemModelCache.put(probandStatusEntryId, model);
}
} else {
model = new CollidingVisitScheduleItemEagerModel(allProbandGroups);
}
return model;
}
示例4: occurenceAdderSink
import java.util.HashMap; //導入方法依賴的package包/類
/**
* Reports how often a sink occurred and how often it occurred without a source
* @param sinks
* @param sources
*/
private static void occurenceAdderSink(HashMap<String, HashSet<String>> sinks, HashMap<String, HashSet<String>> sources, HashMap<String, Integer> sinksOccurred, HashMap<String, Integer> sinksOccurredNoSource) {
for (String sink : sinks.keySet()) {
// System.out.println(sink);
if (sinksOccurred.containsKey(sink)) {
sinksOccurred.put(sink, sinksOccurred.get(sink)+1);
} else {
sinksOccurred.put(sink, 1);
sinksOccurredNoSource.put(sink,0);
}
if (sources.isEmpty()) {
sinksOccurredNoSource.put(sink, sinksOccurredNoSource.get(sink)+1);
}
}
}
示例5: SrlgGraphSearch
import java.util.HashMap; //導入方法依賴的package包/類
/**
* Creates an SRLG graph search object from a map, inferring
* the number of groups and creating an integral mapping.
*
* @param grouping map linking edges to object group assignments,
* with same-group status linked to equality
*/
public SrlgGraphSearch(Map<E, Object> grouping) {
if (grouping == null) {
useSuurballe = true;
return;
}
numGroups = 0;
HashMap<Object, Integer> tmpMap = new HashMap<>();
riskGrouping = new HashMap<>();
for (E key: grouping.keySet()) {
Object value = grouping.get(key);
if (!tmpMap.containsKey(value)) {
tmpMap.put(value, numGroups);
numGroups++;
}
riskGrouping.put(key, tmpMap.get(value));
}
}
示例6: doInBackground
import java.util.HashMap; //導入方法依賴的package包/類
@Override
protected HashMap<String, Integer> doInBackground(Void... params) {
Cursor cursor = context.getContentResolver().query(
CouponContract.CouponTable.URI,
CouponContract.CouponTable.PROJECTION,
CouponContract.CouponTable.COLUMN_VALID_UNTIL + " = ?",
new String[]{ String.valueOf(Utilities.getLongDateToday()) },
CouponContract.CouponTable.COLUMN_VALID_UNTIL
);
if (cursor == null) {
return null;
}
HashMap<String, Integer> merchantCouponCountMap = new HashMap<>();
while (cursor.moveToNext()) {
Coupon coupon = Coupon.getCoupon(cursor);
int count = 1;
if (merchantCouponCountMap.containsKey(coupon.merchant)) {
count += merchantCouponCountMap.get(coupon.merchant);
}
merchantCouponCountMap.put(coupon.merchant, count);
}
return merchantCouponCountMap;
}
示例7: getOpenNoParticipationSummary
import java.util.HashMap; //導入方法依賴的package包/類
public MoneyTransferSummaryVO getOpenNoParticipationSummary(ProbandOutVO proband) {
if (trialId != null && proband != null) {
HashMap<Long, MoneyTransferSummaryVO> cache;
MoneyTransferSummaryVO summary;
if (noParticipationOpenSummaryCache.containsKey(trialId)) {
cache = noParticipationOpenSummaryCache.get(trialId);
if (cache.containsKey(proband.getId())) {
summary = cache.get(proband.getId());
} else {
summary = WebUtil.getProbandOpenReimbursementSummary(trialId, proband.getId(), null);
cache.put(proband.getId(), summary);
}
} else {
cache = new HashMap<Long, MoneyTransferSummaryVO>();
noParticipationOpenSummaryCache.put(trialId, cache);
summary = WebUtil.getProbandOpenReimbursementSummary(trialId, proband.getId(), null);
cache.put(proband.getId(), summary);
}
return summary;
}
return null;
}
示例8: setInputModelErrorMsgs
import java.util.HashMap; //導入方法依賴的package包/類
private void setInputModelErrorMsgs(Object data) {
HashMap<Long, String> errorMessagesMap;
try {
errorMessagesMap = (HashMap<Long, String>) data;
} catch (ClassCastException e) {
errorMessagesMap = null;
}
if (errorMessagesMap != null && errorMessagesMap.size() > 0) {
Iterator<ProbandListEntryTagInputModel> it = inputModels.iterator();
while (it.hasNext()) {
ProbandListEntryTagInputModel inputModel = it.next();
if (errorMessagesMap.containsKey(inputModel.getProbandListTagId())) {
inputModel.setErrorMessage(errorMessagesMap.get(inputModel.getProbandListTagId()));
} else {
inputModel.setErrorMessage(null);
}
}
} else {
clearInputModelErrorMsgs();
}
}
示例9: countGames
import java.util.HashMap; //導入方法依賴的package包/類
private void countGames(HashMap<String, AtomicInteger> hm, int length, String startsWith) {
for (String game : games) {
String str = null;
if (game.length() >= length) {
str = game.substring(0, length);
}
if (str != null && (startsWith == null || str.startsWith(startsWith))) {
if (hm.containsKey(str)) {
hm.get(str).incrementAndGet();
} else {
hm.put(str, new AtomicInteger(1));
}
}
}
if (length == 1) {
checkKeys(hm, length);
}
}
示例10: dispatchSBDExport
import java.util.HashMap; //導入方法依賴的package包/類
/**
* Generates the necessary files for the forms upload to the SeaBioData repository
*/
private void dispatchSBDExport() throws IOException {
SharedPreferences settings = getSharedPreferences(getString(R.string.app_name), MODE_PRIVATE);
if (!settings.contains(Utils.TAG_SBD_USERNAME)) {
Toast.makeText(this, getString(R.string.sbd_username_missing_export), Toast.LENGTH_SHORT).show();
return;
}
HashMap<String, ArrayList<FormInstance>> groupedInstances = new HashMap<>();
for (FormInstance fi : currentItem.getLinkedForms()) {
if (groupedInstances.containsKey(fi.getParent())) {
groupedInstances.get(fi.getParent()).add(fi);
continue;
}
ArrayList<FormInstance> newInstances = new ArrayList<>();
newInstances.add(fi);
groupedInstances.put(fi.getParent(), newInstances);
}
for (String key : groupedInstances.keySet()) {
FormExportItem exportItem = new FormExportItem(groupedInstances.get(key), settings.getString(Utils.TAG_SBD_USERNAME, ""));
File file = new File(Environment.getExternalStorageDirectory() + File.separator + key + "_" + new Date().toString() + ".json");
if(file.createNewFile()) {
OutputStream fo = new FileOutputStream(file);
fo.write(new Gson().toJson(exportItem).getBytes());
fo.close();
}
}
Toast.makeText(getApplicationContext(), getString(R.string.sbd_dorms_exported_successfully), Toast.LENGTH_SHORT).show();
}
示例11: annotateWithPileup
import java.util.HashMap; //導入方法依賴的package包/類
private Double annotateWithPileup(final AlignmentContext stratifiedContext, final VariantContext vc) {
final HashMap<Byte, Integer> alleleCounts = new HashMap<>();
for (final Allele allele : vc.getAlleles())
alleleCounts.put(allele.getBases()[0], 0);
final ReadBackedPileup pileup = stratifiedContext.getBasePileup();
for (final PileupElement p : pileup) {
if (alleleCounts.containsKey(p.getBase()))
alleleCounts.put(p.getBase(), alleleCounts.get(p.getBase()) + 1);
}
// we need to add counts in the correct order
final int[] counts = new int[alleleCounts.size()];
counts[0] = alleleCounts.get(vc.getReference().getBases()[0]);
for (int i = 0; i < vc.getAlternateAlleles().size(); i++)
counts[i + 1] = alleleCounts.get(vc.getAlternateAllele(i).getBases()[0]);
// sanity check
if (counts[0] + counts[1] == 0)
return null;
return ((double) counts[0] / (double) (counts[0] + counts[1]));
}
示例12: twoSum
import java.util.HashMap; //導入方法依賴的package包/類
public int[] twoSum(int[] nums, int target) {
int len = nums.length;
HashMap<Integer, Integer> map = new HashMap<>();
for (int i = 0; i < len; ++i) {
if (map.containsKey(nums[i])) {
return new int[]{map.get(nums[i]), i};
}
map.put(target - nums[i], i);
}
return null;
}
示例13: main
import java.util.HashMap; //導入方法依賴的package包/類
public static void main(String[] args) {
//create HashMap object
HashMap hMap = new HashMap();
//add key value pairs to HashMap
hMap.put("1", "One");
hMap.put("2", "Two");
hMap.put("3", "Three");
/*
get Set of keys contained in HashMap using
Set keySet() method of HashMap class
*/
Set st = hMap.keySet();
System.out.println("Set created from HashMap Keys contains :");
//iterate through the Set of keys
Iterator itr = st.iterator();
while (itr.hasNext()) System.out.println(itr.next());
/*
Please note that resultant Set object is backed by the HashMap.
Any key that is removed from Set will also be removed from
original HashMap object. The same is not the case with the element
addition.
*/
//remove 2 from Set
st.remove("2");
//check if original HashMap still contains 2
boolean blnExists = hMap.containsKey("2");
System.out.println("Does HashMap contain 2 ? " + blnExists);
}
示例14: occurrenceAnalyzer
import java.util.HashMap; //導入方法依賴的package包/類
/**
* Reports Flows where the sink did not occur for all mutated files. It also reports how often a sink occurred and whether it occurred for files where no source was mutated.
* @param flowocc
* @param sinkCounter
* @param occurredForNoSource
* @param fileCounter
* @param writer
* @param flowPosition
* @param crashReports
*/
private static void occurrenceAnalyzer(HashMap<String, HashMap<String, Integer>> flowocc, HashMap<String, Integer> sinkCounter, HashSet<String> occurredForNoSource,float fileCounter, int noMutationCounter,
PrintWriter writer, HashMap<String, HashMap<String, String>> flowPosition, HashMap<String, HashMap<String, Boolean>> crashReports, HashMap<String, HashSet<String>> refoundFlows) {
if (notCondensed) {
writer.write("\nDroidMutant found the following flows. Such without a number indicate flows, where a value was again found in the sink: \n");
}
for (Entry<String, HashSet<String>> ent : refoundFlows.entrySet()) {
for (String sink : ent.getValue()) {
writer.write(ent.getKey()+"\t"+sink+"\n");
refoundCounter++;
}
}
for (Entry<String,HashMap<String, Integer>> sourceEntry : flowocc.entrySet()) {
for (Entry<String,Integer> sinkEntry : sourceEntry.getValue().entrySet()) {
if (!sinkCounter.get(sinkEntry.getKey()).equals(fileCounter)) { //if sink did not occur for all mutated files
float sinkCount = sinkCounter.get(sinkEntry.getKey());
if (!occurredForNoSource.contains(sinkEntry.getKey())) {
if ((!refoundFlows.containsKey(sourceEntry.getKey())) || (!refoundFlows.get(sourceEntry.getKey()).contains(sinkEntry.getKey()))) {
writer.write(sourceEntry.getKey()+"\t"+sinkEntry.getKey()+"\t"+sinkCount+"\t"+fileCounter + "\t" + (occurredForNoSource.contains(sinkEntry.getKey()) ? 0 : 1)+"\t"+noMutationCounter+ "\n");
}
HashMap<String, Boolean> currentAPKMap = crashReports.get(FlowExtractor.currentAPK);
//crashes with NPE if Converter was not run firstly
boolean crashed = false;
System.out.println(flowPosition.get(sourceEntry.getKey()).get(sinkEntry.getKey()) +" " + sourceEntry.getKey() + " " + sinkEntry.getKey() + " " + crashed );
}
}
}
}
}
示例15: checkLogin
import java.util.HashMap; //導入方法依賴的package包/類
private boolean checkLogin(HttpRequest request) {
boolean res = false;
// в запросе должен быть пароль и пользователь, если нету, то отказ на вход
String entityContent = NetUtil.getEntityContent(request);
QLog.l().logger().trace("Принятые параметры \"" + entityContent + "\".");
// ресурс для выдачи в браузер. это либо список отчетов при корректном логининге или отказ на вход
// разбирем параметры
final HashMap<String, String> cookie = NetUtil.getCookie(entityContent, "&");
if (cookie.containsKey("username") && cookie.containsKey("password")) {
if (isTrueUser(cookie.get("username"), cookie.get("password"))) {
res = true;
}
}
return res;
}