本文整理汇总了Java中java.util.LinkedHashMap.clear方法的典型用法代码示例。如果您正苦于以下问题:Java LinkedHashMap.clear方法的具体用法?Java LinkedHashMap.clear怎么用?Java LinkedHashMap.clear使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.LinkedHashMap
的用法示例。
在下文中一共展示了LinkedHashMap.clear方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import java.util.LinkedHashMap; //导入方法依赖的package包/类
public static void main(String[] args) {
//create LinkedHashMap object
LinkedHashMap lHashMap = new LinkedHashMap();
//add key value pairs to LinkedHashMap
lHashMap.put("1", "One");
lHashMap.put("2", "Two");
lHashMap.put("3", "Three");
/*
To remove all values or clear LinkedHashMap use
void clear method() of LinkedHashMap class. Clear method removes all
key value pairs contained in LinkedHashMap.
*/
lHashMap.clear();
System.out.println("Total key value pairs in LinkedHashMap are : " + lHashMap.size());
}
示例2: getHaplotypeMapFromAlleles
import java.util.LinkedHashMap; //导入方法依赖的package包/类
public static void getHaplotypeMapFromAlleles(final List<Allele> alleleList,
final ReferenceContext ref,
final GenomeLoc loc,
final LinkedHashMap<Allele, Haplotype> haplotypeMap) {
// protect against having an indel too close to the edge of a contig
if (loc.getStart() <= HAPLOTYPE_SIZE)
haplotypeMap.clear();
// check if there is enough reference window to create haplotypes (can be an issue at end of contigs)
else if (ref.getWindow().getStop() < loc.getStop() + HAPLOTYPE_SIZE)
haplotypeMap.clear();
else if (alleleList.isEmpty())
haplotypeMap.clear();
else {
final int eventLength = getEventLength(alleleList);
final int hsize = ref.getWindow().size() - Math.abs(eventLength) - 1;
final int numPrefBases = ref.getLocus().getStart() - ref.getWindow().getStart() + 1;
if (hsize <= 0) // protect against event lengths larger than ref window sizes
haplotypeMap.clear();
else
haplotypeMap.putAll(Haplotype.makeHaplotypeListFromAlleles(alleleList, loc.getStart(),
ref, hsize, numPrefBases));
}
}
示例3: sortScopes
import java.util.LinkedHashMap; //导入方法依赖的package包/类
/**
* Sorts the scopes map using {@link ContextScope#getOrder()}
* @param scopes Scopes map to sort
*/
private static void sortScopes(LinkedHashMap<String, ContextScope> scopes) {
List<Map.Entry<String, ContextScope>> entries = new ArrayList<>(scopes.entrySet());
scopes.clear();
entries.stream()
.sorted(Comparator.comparing(Map.Entry::getValue, Comparator.comparingInt((v) -> v.getOrder())))
.forEachOrdered(e -> scopes.put(e.getKey(), e.getValue()));
}
示例4: visitTryStatement
import java.util.LinkedHashMap; //导入方法依赖的package包/类
@Override
public String visitTryStatement(JavaParser.TryStatementContext ctx) {
// 'try' block (catchClause+ finallyBlock? | finallyBlock)
LinkedHashMap<String, JavaClass> tempLocalVariables = new LinkedHashMap<>();
tempLocalVariables.putAll(localVariables);
visit(ctx.block());
localVariables.clear();
localVariables.putAll(tempLocalVariables);
if (ctx.finallyBlock() != null) {
// 'finally' block
tempLocalVariables.clear();
tempLocalVariables.putAll(localVariables);
visit(ctx.finallyBlock().block());
localVariables.clear();
localVariables.putAll(tempLocalVariables);
}
// Now visit any available catch clauses
if (ctx.catchClause() != null && ctx.catchClause().size() > 0) {
// 'catch' '(' variableModifier* catchType Identifier ')' block
for (JavaParser.CatchClauseContext cx : ctx.catchClause()) {
tempLocalVariables.clear();
tempLocalVariables.putAll(localVariables);
String name = cx.Identifier().getText();
//Assume that the catch type is a simple class name, for now
String type = cx.catchType().getText();
localVariables.put(name, findClassbyName(type));
visit(cx.block());
localVariables.clear();
localVariables.putAll(tempLocalVariables);
}
}
return null;
}
示例5: readGroupedEntryMap
import java.util.LinkedHashMap; //导入方法依赖的package包/类
protected static <T extends GroupedBiomeEntry> void readGroupedEntryMap(JsonObject readFrom, LinkedHashMap<String, T> list, String tagname, Class<T> clazz) {
list.clear();
if (readFrom.has(tagname)) {
JsonObject b = JsonUtil.getAsObject(readFrom, tagname);
readGroupedEntryMap(b, list, clazz);
}
}
示例6: readJsonableMap
import java.util.LinkedHashMap; //导入方法依赖的package包/类
static <T extends IJsonMappable> void readJsonableMap(JsonObject o, LinkedHashMap<String, T> list, String tagname, Class<T> clazz) {
list.clear();
if (o.has(tagname)) {
JsonArray g = JsonUtil.getAsArray(o, tagname); //o.getAsJsonArray(tagname);
for (JsonElement element : g) {
T def = IJsonable.create(clazz);
JsonObject eo;
/*try {
eo = element.getAsJsonObject();
} catch (Exception e) {
return;
}*/
eo = JsonUtil.asObject(element);
def.fromJson(eo);
list.put(def.getMapKey(), def);
}
}
}
示例7: execBulkRequestForNavigationProperty
import java.util.LinkedHashMap; //导入方法依赖的package包/类
/**
* NP経由ユーザデータをバルク登録する.
* @param npBulkContexts NavigationPropertyコンテキストのリスト
*/
private void execBulkRequestForNavigationProperty(List<NavigationPropertyBulkContext> npBulkContexts) {
// バルク登録用にコンテキストからBulkRequestを作成
// NP側のEntityTypeの存在チェック、バルクデータ内でのID競合チェックもここで行う
LinkedHashMap<String, BulkRequest> npBulkRequests = new LinkedHashMap<String, BulkRequest>();
for (NavigationPropertyBulkContext npBulkContext : npBulkContexts) {
BatchBodyPart bodyPart = npBulkContext.getBodyPart();
BulkRequest bulkRequest = new BulkRequest(bodyPart);
String key = PersoniumUUID.randomUUID();
if (npBulkContext.isError()) {
bulkRequest.setError(npBulkContext.getException());
npBulkRequests.put(key, bulkRequest);
continue;
}
String targetEntitySetName = bodyPart.getTargetEntitySetName();
bulkRequest = createBulkRequest(bodyPart, targetEntitySetName);
// データ内でのID競合チェック
// TODO 複合主キー対応、ユニークキーのチェック、NTKP対応
if (bulkRequest.getError() == null) {
EntitySetDocHandler docHandler = bulkRequest.getDocHandler();
key = docHandler.getEntityTypeId() + ":" + (String) docHandler.getStaticFields().get("__id");
if (npBulkRequests.containsKey(key)) {
key = PersoniumUUID.randomUUID();
bulkRequest.setError(PersoniumCoreException.OData.ENTITY_ALREADY_EXISTS);
}
}
npBulkRequests.put(key, bulkRequest);
}
try {
this.odataResource.getODataProducer().bulkCreateEntityViaNavigationProperty(npBulkContexts, npBulkRequests);
} catch (PersoniumCoreException e) {
// 503が発生した後の処理を継続させるため、shutterにステータスを設定。
shutter.updateStatus(e);
if (!PersoniumCoreException.Misc.TOO_MANY_CONCURRENT_REQUESTS.equals(e)) {
throw e;
} else {
createTooManyConcurrentResponse(npBulkContexts);
}
}
npBulkRequests.clear();
}