本文整理汇总了Java中java.util.HashMap.clear方法的典型用法代码示例。如果您正苦于以下问题:Java HashMap.clear方法的具体用法?Java HashMap.clear怎么用?Java HashMap.clear使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.HashMap
的用法示例。
在下文中一共展示了HashMap.clear方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import java.util.HashMap; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
HashMap<Integer, Object> hm = makeMap();
hm = (HashMap<Integer, Object>)hm.clone();
hm.clear();
// There should no longer be a strong reference to testObject
// the WeakReference should be nulled out by GC. If not,
// we will hang here until timed out by the test harness.
Object[] chain = null;
while (wr.get() != null) {
try {
Object[] allocate = new Object[1000000];
allocate[0] = chain;
chain = allocate;
} catch (OutOfMemoryError oome) {
chain = null;
}
System.gc();
Thread.sleep(100);
}
}
示例2: 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");
/*
To remove all values or clear HashMap use
void clear method() of HashMap class. Clear method removes all
key value pairs contained in HashMap.
*/
hMap.clear();
System.out.println("Total key value pairs in HashMap are : " + hMap.size());
}
示例3: testSelectColumnRead
import java.util.HashMap; //导入方法依赖的package包/类
/**
* Tests the attribute in a scan node to limit the columns read by a scan.
*
* The functionality of selecting all columns is tested in all of the other tests that leave out the attribute.
* @throws Exception
*/
@Test
public void testSelectColumnRead() throws Exception {
HashMap<String, FieldInfo> fields = new HashMap<>();
ParquetTestProperties props = new ParquetTestProperties(4, 3000, DEFAULT_BYTES_PER_PAGE, fields);
// generate metatdata for a series of test columns, these columns are all generated in the test file
populateFieldInfoMap(props);
TestFileGenerator.generateParquetFile("/tmp/test.parquet", props);
fields.clear();
// create a new object to describe the dataset expected out of the scan operation
// the fields added below match those requested in the plan specified in parquet_selective_column_read.json
// that is used below in the test query
props = new ParquetTestProperties(4, 3000, DEFAULT_BYTES_PER_PAGE, fields);
props.fields.put("integer", new FieldInfo("int32", "integer", 32, TestFileGenerator.intVals, TypeProtos.MinorType.INT, props));
props.fields.put("bigInt", new FieldInfo("int64", "bigInt", 64, TestFileGenerator.longVals, TypeProtos.MinorType.BIGINT, props));
props.fields.put("bin", new FieldInfo("binary", "bin", -1, TestFileGenerator.binVals, TypeProtos.MinorType.VARBINARY, props));
props.fields.put("bin2", new FieldInfo("binary", "bin2", -1, TestFileGenerator.bin2Vals, TypeProtos.MinorType.VARBINARY, props));
testParquetFullEngineEventBased(true, false, "/parquet/parquet_selective_column_read.json", null, "/tmp/test.parquet", 1, props, QueryType.PHYSICAL);
}
示例4: apply
import java.util.HashMap; //导入方法依赖的package包/类
/**
* init the cache on your own.
*
* @param recyclerView
* @param items
*/
public void apply(RecyclerView recyclerView, Iterable<Item> items) {
if (items != null) {
//we pre-create the views for our cache
HashMap<Integer, Stack<RecyclerView.ViewHolder>> cache = new HashMap<>();
for (Item d : items) {
if (!cache.containsKey(d.getType())) {
cache.put(d.getType(), new Stack<RecyclerView.ViewHolder>());
}
if (mCacheSize == -1 || cache.get(d.getType()).size() <= mCacheSize) {
cache.get(d.getType()).push(d.getViewHolder(recyclerView));
}
RecyclerView.RecycledViewPool recyclerViewPool = new RecyclerView.RecycledViewPool();
//we fill the pool
for (Map.Entry<Integer, Stack<RecyclerView.ViewHolder>> entry : cache.entrySet()) {
recyclerViewPool.setMaxRecycledViews(entry.getKey(), mCacheSize);
for (RecyclerView.ViewHolder holder : entry.getValue()) {
recyclerViewPool.putRecycledView(holder);
}
//make sure to clear the stack
entry.getValue().clear();
}
//make sure to clear the cache
cache.clear();
recyclerView.setRecycledViewPool(recyclerViewPool);
}
}
}
示例5: testMSSQL2005
import java.util.HashMap; //导入方法依赖的package包/类
public void testMSSQL2005() throws Exception {
/*
add(getMessage("DRIVERNAME_MSSQL2005"),
"com.microsoft.sqlserver.jdbc.SQLServerDriver",
"jdbc:sqlserver://[<HOST>[\\<INSTANCE>][:<PORT>]][;databaseName=<DB>][;<ADDITIONAL>]", true);
*/
ArrayList<String> supportedProps = new ArrayList<String>();
supportedProps.addAll(STD_SUPPORTED_PROPS);
supportedProps.add(JdbcUrl.TOKEN_INSTANCE);
ArrayList<String> requiredProps = new ArrayList<String>();
JdbcUrl url = checkUrl(getDriverName("DRIVERNAME_MSSQL2005"), null,
"com.microsoft.sqlserver.jdbc.SQLServerDriver",
"jdbc:sqlserver://[<HOST>[\\<INSTANCE>][:<PORT>]][;databaseName=<DB>][;<ADDITIONAL>]",
supportedProps, requiredProps);
HashMap<String, String> propValues = buildPropValues(supportedProps);
testUrlString(url, propValues, "jdbc:sqlserver://" + HOST + "\\" + INSTANCE + ":" + PORT + ";databaseName=" + DB + ";" + ADDITIONAL);
propValues.remove(JdbcUrl.TOKEN_ADDITIONAL);
testUrlString(url, propValues, "jdbc:sqlserver://" + HOST + "\\" + INSTANCE + ":" + PORT + ";databaseName=" + DB);
propValues.remove(JdbcUrl.TOKEN_PORT);
testUrlString(url, propValues, "jdbc:sqlserver://" + HOST + "\\" + INSTANCE + ";databaseName=" + DB);
propValues.remove(JdbcUrl.TOKEN_INSTANCE);
testUrlString(url, propValues, "jdbc:sqlserver://" + HOST + ";databaseName=" + DB);
propValues.remove(JdbcUrl.TOKEN_DB);
testUrlString(url, propValues, "jdbc:sqlserver://" + HOST);
propValues.remove(JdbcUrl.TOKEN_HOST);
propValues.put(JdbcUrl.TOKEN_DB, DB);
testUrlString(url, propValues, "jdbc:sqlserver://;databaseName=" + DB);
propValues.clear();
testUrlString(url, propValues, "jdbc:sqlserver://");
}
示例6: updateFile
import java.util.HashMap; //导入方法依赖的package包/类
private void updateFile(HashMap<File, ArrayList<String>> file_data_temp, boolean reload) {
file_data_temp.clear();
if(file != null) {
if(!file.exists()) {
file_data_temp.put(file, null);
} else {
if(file.isFile()) {
ArrayList<String> data = new ArrayList<>();/*
if(file.exists()) {
try (Scanner scanner = new Scanner(file)) {
while(scanner.hasNextLine()) {
String line = scanner.nextLine();
data.add(line);
}
scanner.close();
} catch (Exception ex) {
StaticStandard.logErr("Error while scanning file: " + ex);
}
}*/
file_data_temp.put(file, data);
} else if(file.isDirectory()) {
addFolder(file, file_data_temp);
}
}
}
if(reload) {
reloadFile();
}
}
示例7: getView
import java.util.HashMap; //导入方法依赖的package包/类
@Override
public View getView(int position, View convertView, ViewGroup parent) {
SimpleMonthView v;
HashMap<String, Integer> drawingParams = null;
if (convertView != null) {
v = (SimpleMonthView) convertView;
drawingParams = (HashMap<String, Integer>) v.getTag();
} else {
v = new SimpleMonthView(mContext);
v.setLayoutParams(new AbsListView.LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
v.setClickable(true);
v.setOnDayClickListener(this);
}
if (drawingParams == null) {
drawingParams = new HashMap<String, Integer>();
}
drawingParams.clear();
final int month = position % MONTHS_IN_YEAR;
final int year = position / MONTHS_IN_YEAR + mController.getMinYear();
int selectedDay = -1;
if (isSelectedDayInMonth(year, month)) {
selectedDay = mSelectedDay.day;
}
v.reuse();
drawingParams
.put(SimpleMonthView.VIEW_PARAMS_SELECTED_DAY, selectedDay);
drawingParams.put(SimpleMonthView.VIEW_PARAMS_YEAR, year);
drawingParams.put(SimpleMonthView.VIEW_PARAMS_MONTH, month);
drawingParams.put(SimpleMonthView.VIEW_PARAMS_WEEK_START,
mController.getFirstDayOfWeek());
v.setMonthParams(drawingParams);
v.invalidate();
return v;
}
示例8: invalidateCurrentSession
import java.util.HashMap; //导入方法依赖的package包/类
public void invalidateCurrentSession(HttpServletRequest request) {
/*
FIXME
if (!octopusConfig.getIsSessionInvalidatedAtLogin()) {
// Defined with config that developer don't was logout/session invalidation.
return;
}
*/
/*
if (SecurityUtils.getSubject() instanceof TwoStepSubject) {
// Otherwise the principals are cleared from the current subject which isn't something we want :)
return;
}
*/
HttpSession session = request.getSession();
HashMap<String, Object> content = new HashMap<>();
Enumeration keys = session.getAttributeNames();
while (keys.hasMoreElements()) {
String key = (String) keys.nextElement();
content.put(key, session.getAttribute(key));
session.removeAttribute(key);
}
SecurityUtils.getSubject().logout();
session = request.getSession(true);
for (Map.Entry m : content.entrySet()) {
session.setAttribute((String) m.getKey(), m.getValue());
}
content.clear();
}
示例9: put
import java.util.HashMap; //导入方法依赖的package包/类
private void put(K key, V value){
if (queue.get(queue.size() - 1).size() >= bufferSize) {
if (queue.size() < queueLen) {
queue.add(new HashMap<>());
} else {
HashMap<K, V> remove = queue.remove(0);
remove.clear();
queue.add(remove);
}
}
queue.get(queue.size() - 1).put(key, value);
}
示例10: Node
import java.util.HashMap; //导入方法依赖的package包/类
public Node(ArrayList<double[]> data)
{
this.dataList = data;
leftNode = null;
rightNode = null;
isLeaf = true;
//Calculate Gini-impurity
HashMap<Double, Integer>classType = new HashMap();
for(double[] dataValue : dataList)
{
if(!classType.containsKey(dataValue[dataValue.length - 1]))
classType.put(dataValue[dataValue.length - 1], 1);
else
{
int count = classType.get(dataValue[dataValue.length - 1]) + 1;
classType.put(dataValue[dataValue.length - 1], count);
}
}
impurity = 1;
double count, dataSize = dataList.size();
double maxCount = -1;
for(double classIndex : classType.keySet())
{
count = classType.get(classIndex);
impurity = impurity - Math.pow(count/dataSize, 2);
if(count > maxCount)
{
majorityType = classIndex;
maxCount = count;
}
}
classType.clear();
}
示例11: updateContext
import java.util.HashMap; //导入方法依赖的package包/类
public HashMap<String, Object> updateContext(HashMap<String, Object> newContext) {
if (odooSession != null && odooSession.userContext() != null)
newContext.putAll(odooSession.userContext());
if (user != null) {
newContext.clear();
newContext.put("uid", user.getUserId());
newContext.put("tz", user.getTimezone());
}
return newContext;
}
示例12: fetchEntries
import java.util.HashMap; //导入方法依赖的package包/类
/**
* Fetches entries from local and remote nodes and appends these to register-interest response.
*/
public void fetchEntries(HashMap<Integer, HashSet> bucketKeys, VersionedObjectList values,
ServerConnection servConn) throws IOException {
int retryAttempts = calcRetry();
RetryTimeKeeper retryTime = null;
HashMap<Integer, HashSet> failures = new HashMap<Integer, HashSet>(bucketKeys);
HashMap<InternalDistributedMember, HashMap<Integer, HashSet>> nodeToBuckets =
new HashMap<InternalDistributedMember, HashMap<Integer, HashSet>>();
while (--retryAttempts >= 0 && !failures.isEmpty()) {
nodeToBuckets.clear();
updateNodeToBucketMap(nodeToBuckets, failures);
failures.clear();
HashMap<Integer, HashSet> localBuckets = nodeToBuckets.remove(getMyId());
if (localBuckets != null && !localBuckets.isEmpty()) {
Set keys = new HashSet();
for (Integer id : localBuckets.keySet()) {
keys.addAll(localBuckets.get(id));
}
if (!keys.isEmpty()) {
BaseCommand.appendNewRegisterInterestResponseChunkFromLocal(this, values, "keyList", keys,
servConn);
}
}
// Handle old nodes for Rolling Upgrade support
Set<Integer> failedSet = handleOldNodes(nodeToBuckets, values, servConn);
// Add failed buckets to nodeToBuckets map so that these will be tried on
// remote nodes.
if (!failedSet.isEmpty()) {
for (Integer bId : failedSet) {
failures.put(bId, bucketKeys.get(bId));
}
updateNodeToBucketMap(nodeToBuckets, failures);
failures.clear();
}
fetchRemoteEntries(nodeToBuckets, failures, values, servConn);
if (!failures.isEmpty()) {
if (retryTime == null) {
retryTime = new RetryTimeKeeper(this.retryTimeout);
}
if (!waitForFetchRemoteEntriesRetry(retryTime)) {
break;
}
}
}
if (!failures.isEmpty()) {
throw new InternalGemFireException("Failed to fetch entries from " + failures.size()
+ " buckets of region " + getName() + " for register interest.");
}
}
示例13: getEcrfFieldValues
import java.util.HashMap; //导入方法依赖的package包/类
private ECRFFieldValuesOutVO getEcrfFieldValues(ECRF ecrf, String section, ProbandListEntryOutVO listEntryVO, boolean addSeries, boolean jsValues, boolean loadAllJsValues,
PSFVO psf) throws Exception {
ECRFFieldValuesOutVO result = new ECRFFieldValuesOutVO();
if (listEntryVO != null && ecrf != null) {
ECRFFieldDao ecrfFieldDao = this.getECRFFieldDao();
ECRFFieldValueDao ecrfFieldValueDao = this.getECRFFieldValueDao();
Collection<Map> ecrfFieldValues = ecrfFieldValueDao.findByListEntryEcrfSectionJs(listEntryVO.getId(), ecrf.getId(), section, true, null, psf);
HashMap<String, Long> maxSeriesIndexMap = null;
HashMap<String, Long> fieldMaxPositionMap = null;
HashMap<String, Long> fieldMinPositionMap = null;
HashMap<String, Set<ECRFField>> seriesEcrfFieldMap = null;
// HashMap<String, Set<ECRFField>> seriesEcrfFieldJsMap = null;
if (addSeries) {
maxSeriesIndexMap = new HashMap<String, Long>();
fieldMaxPositionMap = new HashMap<String, Long>();
fieldMinPositionMap = new HashMap<String, Long>();
seriesEcrfFieldMap = new HashMap<String, Set<ECRFField>>();
// seriesEcrfFieldJsMap = new HashMap<String, Set<ECRFField>>();
ServiceUtil.initSeriesEcrfFieldMaps(
ecrfFieldDao.findByTrialEcrfSectionSeriesJs(null, ecrf.getId(), section, true, true, null, null),
listEntryVO.getId(),
ecrf.getId(),
maxSeriesIndexMap,
fieldMaxPositionMap,
fieldMinPositionMap,
seriesEcrfFieldMap,
// seriesEcrfFieldJsMap,
ecrfFieldValueDao
);
}
result.setPageValues(ServiceUtil.getEcrfFieldValues(listEntryVO, ecrfFieldValues, maxSeriesIndexMap, fieldMaxPositionMap, fieldMinPositionMap, seriesEcrfFieldMap,
null,
ecrfFieldDao,
ecrfFieldValueDao,
this.getECRFFieldStatusEntryDao(),
this.getECRFFieldStatusTypeDao())); // this.getInputFieldSelectionSetValueDao()
if (jsValues) {
if (addSeries) {
maxSeriesIndexMap.clear();
fieldMaxPositionMap.clear();
fieldMinPositionMap.clear();
seriesEcrfFieldMap.clear();
// seriesEcrfFieldJsMap.clear();
ServiceUtil.initSeriesEcrfFieldMaps(
(loadAllJsValues ? ecrfFieldDao.findByTrialEcrfSeriesJs(null, ecrf.getId(), true, true, true, null) :
ecrfFieldDao.findByTrialEcrfSectionSeriesJs(null, ecrf.getId(), section, true, true, true, null)),
listEntryVO.getId(),
ecrf.getId(),
maxSeriesIndexMap,
fieldMaxPositionMap,
fieldMinPositionMap,
seriesEcrfFieldMap,
// seriesEcrfFieldJsMap,
ecrfFieldValueDao
);
}
if (loadAllJsValues) {
result.setJsValues(ServiceUtil.getEcrfFieldJsonValues(
// ecrfFieldValueDao.findByListEntryEcrfSectionJs(listEntryVO.getId(), ecrf.getId(), section, true, true, null),
ecrfFieldValueDao.findByListEntryEcrfJs(listEntryVO.getId(), ecrf.getId(), true, true, null),
maxSeriesIndexMap, fieldMaxPositionMap,
fieldMinPositionMap, seriesEcrfFieldMap,
false, ecrfFieldValueDao,
this.getInputFieldSelectionSetValueDao()));
} else {
result.setJsValues(ServiceUtil.getEcrfFieldJsonValues(ecrfFieldValues,
maxSeriesIndexMap, fieldMaxPositionMap,
fieldMinPositionMap, seriesEcrfFieldMap,
true, ecrfFieldValueDao,
this.getInputFieldSelectionSetValueDao()));
}
}
}
return result;
}
示例14: parseMultipartUpload
import java.util.HashMap; //导入方法依赖的package包/类
public void parseMultipartUpload()
throws IOException {
// setup the initial buffered input stream, boundary string that separates
// various parts in the stream.
startMultipartParse();
HashMap partHeaders = parsePartHeaders();
while (partHeaders != null) {
String fieldName = (String)partHeaders.get("fieldName");
String fileName = (String)partHeaders.get("fileName");
if (fileName != null) {
// This is a file upload part
if (fileName.equals("")) {
fileName = null; // empty filename, probably an "empty" file param
}
if (fileName != null) {
// a filename was actually specified
String content = (String)partHeaders.get("content-type");
fileName = saveUploadFile(fileName, content);
uploadFiles.put(fieldName,
new OneUpload(
uploadDir.toString(),
fileName,
content
)
);
}
else {
uploadFiles.put(fieldName, new OneUpload(null, null, null));
}
}
else {
// this is a parameters list part
byte[] valueBytes = parseFormFieldBytes();
String value = new String(valueBytes, fieldEncoding);
Vector<String> existingValues = formFields.get(fieldName);
if (existingValues == null) {
existingValues = new Vector<String>();
formFields.put(fieldName, existingValues);
}
existingValues.addElement(value);
}
partHeaders.clear();
partHeaders = parsePartHeaders();
}
}
示例15: getView
import java.util.HashMap; //导入方法依赖的package包/类
@SuppressLint("NewApi")
@SuppressWarnings("unchecked")
@Override
public View getView(int position, View convertView, ViewGroup parent) {
MonthView v;
HashMap<String, Integer> drawingParams = null;
if (convertView != null) {
v = (MonthView) convertView;
// We store the drawing parameters in the view so it can be recycled
drawingParams = (HashMap<String, Integer>) v.getTag();
} else {
v = createMonthView(mContext);
// Set up the new view
LayoutParams params = new LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
v.setLayoutParams(params);
v.setClickable(true);
v.setOnDayClickListener(this);
}
if (drawingParams == null) {
drawingParams = new HashMap<>();
}
drawingParams.clear();
final int month = (position + mController.getStartDate().get(Calendar.MONTH)) % MONTHS_IN_YEAR;
final int year = (position + mController.getStartDate().get(Calendar.MONTH)) / MONTHS_IN_YEAR + mController.getMinYear();
int selectedDay = -1;
if (isSelectedDayInMonth(year, month)) {
selectedDay = mSelectedDay.day;
}
// Invokes requestLayout() to ensure that the recycled view is set with the appropriate
// height/number of weeks before being displayed.
v.reuse();
drawingParams.put(MonthView.VIEW_PARAMS_SELECTED_DAY, selectedDay);
drawingParams.put(MonthView.VIEW_PARAMS_YEAR, year);
drawingParams.put(MonthView.VIEW_PARAMS_MONTH, month);
drawingParams.put(MonthView.VIEW_PARAMS_WEEK_START, mController.getFirstDayOfWeek());
v.setMonthParams(drawingParams);
v.invalidate();
return v;
}