本文整理汇总了Java中java.util.HashMap.size方法的典型用法代码示例。如果您正苦于以下问题:Java HashMap.size方法的具体用法?Java HashMap.size怎么用?Java HashMap.size使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.HashMap
的用法示例。
在下文中一共展示了HashMap.size方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setData
import java.util.HashMap; //导入方法依赖的package包/类
public void setData(Platform[] platforms, HashMap<String, String> hiddenPlatforms) {
if (platforms != null) {
if (hiddenPlatforms == null || hiddenPlatforms.size() <= 0) {
this.logos.addAll(Arrays.asList(platforms));
} else {
ArrayList<Platform> ps = new ArrayList();
for (Platform p : platforms) {
if (!hiddenPlatforms.containsKey(p.getName())) {
ps.add(p);
}
}
this.logos.addAll(ps);
}
this.checkedPositionList.clear();
notifyDataSetChanged();
}
}
示例2: mergeMethods
import java.util.HashMap; //导入方法依赖的package包/类
private MethodDescriptor[] mergeMethods(MethodDescriptor[] superDescs) {
HashMap<String, MethodDescriptor> subMap = internalAsMap(methods);
for (MethodDescriptor superMethod : superDescs) {
String methodName = getQualifiedName(superMethod.getMethod());
MethodDescriptor method = subMap.get(methodName);
if (method == null) {
subMap.put(methodName, superMethod);
} else {
method.merge(superMethod);
}
}
MethodDescriptor[] theMethods = new MethodDescriptor[subMap.size()];
subMap.values().toArray(theMethods);
return theMethods;
}
示例3: searchForDevice
import java.util.HashMap; //导入方法依赖的package包/类
private void searchForDevice(Context context) {
HashMap<String, UsbDevice> devices = mUsbManager.getDeviceList();
UsbDevice selected = null;
int num_of_devices = devices.size();
if (num_of_devices == 1) {
//If there's only one device, go ahead and connect. YOLO to keyboards!
for (UsbDevice device : devices.values()) {
selected = device;
}
if (mUsbManager.hasPermission(selected)) {
setUSBDevice(selected);
} else {
mUsbManager.requestPermission(selected, mPermissionIntent);
}
} else {
if (num_of_devices > 1) {
Log.wtf(TAG, "Extra devices are plugged in. Found: " + num_of_devices);
}
showListOfDevices(context);
}
}
示例4: PostData
import java.util.HashMap; //导入方法依赖的package包/类
public static String PostData(String url, HashMap<String, String> params) {
try {
FormBody.Builder build = new FormBody.Builder();
int len = params.size();
if (len <= 0) {
return "";
}
Set<String> keys = params.keySet();
for (String s : keys) {
build.add(s, params.get(s));
}
FormBody body = build.build();
Request request = new Request.Builder().url(url).post(body).headers(headers).build();
Response execute = client.newCall(request).execute();
if (execute.isSuccessful()) {
return execute.body().string();
}
} catch (Exception e) {
}
return "";
}
示例5: createImmutable
import java.util.HashMap; //导入方法依赖的package包/类
/**
* Creates an immutable <code>AttributeSet</code> as a copy of <code>AttributeSet</code>s
* passed into this method. If the <code>AttributeSet</code>s
* contain attributes with the same name the resulting <code>AttributeSet</code>
* will return value of the first attribute it will find going through
* the sets in the order as they were passed in.
*
* @param sets The <code>AttributeSet</code>s which attributes will become
* a contents of the newly created <code>AttributeSet</code>.
*
* @return The new immutable <code>AttributeSet</code>.
*/
public static AttributeSet createImmutable(AttributeSet... sets) {
if (true) {
return org.netbeans.modules.editor.settings.AttrSet.merge(sets);
}
HashMap<Object, Object> map = new HashMap<Object, Object>();
for(int i = sets.length - 1; i >= 0; i--) {
AttributeSet set = sets[i];
for(Enumeration<?> keys = set.getAttributeNames(); keys.hasMoreElements(); ) {
Object attrKey = keys.nextElement();
Object attrValue = set.getAttribute(attrKey);
map.put(attrKey, attrValue);
}
}
return map.size() > 0 ? new Immutable(map) : SimpleAttributeSet.EMPTY;
}
示例6: setData
import java.util.HashMap; //导入方法依赖的package包/类
public void setData(Platform[] platforms, HashMap<String, String> hiddenPlatforms) {
if(platforms == null)
return;
if (hiddenPlatforms != null && hiddenPlatforms.size() > 0) {
ArrayList<Platform> ps = new ArrayList<Platform>();
for (Platform p : platforms) {
if (hiddenPlatforms.containsKey(p.getName())) {
continue;
}
ps.add(p);
}
logos.addAll(ps);
} else {
logos.addAll(Arrays.asList(platforms));
}
checkedPositionList.clear();
notifyDataSetChanged();
}
示例7: publishClips
import java.util.HashMap; //导入方法依赖的package包/类
private void publishClips(HashMap<Long, Clip> wantClipsPublished, long channelId,
int clipsPublishedAlready) {
int weight = clipsPublishedAlready + wantClipsPublished.size();
for (Clip clip : wantClipsPublished.values()) {
SampleTvProvider.publishProgram(mContext, clip, channelId, weight--);
}
}
开发者ID:googlesamples,项目名称:leanback-homescreen-channels,代码行数:8,代码来源:SynchronizeDatabaseJobService.java
示例8: saveData
import java.util.HashMap; //导入方法依赖的package包/类
private void saveData(@NonNull ReparativeDelegates.Container writeOnlyContainer) {
InstanceRestoration restorationAnnotation = this.getClass().getAnnotation(InstanceRestoration.class);
Field[] fields = null;
if (restorationAnnotation.policy() == InstanceRestoration.Policy.IGNORE_ALL_FIELDS) {
fields = Reflector.getAnnotatedFields(this, Restore.class);
} else {
fields = Reflector.getNonAnnotatedFields(this, Ignore.class);
}
if (fields != null && fields.length > 0) {
for (Field field : fields) {
try {
Object object = Reflector.readValue(this, field);
writeOnlyContainer.set(field.getName(), object);
} catch (Reflector.ReflectorException ignored) {}
}
HashMap<String, Object> saveFailedMap = writeOnlyContainer.getUnboxable();
if (saveFailedMap.size() > 0) {
onSaveFailedMapReady(saveFailedMap);
}
writeOnlyContainer.flush();
}
}
示例9: setPhotoMap
import java.util.HashMap; //导入方法依赖的package包/类
public void setPhotoMap(HashMap<Integer, ToadData> photoMap) {
if (this.photoMap == null) {
updateView();
}
this.photoMap = photoMap;
tableMap = new ArrayList<Integer>();
tableMap.addAll(photoMap.keySet());
Object[][] data = new Object[photoMap.size()][3];
int i = 0;
for (ToadData toadData : photoMap.values()) {
data[i][2] = new File(toadData.getFileName()).getName();
data[i][0] = toadData.getName();
i++;
}
// tableMap.add(pair.getKey());
// Iterator it = photoMap.entrySet().iterator();
// while (it.hasNext()) {
// Map.Entry<Integer, ToadData> pair = (Map.Entry<Integer,
// ToadData>)it.next();
//// pair.getKey()
// System.out.println(pair.getKey() + " = " + pair.getValue());
// }
photoList.setData(data);
this.revalidate();
}
示例10: getTfIdfScores
import java.util.HashMap; //导入方法依赖的package包/类
/**
* Calculates the instance array containing TF-IDF scores for each token
* @param tokenCounts the token count for each token ID
* @return an array of {@link Feature} elements
*/
private Feature[] getTfIdfScores(HashMap<Integer, Integer> tokenCounts) {
int count;
double idf;
double weight;
double normalizedWeight;
double norm = 0;
HashMap<Integer, Double> termWeights = new HashMap<>();
// calculate TF-IDF scores for each token, also add to normalizer
for (int tokenID : tokenCounts.keySet()) {
count = tokenCounts.get(tokenID);
idf = termIdf.get(tokenID);
weight = count * idf;
if (weight > 0.0) {
norm += Math.pow(weight, 2);
termWeights.put(tokenID, weight);
}
}
// calculate normalization
norm = Math.sqrt(norm);
Feature[] instance = new Feature[termWeights.size()];
ArrayList<Integer> list = new ArrayList<>(termWeights.keySet());
Collections.sort(list);
Double w;
int i =0;
// add normalized TF-IDF scores to the training instance
for (int tokenId: list) {
w = termWeights.get(tokenId);
if (w == null) {
w = 0.0;
}
normalizedWeight = w / norm;
instance[i++] = new FeatureNode(tokenId+offset, normalizedWeight);
}
return instance;
}
示例11: validate
import java.util.HashMap; //导入方法依赖的package包/类
@Override
public String validate(String driverClassName, String url, String username, String password,
HttpRequest request, HashMap<String, String> params) {
//sd=20.01.2009&ed=28.01.2009
// проверка на корректность введенных параметров
QLog.l().logger().trace("Принятые параметры \"" + params.toString() + "\".");
if (params.size() == 2) {
Date sd;
Date fd;
Date fd1;
try {
sd = Uses.FORMAT_DD_MM_YYYY.parse(params.get("sd"));
fd = Uses.FORMAT_DD_MM_YYYY.parse(params.get("ed"));
fd1 = DateUtils.addDays(Uses.FORMAT_DD_MM_YYYY.parse(params.get("ed")), 1);
} catch (ParseException ex) {
return "<br>Ошибка ввода параметров! Не все параметры введены корректно(дд.мм.гггг).";
}
if (!sd.after(fd)) {
paramMap.put("sd", sd);
paramMap.put("ed", fd);
paramMap.put("ed1", fd1);
} else {
return "<br>Ошибка ввода параметров! Дата начала больше даты завершения.";
}
} else {
return "<br>Ошибка ввода параметров!";
}
return null;// все нормально
}
示例12: getMapMembers
import java.util.HashMap; //导入方法依赖的package包/类
public Member[] getMapMembers(HashMap<Member, Long> members) {
synchronized (members) {
Member[] result = new Member[members.size()];
members.keySet().toArray(result);
return result;
}
}
示例13: removeJob
import java.util.HashMap; //导入方法依赖的package包/类
/**
* <p>
* Remove (delete) the <code>{@link org.quartz.Job}</code> with the given
* name, and any <code>{@link org.quartz.Trigger}</code> s that reference
* it.
* </p>
*
* @return <code>true</code> if a <code>Job</code> with the given name &
* group was found and removed from the store.
*/
public boolean removeJob(JobKey jobKey) {
boolean found = false;
synchronized (lock) {
List<OperableTrigger> triggersOfJob = getTriggersForJob(jobKey);
for (OperableTrigger trig: triggersOfJob) {
this.removeTrigger(trig.getKey());
found = true;
}
found = (jobsByKey.remove(jobKey) != null) | found;
if (found) {
HashMap<JobKey, JobWrapper> grpMap = jobsByGroup.get(jobKey.getGroup());
if (grpMap != null) {
grpMap.remove(jobKey);
if (grpMap.size() == 0) {
jobsByGroup.remove(jobKey.getGroup());
}
}
}
}
return found;
}
示例14: getCachedWordLists
import java.util.HashMap; //导入方法依赖的package包/类
/**
* Returns the list of cached files for a specific locale, one for each category.
*
* This will return exactly one file for each word list category that matches
* the passed locale. If several files match the locale for any given category,
* this returns the file with the closest match to the locale. For example, if
* the passed word list is en_US, and for a category we have an en and an en_US
* word list available, we'll return only the en_US one.
* Thus, the list will contain as many files as there are categories.
*
* @param locale the locale to find the dictionary files for, as a string.
* @param context the context on which to open the files upon.
* @return an array of binary dictionary files, which may be empty but may not be null.
*/
public static File[] getCachedWordLists(final String locale, final Context context) {
final File[] directoryList = DictionaryInfoUtils.getCachedDirectoryList(context);
if (null == directoryList) return EMPTY_FILE_ARRAY;
final HashMap<String, FileAndMatchLevel> cacheFiles = new HashMap<>();
for (File directory : directoryList) {
if (!directory.isDirectory()) continue;
final String dirLocale =
DictionaryInfoUtils.getWordListIdFromFileName(directory.getName());
final int matchLevel = LocaleUtils.getMatchLevel(dirLocale, locale);
if (LocaleUtils.isMatch(matchLevel)) {
final File[] wordLists = directory.listFiles();
if (null != wordLists) {
for (File wordList : wordLists) {
final String category =
DictionaryInfoUtils.getCategoryFromFileName(wordList.getName());
final FileAndMatchLevel currentBestMatch = cacheFiles.get(category);
if (null == currentBestMatch || currentBestMatch.mMatchLevel < matchLevel) {
cacheFiles.put(category, new FileAndMatchLevel(wordList, matchLevel));
}
}
}
}
}
if (cacheFiles.isEmpty()) return EMPTY_FILE_ARRAY;
final File[] result = new File[cacheFiles.size()];
int index = 0;
for (final FileAndMatchLevel entry : cacheFiles.values()) {
result[index++] = entry.mFile;
}
return result;
}
示例15: getParetoFrontIndices
import java.util.HashMap; //导入方法依赖的package包/类
/**
*
* @param solutions
* @return
*/
public static int[] getParetoFrontIndices(double[][] solutions) {
double[] dim1 = new double[solutions.length];
for (int i=0; i<=dim1.length-1; i++) {
dim1[i] = solutions[i][0];
}
int[] sortedIdxDim1 = sortedIndices(dim1);
double[][] sortedSolutions = new double[solutions.length][2];
for (int i=0; i<=sortedIdxDim1.length-1; i++) {
sortedSolutions[i][0] = solutions[sortedIdxDim1[i]][0];
sortedSolutions[i][1] = solutions[sortedIdxDim1[i]][1];
}
HashMap<Integer,Integer> pFront = new HashMap<Integer,Integer>();
Integer pPointCount = 0;
Integer pPointIndex = sortedIdxDim1[0];
pFront.put(pPointCount, pPointIndex);
for (int i=1; i<=sortedIdxDim1.length-1; i++) {
double dim2Val = solutions[sortedIdxDim1[i]][1];
if (dim2Val<solutions[(int)pPointIndex][1]) {
pPointCount = pPointCount+1;
pPointIndex = (Integer)sortedIdxDim1[i];
pFront.put(pPointCount, pPointIndex);
}
}
int[] pPointIndices = new int[pFront.size()];
for (int i=0; i<=pPointIndices.length-1; i++) {
pPointIndices[i] = (int)pFront.get((Integer)i);
}
// double[][] paretoFront = new double[pFront.size()][2];
// for (int i=0; i<=paretoFront.length-1; i++) {
// int pIndex = (int)pFront.get((Integer)i);
// paretoFront[i][0] = solutions[pIndex][0];
// paretoFront[i][1] = solutions[pIndex][1];
// }
return pPointIndices;
}