本文整理汇总了Java中java.util.HashMap.get方法的典型用法代码示例。如果您正苦于以下问题:Java HashMap.get方法的具体用法?Java HashMap.get怎么用?Java HashMap.get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.HashMap
的用法示例。
在下文中一共展示了HashMap.get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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();
}
示例2: addItemToCell
import java.util.HashMap; //导入方法依赖的package包/类
private void addItemToCell(Item<E> item, float cx, float cy) {
if (!rows.containsKey(cy)) {
rows.put(cy, new HashMap<Float, Cell>());
}
HashMap<Float, Cell> row = rows.get(cy);
if (!row.containsKey(cx)) {
row.put(cx, new Cell());
}
Cell cell = row.get(cx);
nonEmptyCells.put(cell, true);
if (!cell.items.containsKey(item)) {
cell.items.put(item, true);
cell.itemCount = cell.itemCount + 1;
}
}
示例3: getAlternatives
import java.util.HashMap; //导入方法依赖的package包/类
public List<Station> getAlternatives(IAlternativeQualifier qualifier, int maxAmount) {
final HashMap<Station, Double> stationCost = new HashMap<>();
for (Stop source : getStops()) {
BellmanFordShortestPath<Stop, Connection> bf = new BellmanFordShortestPath<Stop, Connection>(getNetwork(), source);
for (Stop sink : getNetwork().vertexSet()) {
if (sink != source && qualifier.acceptable(sink.getStation()) &&
bf.getCost(sink) < (stationCost.get(sink.getStation()) == null ? Double.MAX_VALUE : stationCost.get(sink.getStation()))) {
stationCost.put(sink.getStation(), bf.getCost(sink));
}
}
}
List<Station> alternatives = new ArrayList<>(stationCost.keySet());
Collections.sort(alternatives, new Comparator<Station>() {
@Override
public int compare(Station station, Station t1) {
return stationCost.get(station).compareTo(stationCost.get(t1));
}
});
return alternatives.subList(0, maxAmount > alternatives.size() ? alternatives.size() : maxAmount);
}
示例4: validateMoney
import java.util.HashMap; //导入方法依赖的package包/类
/**
* Automatically converts the cash that a player character is holding
*/
public void validateMoney() {
HashMap<Money, Integer> cash = getMoney();
// Check for negative balances
while (cash.get(Money.SILVER) < 0 && cash.get(Money.GOLD) - 1 >= 0) {
System.out.println(cash);
cash.put(Money.GOLD, cash.get(Money.GOLD) - 1);
cash.put(Money.SILVER, cash.get(Money.SILVER) + 100);
}
while (cash.get(Money.COPPER) < 0 && cash.get(Money.SILVER) - 1 >= 0){
System.out.println(cash);
cash.put(Money.SILVER, cash.get(Money.SILVER) - 1);
cash.put(Money.COPPER, cash.get(Money.COPPER) + 100);
}
// Check for overflow
int tradedUpSilver = cash.get(Money.COPPER) / 100;
cash.put(Money.COPPER, cash.get(Money.COPPER) % 100);
cash.put(Money.SILVER, (cash.get(Money.SILVER) % 100) + tradedUpSilver);
int tradedUpGold = cash.get(Money.SILVER) / 100;
cash.put(Money.GOLD, cash.get(Money.GOLD) + tradedUpGold);
}
示例5: getEntityFeaturesJson
import java.util.HashMap; //导入方法依赖的package包/类
private JSONArray getEntityFeaturesJson(
HashMap<String, List<Triple<Integer, HashMap<String, Double>, Boolean>>> source,
String query, WikipediaInterface wikiApi) throws JSONException,
IOException {
JSONArray res = new JSONArray();
if (source.containsKey(query))
for (Triple<Integer, HashMap<String, Double>, Boolean> p : source
.get(query)) {
JSONObject pairJs = new JSONObject();
res.put(pairJs);
pairJs.put("wid", p.getLeft());
pairJs.put("title", wikiApi.getTitlebyId(p.getLeft()));
pairJs.put("url", widToUrl(p.getLeft(), wikiApi));
JSONObject features = new JSONObject();
pairJs.put("features", features);
for (String ftrName : SmaphUtils.sorted(p.getMiddle().keySet()))
features.put(ftrName, p.getMiddle().get(ftrName));
pairJs.put("accepted", p.getRight());
}
return res;
}
示例6: numWays
import java.util.HashMap; //导入方法依赖的package包/类
public static long numWays(int n, int [] coins, int coinNumber, HashMap<String, Long> cache) {
/* Check our cache */
String key = n + "," + coinNumber;
if (cache.containsKey(key)) {
return cache.get(key);
}
/* Base case */
if (coinNumber == coins.length - 1) {
if (n % coins[coinNumber] == 0) {
cache.put(key, 1L);
return 1;
} else {
cache.put(key, 0L);
return 0;
}
}
/* Recursive case */
long ways = 0;
for (int i = 0; i <= n; i += coins[coinNumber]) {
ways += numWays(n - i, coins, coinNumber + 1, cache);
}
/* Cache and return solution */
cache.put(key, ways);
return ways;
}
示例7: refreshNature
import java.util.HashMap; //导入方法依赖的package包/类
private void refreshNature() {
gain = 1;
maxPower = 0;
HashMap<Block, Integer> map = new HashMap<Block, Integer>();
for (int i = -RADIUS; i <= RADIUS; i++) {
for (int j = -RADIUS; j <= RADIUS; j++) {
for (int k = -RADIUS; k <= RADIUS; k++) {
BlockPos checking = getPos().add(i, j, k);
int score = getPowerValue(checking);
if (score > 0) {
Block block = getWorld().getBlockState(checking).getBlock();
int currentScore = 0;
if (map.containsKey(block)) currentScore = map.get(block);
if (currentScore < MAX_SCORE_PER_CATEGORY) map.put(block, currentScore + score);
}
}
}
}
map.values().forEach(i -> maxPower += i);
maxPower += (map.keySet().size() * 80); //Variety is the most important thing
double multiplier = 1;
boolean[] typesGain = new boolean[3]; //Types of modifiers. 0=skull, 1=torch/plate, 2=vase
boolean[] typesMult = new boolean[3]; //Types of modifiers. 0=skull, 1=goblet, 2=plate
for (int dx = -1; dx <= 1; dx++)
for (int dz = -1; dz <= 1; dz++) {
BlockPos ps = getPos().add(dx, 0, dz);
if (getWorld().getBlockState(ps).getBlock().equals(ModBlocks.witch_altar) && !getWorld().getBlockState(ps).getValue(BlockWitchAltar.ALTAR_TYPE).equals(AltarMultiblockType.UNFORMED)) {
multiplier += getMultiplier(ps.up(), typesMult);
gain += getGain(ps.up(), typesGain);
}
}
maxPower *= multiplier;
}
示例8: eval
import java.util.HashMap; //导入方法依赖的package包/类
private BigDecimal eval(Interpreter interpreter, HashMap<String, BigDecimal> arguments, HashSet<String> reserved) throws SyntaxException, ArithmeticException, StackOverflowError {
if (value == null) {
BigDecimal l = left.eval(interpreter, arguments);
BigDecimal r = right.eval(interpreter, arguments);
switch (operator) {
case '-': return l.subtract(r);
case '+': return l.add(r);
case '*': return l.multiply(r);
case '%': return l.remainder(r);
case '/': return l.divide(r, interpreter.getInternalRounding(), RoundingMode.HALF_UP);
case '^': return l.pow(r.intValue());
}
}
if (reserved.contains(value))
throw new SyntaxException("Variable '" + value + "' is reserved");
if(arguments.containsKey(value))
return arguments.get(value);
HashMap<String, BigDecimal> variables = interpreter.getVariables();
if(variables.containsKey(value))
return variables.get(value);
if (value.contains("(")) {
HashMap<String, Function> functions = interpreter.getFunctions();
String name = value.split("\\(")[0];
if(!functions.containsKey(name)) throw new SyntaxException("Function '" + name + "' not defined");
String args = value.substring(name.length() + 1, value.length() - 1);
return functions.get(name).eval(interpreter, arguments, args);
}
if(value.matches("[0-9]+(\\.[0-9]*)?"))
return new BigDecimal(value);
throw new SyntaxException("Variable '" + value + "' not defined");
}
示例9: getValueForBlock
import java.util.HashMap; //导入方法依赖的package包/类
/**
* Get the value to use within the specified basic block available values
* are in phis.
* @param domNode
* @param inst
* @param phis
* @return
*/
private Value getValueForBlock(DomTreeNodeBase<BasicBlock> domNode,
Instruction inst, HashMap<DomTreeNodeBase<BasicBlock>, Value> phis)
{
if (domNode == null)
return Value.UndefValue.get(inst.getType());
if(phis.containsKey(domNode))
return phis.get(domNode);
DomTreeNodeBase<BasicBlock> idom = domNode.getIDom();
if (!inLoop(idom.getBlock()))
{
Value val = getValueForBlock(idom, inst, phis);
phis.put(domNode, val);
return val;
}
BasicBlock bb = domNode.getBlock();
PhiNode pn = new PhiNode(inst.getType(),
predCache.getNumPreds(bb),
inst.getName()+".lcssa",
bb);
phis.put(domNode, pn);
predCache.getPreds(bb).forEach(pred->
{
pn.addIncoming(getValueForBlock(dt.getNode(pred), inst, phis), pred);
});
return pn;
}
示例10: updatePlayerInfo
import java.util.HashMap; //导入方法依赖的package包/类
public void updatePlayerInfo(HashMap<String, String> values) {
playerInfo = values;
for (String key : values.keySet()) {
if (key.equals("name")) {
name = values.get(key);
}
if (key.equals("pid")) {
pid = values.get(key);
}
if (key.equals("ip")) {
ip = values.get(key);
}
if (key.equals("model")) {
model = values.get(key);
}
if (key.equals("version")) {
version = values.get(key);
}
if (key.equals("lineout")) {
lineout = values.get(key);
}
if (key.equals("network")) {
network = values.get(key);
}
if (key.equals("gid")) {
gid = values.get(key);
}
}
}
示例11: makeDiffMap1
import java.util.HashMap; //导入方法依赖的package包/类
/**
* Reduces Map1 and its elements to the ones which did not occur in Map2.
*
* @param Map1
* @param Map2
*/
private static void makeDiffMap1(HashMap<String, HashSet<String>> Map1,
HashMap<String, HashSet<String>> Map2) {
Set<String> keySet1 = new HashSet(Map1.keySet()); // conversion is type
// safe
Set<String> keySet2 = new HashSet(Map2.keySet()); // conversion is type
// safe
for (String s : keySet1) {
HashSet<String> values1 = Map1.get(s);
HashSet<String> values2 = null;
try {
values2 = (HashSet<String>) Map2.get(s).clone(); // conversion
// is type
// safe
} catch (NullPointerException e) {
continue; // here a method was found which is new and did not
// occur in map1
}
if ((values1 == null) || (values2 == null)) { // values should not
// be both null
// since only the
// intersection is
// considered
throw new Error("Values are not both not null.");
}
values1.removeAll(values2);
if (values1.isEmpty()) {
Map1.remove(s);
}
}
}
示例12: getZoomedCell
import java.util.HashMap; //导入方法依赖的package包/类
private ZoomedCell getZoomedCell(XMBean mbean, String attribute, Object value) {
synchronized (viewersCache) {
HashMap<String, ZoomedCell> viewers;
if (viewersCache.containsKey(mbean)) {
viewers = viewersCache.get(mbean);
} else {
viewers = new HashMap<String, ZoomedCell>();
}
ZoomedCell cell;
if (viewers.containsKey(attribute)) {
cell = viewers.get(attribute);
cell.setValue(value);
if (cell.isMaximized() && cell.getType() != XDataViewer.NUMERIC) {
// Plotters are the only viewers with auto update capabilities.
// Other viewers need to be updated manually.
Component comp =
mbeansTab.getDataViewer().createAttributeViewer(
value, mbean, attribute, XMBeanAttributes.this);
cell.init(cell.getMinRenderer(), comp, cell.getMinHeight());
XDataViewer.registerForMouseEvent(comp, mouseListener);
}
} else {
cell = new ZoomedCell(value);
viewers.put(attribute, cell);
}
viewersCache.put(mbean, viewers);
return cell;
}
}
示例13: getDeclaredType
import java.util.HashMap; //导入方法依赖的package包/类
private DeclaredType getDeclaredType(TypeElement e, HashMap<? extends Element, ? extends TypeMirror> map, Types types) {
List<? extends TypeParameterElement> tpes = e.getTypeParameters();
TypeMirror[] targs = new TypeMirror[tpes.size()];
int i = 0;
for (Iterator<? extends TypeParameterElement> it = tpes.iterator(); it.hasNext();) {
TypeParameterElement tpe = it.next();
TypeMirror t = map.get(tpe);
targs[i++] = t != null ? t : tpe.asType();
}
Element encl = e.getEnclosingElement();
if ((encl.getKind().isClass() || encl.getKind().isInterface()) && !((TypeElement)encl).getTypeParameters().isEmpty())
return types.getDeclaredType(getDeclaredType((TypeElement)encl, map, types), e, targs);
return types.getDeclaredType(e, targs);
}
示例14: toMap
import java.util.HashMap; //导入方法依赖的package包/类
static Map<String, List<String>> toMap(MimeHeaders headers) {
HashMap<String, List<String>> map = new HashMap<String, List<String>>();
for (Iterator<MimeHeader> i = headers.getAllHeaders(); i.hasNext();) {
MimeHeader mh = i.next();
List<String> values = map.get(mh.getName());
if (values == null) {
values = new ArrayList<String>();
map.put(mh.getName(), values);
}
values.add(mh.getValue());
}
return map;
}
示例15: setMonthParams
import java.util.HashMap; //导入方法依赖的package包/类
/**
* 设置传递进来的参数
*
* @param params
*/
public void setMonthParams(HashMap<String, Object> params) {
if (!params.containsKey(VIEW_PARAMS_MONTH) && !params.containsKey(VIEW_PARAMS_YEAR)) {
throw new InvalidParameterException("You must specify month and year for this view");
}
setTag(params);
// if (params.containsKey(VIEW_PARAMS_HEIGHT)) {
// mRowHeight = (int) params.get(VIEW_PARAMS_HEIGHT);
// if (mRowHeight < MIN_HEIGHT) {
// mRowHeight = MIN_HEIGHT;
// }
// }
if (params.containsKey(VIEW_PARAMS_SELECTED_BEGIN_DATE)) {
mStartDate = (SimpleMonthAdapter.CalendarDay) params.get(VIEW_PARAMS_SELECTED_BEGIN_DATE);
}
if (params.containsKey(VIEW_PARAMS_SELECTED_LAST_DATE)) {
mEndDate = (SimpleMonthAdapter.CalendarDay) params.get(VIEW_PARAMS_SELECTED_LAST_DATE);
}
if (params.containsKey("mNearestDay")) {
mNearestDay = (SimpleMonthAdapter.CalendarDay) params.get("mNearestDay");
}
mMonth = (int) params.get(VIEW_PARAMS_MONTH);
mYear = (int) params.get(VIEW_PARAMS_YEAR);
mHasToday = false;
mToday = -1;
mCalendar.set(Calendar.MONTH, mMonth);
mCalendar.set(Calendar.YEAR, mYear);
mCalendar.set(Calendar.DAY_OF_MONTH, 1);
mDayOfWeekStart = mCalendar.get(Calendar.DAY_OF_WEEK);
if (params.containsKey(VIEW_PARAMS_WEEK_START)) {
mWeekStart = (int) params.get(VIEW_PARAMS_WEEK_START);
} else {
mWeekStart = mCalendar.getFirstDayOfWeek();
}
mNumCells = CalendarUtils.getDaysInMonth(mMonth, mYear);
for (int i = 0; i < mNumCells; i++) {
final int day = i + 1;
if (sameDay(day, today)) {
mHasToday = true;
mToday = day;
}
}
mNumRows = calculateNumRows();
}