List of usage examples for java.util HashMap containsKey
public boolean containsKey(Object key)
From source file:com.github.chenxiaolong.dualbootpatcher.appsharing.AppSharingService.java
private void onPackageRemoved(final String pkg) { RomInformation info;//from www . ja va 2 s .c o m MbtoolConnection conn = null; try { conn = new MbtoolConnection(this); MbtoolInterface iface = conn.getInterface(); info = RomUtils.getCurrentRom(this, iface); } catch (Exception e) { Log.e(TAG, "Failed to determine current ROM. App sharing status was NOT updated", e); return; } finally { IOUtils.closeQuietly(conn); } if (info == null) { Log.e(TAG, "Failed to determine current ROM. App sharing status was NOT updated"); return; } // Unshare package if explicitly removed. This only exists to keep the config file clean. // Mbtool will not touch any app that's not listed in the package database. RomConfig config = RomConfig.getConfig(info.getConfigPath()); HashMap<String, SharedItems> sharedPkgs = config.getIndivAppSharingPackages(); if (sharedPkgs.containsKey(pkg)) { sharedPkgs.remove(pkg); config.setIndivAppSharingPackages(sharedPkgs); config.apply(); new Handler(Looper.getMainLooper()).post(new Runnable() { @Override public void run() { String message = getString(R.string.indiv_app_sharing_app_no_longer_shared); Toast.makeText(AppSharingService.this, String.format(message, pkg), Toast.LENGTH_LONG).show(); } }); } }
From source file:controller.Parser.java
static LP parse(File f) throws FileNotFoundException { Scanner s = new Scanner(f); Pattern p = Pattern.compile(dvarreg); HashMap<String, Integer> x = new HashMap<String, Integer>(); HashMap<Integer, String> xReverse = new HashMap<Integer, String>(); int xcol = 0; /* Get input size and names of the decision variables. */ int constraints = -1; // Take the objective function into account. while (s.hasNextLine()) { String line = s.nextLine(); if (line.trim().equals("")) continue; /* /*from w w w .j a v a 2 s . c om*/ * TODO: Beware, will now accept invalid * files with multiple objective functions. */ /* if (!validConstraint(line) && !validObj(line)) { String e = "Unsupported format in file " + f; throw new IllegalArgumentException(e); } */ Matcher m = p.matcher(line); while (m.find()) { String var = m.group(3); if (validVarName(var) && !x.containsKey(var)) { x.put(var, xcol); xReverse.put(xcol++, var); } } constraints++; } BigFraction[][] Ndata = new BigFraction[constraints][x.size()]; for (int i = 0; i < Ndata.length; i++) { Arrays.fill(Ndata[i], BigFraction.ZERO); } BigFraction[] bdata = new BigFraction[constraints]; BigFraction[] cdata = new BigFraction[x.size()]; Arrays.fill(cdata, BigFraction.ZERO); s = new Scanner(f); String obj = s.nextLine(); Matcher m = p.matcher(obj); while (m.find()) { String var = m.group(3); if (!x.containsKey(var)) continue; String sign = m.group(1); if (sign == null) sign = "+"; String coeffStr = m.group(2); BigFraction coeff; if (coeffStr == null) { coeff = BigFraction.ONE; } else { coeff = new BigFraction(Double.parseDouble(coeffStr)); } if (sign.equals("-")) coeff = coeff.negate(); cdata[x.get(var)] = coeff; } int row = 0; while (s.hasNextLine()) { String line = s.nextLine(); String[] split = line.split("<="); if (line.trim().equals("")) continue; if (split.length != 2) { String e = "Unsupported format in file " + f; throw new IllegalArgumentException(e); } m = p.matcher(line); bdata[row] = new BigFraction(Double.parseDouble(split[1])); while (m.find()) { String var = m.group(3); if (!x.containsKey(var)) continue; String sign = m.group(1); if (sign == null) sign = "+"; String coeffStr = m.group(2); BigFraction coeff; if (coeffStr == null) { coeff = BigFraction.ONE; } else { coeff = new BigFraction(Double.parseDouble(coeffStr)); } if (sign.equals("-")) coeff = coeff.negate(); Ndata[row][x.get(var)] = coeff; } row++; } return new LP(new Array2DRowFieldMatrix<BigFraction>(Ndata), new ArrayFieldVector<BigFraction>(bdata), new ArrayFieldVector<BigFraction>(cdata), xReverse); }
From source file:lux.index.XmlPathMapper.java
private void incrCount(HashMap<CharSequence, Integer> map, MutableString o) { if (map.containsKey(o)) map.put(o, map.get(o) + 1);/* w ww.j a v a 2s .c o m*/ else { MutableString copy = new MutableString(o); map.put(copy, 1); names.put(copy, copy); } }
From source file:edu.illinois.cs.cogcomp.transliteration.WikiTransliteration.java
/** * Given a map of productions and corresponding counts, get the counts of the source word in each * production.//from w w w . jav a 2 s . c o m * @param counts production counts * @return a map from source strings to counts. */ public static HashMap<String, Double> GetAlignmentTotals1(HashMap<Production, Double> counts) { // the string in this map is the source string. HashMap<String, Double> result = new HashMap<>(); for (Production key : counts.keySet()) { Double value = counts.get(key); String source = key.getFirst(); // Increment or set if (result.containsKey(source)) { result.put(source, result.get(source) + value); } else { result.put(source, value); } } return result; }
From source file:ru.apertum.qsystem.reports.generators.ReportsList.java
@Override protected Response preparationReport(HttpRequest request) { // ? , ? , String entityContent = NetUtil.getEntityContent(request); QLog.l().logger().trace("? \"" + entityContent + "\"."); // ?? ? . ? ?? String res = "/ru/apertum/qsystem/reports/web/error_login.html"; String usr = "err"; String pwd = "err"; // // w ww. jav a2s. c om final HashMap<String, String> cookie = NetUtil.getCookie(entityContent, "&"); if (cookie.containsKey("username") && cookie.containsKey("password")) { if (QReportsList.getInstance().isTrueUser(cookie.get("username"), cookie.get("password"))) { res = "/ru/apertum/qsystem/reports/web/reportList.html"; usr = cookie.get("username"); pwd = cookie.get("password"); } } final InputStream inStream = getClass().getResourceAsStream(res); byte[] result = null; try { result = RepResBundle.getInstance().prepareString(new String(Uses.readInputStream(inStream), "UTF-8")) .replaceFirst(Uses.ANCHOR_PROJECT_NAME_FOR_REPORT, Uses.getLocaleMessage("project.name" + FAbout.getCMRC_SUFF())) .getBytes("UTF-8"); if ("/ru/apertum/qsystem/reports/web/reportList.html".equals(res)) { // ?? ? result = new String(result, "UTF-8") .replaceFirst(Uses.ANCHOR_REPORT_LIST, QReportsList.getInstance().getHtmlRepList()) .getBytes("UTF-8"); // ? ??? //<META HTTP-EQUIV="Set-Cookie" CONTENT="NAME=value; EXPIRES=date; DOMAIN=domain_name; PATH=path; SECURE"> final String coocie = "<META HTTP-EQUIV=\"Set-Cookie\" CONTENT=\"username=" + URLEncoder.encode(usr, "utf-8") + "\">\n<META HTTP-EQUIV=\"Set-Cookie\" CONTENT=\"password=" + URLEncoder.encode(pwd, "utf-8") + "\">"; result = new String(result, "UTF-8").replaceFirst(Uses.ANCHOR_COOCIES, coocie).getBytes("UTF-8"); } } catch (IOException ex) { throw new ReportException( " ? ?? ? . " + ex); } return new Response(result); }
From source file:com.apexxs.neonblack.scoring.StringScorers.java
public void getDocumentCountryContext(List<DetectedLocation> locs) { HashMap<String, Integer> contextHashMap = new HashMap<>(); for (DetectedLocation loc : locs) { if (!StringUtils.isEmpty(loc.countryCode)) { if (!contextHashMap.containsKey(loc.countryCode)) { contextHashMap.put(loc.countryCode, loc.startPos.size()); } else { contextHashMap.put(loc.countryCode, contextHashMap.get(loc.countryCode) + loc.startPos.size()); }/*from w ww.j av a 2 s . co m*/ } } }
From source file:com.wormsim.utils.Utils.java
public static SimulationCommands readCommandLine(String[] p_args) throws IllegalArgumentException { // Convert the arguments into command lists HashMap<String, List<String>> data = new HashMap<>(p_args.length); String current_cmd = null;//w w w . j a v a 2 s .c o m for (String arg : p_args) { if (arg.startsWith("-")) { current_cmd = arg; if (data.putIfAbsent(arg, new ArrayList<>(2)) != null) { throw new IllegalArgumentException("Repeated Argument: " + arg); } } else if (current_cmd != null) { data.get(current_cmd).add(arg); } else { throw new IllegalArgumentException("First Parameter must be Argument: " + arg); } } // Check if any of the commands are something to act upon right now, like help. // WARNING: Hard Coded Parameters. if (data.containsKey("-h") || data.containsKey("--help")) { // Print out the help and then terminate, although the other arguments should // also be checked to see if they are relevant. help(); System.exit(0); // Generally not recommended, but should be fine here. // TODO: Detailed information as per argument for help? } SimulationCommands cmds = new SimulationCommands(data); return cmds; }
From source file:com.ibm.crail.tools.CrailFsck.java
private void incStats(HashMap<String, AtomicInteger> stats, String host) { if (!stats.containsKey(host)) { stats.put(host, new AtomicInteger(0)); }/*from w w w . j av a 2 s .com*/ stats.get(host).incrementAndGet(); }
From source file:org.apache.tika.language.translate.CachedTranslator.java
/** * Check whether this CachedTranslator's cache contains a translation of the text from the * source language to the target language. * * @param text What string to check for. * @param sourceLanguage The source language of translation. * @param targetLanguage The target language of translation. * @return true if the cache contains a translation of the text, false otherwise. *//*from ww w . j a v a2 s .c o m*/ public boolean contains(String text, String sourceLanguage, String targetLanguage) { HashMap<String, String> translationCache = getTranslationCache(sourceLanguage, targetLanguage); return translationCache.containsKey(text); }
From source file:com.twosigma.beakerx.chart.ChartDetails.java
protected String getGraphicsUid(HashMap content) { String ret = null;/* w w w . j ava 2 s.co m*/ if (content.containsKey("itemId")) { ret = (String) content.get("itemId"); } return ret; }