public static void main(String[] args) { /*HashMap<Integer, List<TestMap>> map = new HashMap<Integer, List<TestMap>>(); List<TestMap> list = new ArrayList<TestMap>(); list.add(new TestMap("1")); list.add(new TestMap("2")); list.add(new TestMap("3")); list.add(new TestMap("4")); list.add(new TestMap("5")); list.add(new TestMap("6")); map.put(1, list); map.put(2, list); System.out.println(map.toString().replaceAll("\\{", "").replaceAll("\\[", "").replaceAll("], ", ";").replaceAll(", ", "_").replaceAll("]}", ""));*/ HashMap<Long, Long> map = new HashMap<Long, Long>(); map.put(11l, 10l); map.put(13l, 12l); map.put(14l, 15l); map.put(17l, 16l); System.out.println(map.containsKey(11l)); System.out.println(map.containsKey(11l)); System.out.println(map.containsKey(12l)); System.out.println(map.containsKey(12l)); System.out.println(map.containsValue(11l)); System.out.println(map.containsValue(11l)); System.out.println(map.containsValue(12l)); System.out.println(map.containsValue(12l)); }
public void readMeanHeatMap(InputStream in) { BufferedReader br = null; try { br = new BufferedReader(new InputStreamReader(in)); String line = ""; line = br.readLine(); boolean first = true; int probeTableInd = 0; while (line != null) { if (first) { int tissueInd = 0; int strainInd = 0; String[] split = line.split(","); for (int i = 1; i < split.length; i++) { String curTissue = split[i].substring(0, split[i].indexOf(".")); String curStrain = split[i].substring(split[i].indexOf(".") + 1, split[i].lastIndexOf(".")); if (!tissues.containsValue(curTissue)) { tissues.put(tissueInd, curTissue); tissueInd++; } if (!meanStrains.containsValue(curStrain)) { meanStrains.put(strainInd, curStrain); strainInd++; } } first = false; } else { String[] split = line.split(","); String probeID = split[0]; fullProbeList.add(probeID); HashMap tmpData = new HashMap(); ArrayList<Double> means = new ArrayList<Double>(); for (int i = 1; i < split.length; i++) { means.add(Double.parseDouble(split[i])); } tmpData.put("meanRow", means); data.put(probeID, tmpData); } line = br.readLine(); } br.close(); } catch (IOException ex) { ex.printStackTrace(System.err); Logger.getLogger(FullHeatMapData.class.getName()).log(Level.SEVERE, null, ex); } finally { try { br.close(); } catch (IOException ex) { ex.printStackTrace(System.err); Logger.getLogger(FullHeatMapData.class.getName()).log(Level.SEVERE, null, ex); } } }
/** * Method used for API calls, with the request type, body, headers, and callback as parameters. */ public void apiCall( String method, String url, LinkedHashMap<String, String> body, HashMap<String, String> headerMap, Callback callback) { try { OkHttpClient client = new OkHttpClient(); // Check if the Platform is authorized, and add the authorization header this.isAuthorized(); headerMap.put("Authorization", this.getAuthHeader()); // Generate the proper url to be passed into the request HashMap<String, String> options = new HashMap<>(); options.put("addServer", "true"); String apiUrl = apiURL(url, options); Request.Builder requestBuilder = new Request.Builder(); // Add all the headers to the Request.Builder from the headerMap for (Map.Entry<String, String> entry : headerMap.entrySet()) { requestBuilder.addHeader(entry.getKey(), entry.getValue()); } Request request = null; if (method.toUpperCase().equals("GET")) { request = requestBuilder.url(apiUrl).build(); } else if (method.toUpperCase().equals("DELETE")) { request = requestBuilder.url(apiUrl).delete().build(); } else { // For POST and PUT requests, find and set what MediaType the body is MediaType mediaType; if (headerMap.containsValue("application/json")) { mediaType = JSON_TYPE_MARKDOWN; } else if (headerMap.containsValue("multipart/mixed")) { mediaType = MULTI_TYPE_MARKDOWN; } else { mediaType = MEDIA_TYPE_MARKDOWN; } String bodyString = getBodyString(body, mediaType); if (method.toUpperCase().equals("POST")) { request = requestBuilder.url(apiUrl).post(RequestBody.create(mediaType, bodyString)).build(); } else if (method.toUpperCase().equals("PUT")) { request = requestBuilder.url(apiUrl).put(RequestBody.create(mediaType, bodyString)).build(); } } // Make OKHttp request call, that returns response to the callback client.newCall(request).enqueue(callback); } catch (Exception e) { e.printStackTrace(); } }
// 获取所有视频未读消息 public List<HashMap<String, String>> getAllNotifyNoRead() { Cursor cursor = null; try { String sql = "select distinct " + TablesColumns.TABLENOTICE_ID + "," + TablesColumns.TABLENOTICE_SUBJECT + "," + TablesColumns.TABLENOTICE_SIGNAL + "," + TablesColumns.TABLENOTICE_CONTEXT + "," + TablesColumns.TABLENOTICE_USER + "," + TablesColumns.TABLENOTICE_ALERT + "," + TablesColumns.TABLENOTICE_OPERATOR + "," + TablesColumns.TABLENOTICE_CREATEDAT + "," + TablesColumns.TABLENOTICE_READAT + " from " + TablesColumns.TABLENOTICE + " where " + TablesColumns.TABLENOTICE_READAT + " = 'null' and " + TablesColumns.TABLENOTICE_SIGNAL + " in ('like','comment') ORDER BY " + TablesColumns.TABLENOTICE_CREATEDAT + " DESC"; cursor = dataBase.rawQuery(sql, null); List<HashMap<String, String>> data = new ArrayList<HashMap<String, String>>(); HashMap<String, String> map; String[] names = cursor.getColumnNames(); while (cursor.moveToNext()) { map = new HashMap<String, String>(); for (String name : names) { map.put(name, cursor.getString(cursor.getColumnIndex(name))); } boolean isAlreadContain = false; for (HashMap<String, String> alMap : data) { if (alMap.containsValue(map.get(TablesColumns.TABLENOTICE_ID).toString())) { isAlreadContain = true; break; } } if (isAlreadContain) { continue; } data.add(map); } cursor.close(); return data; } catch (Exception e) { return null; } finally { if (cursor != null) cursor.close(); } }
public static void main(String[] args) { HashMap<String, String> usuario = new HashMap<String, String>(); usuario.put("angelo", "1234"); int oportunidades = 3; boolean accesoPermitido = false; Scanner entrada = new Scanner(System.in); System.out.println("Acceso"); System.out.println("========="); System.out.print("Introduzca su nombre de usuario: "); String nombreUsuario = entrada.nextLine(); System.out.print("Introduzca contraseña: "); String contraseñaIntro = entrada.nextLine(); do { if (!usuario.containsKey(nombreUsuario) || !usuario.containsValue(contraseñaIntro)) { System.out.println("Lo siento el usuario o contraseña introducidos no existen"); System.out.print("Vuelva a introducir su nombre de usuario: "); nombreUsuario = entrada.nextLine(); System.out.print("Vuelva a introducir la contraseña: "); contraseñaIntro = entrada.nextLine(); oportunidades--; System.out.println("oportunidades: " + oportunidades); } else { System.out.println("Bienvenido de nuevo " + usuario.get(nombreUsuario)); accesoPermitido = true; } if (oportunidades == 0) { System.out.println("Lo siento se quedo sin oportunidades."); } } while (accesoPermitido == false && oportunidades > 0); }
/** * The constructor automatically adds the new Type to the set so that it can be used just as the * constant Types are. * * @param name The name of the API. * @param code The code that will be passed to PortAudio. */ public Type(String name, int code) { if (map.containsValue(code)) throw new IllegalArgumentException(); this.name = name; this.code = code; map.put(code, this); set.add(this); }
/** * Stores warps in the warp array * * @param player * @param loc */ public boolean addWarp(final UUID player, Location loc) { // Do not allow warps to be in the same location if (warpList.containsValue(loc)) { return false; } // Remove the old warp if it existed if (warpList.containsKey(player)) { warpList.remove(player); } warpList.put(player, loc); saveWarpList(); // Update warp signs // Run one tick later because text gets updated at the end of tick plugin .getServer() .getScheduler() .runTask( plugin, new Runnable() { @Override public void run() { plugin.getWarpPanel().addWarp(player); plugin.getWarpPanel().updatePanel(); } }); return true; }
/** * Allows to get all options given by the user and passed to the server with the post method * * @param req */ private void getOptions(HttpServletRequest req, HttpSession session) { String optionNumber = req.getParameter("optionsNumber"); int optionNumberInt = 0; if (optionNumber != null) { map = new HashMap<String, String>(); optionNumberInt = new Integer(optionNumber).intValue(); for (int i = 1; i < optionNumberInt + 1; i++) { if (req.getParameter("option" + i) != null) { map.put("option" + i, req.getParameter("option" + i)); } if (req.getParameter("value" + i) != null) { map.put("value" + i, req.getParameter("value" + i)); } if (i > 1 && req.getParameter("and-or" + i) != null) { map.put("and-or" + i, req.getParameter("and-or" + i)); } } } if (!isAdmin && currentIP != null && !currentIP.equals("")) { optionNumberInt++; if (!map.containsValue("ip")) { map.put("option" + optionNumberInt, "ip"); map.put("value" + optionNumberInt, currentIP); if (optionNumberInt > 1) { map.put("and-or" + optionNumberInt, "and"); } } } session.setAttribute("optionNumber", (Integer) optionNumberInt); }
public static Character getFirstNonRepeatingChar(String strInput) { Character firstNonRepeatingChar = null; int strLength = strInput.length(); if (strLength > 0) { HashMap<Character, Boolean> charactersMap = new HashMap<Character, Boolean>(strLength); for (int i = 0; i < strLength; i++) { char character = strInput.charAt(i); if (charactersMap.containsKey(character)) { charactersMap.put(character, Boolean.FALSE); } else { charactersMap.put(character, Boolean.TRUE); } } if (charactersMap.containsValue(true)) { for (int i = 0; i < strLength; i++) { char character = strInput.charAt(i); Boolean isNonRepeating = charactersMap.get(character); if (isNonRepeating) { firstNonRepeatingChar = character; break; } } } } return firstNonRepeatingChar; }
@Override public synchronized void onLinphoneChatMessageStateChanged(LinphoneChatMessage msg, State state) { final LinphoneChatMessage finalMessage = msg; final String finalImage = finalMessage.getExternalBodyUrl(); final State finalState = state; if (LinphoneActivity.isInstanciated() && state != State.InProgress) { if (finalMessage != null && !finalMessage.equals("")) { LinphoneActivity.instance() .onMessageStateChanged(sipUri, finalMessage.getText(), finalState.toInt()); } else if (finalImage != null && !finalImage.equals("")) { if (latestImageMessages != null && latestImageMessages.containsValue(finalImage)) { int id = -1; for (int key : latestImageMessages.keySet()) { String object = latestImageMessages.get(key); if (object.equals(finalImage)) { id = key; break; } } if (id != -1) { LinphoneActivity.instance().onImageMessageStateChanged(sipUri, id, finalState.toInt()); } } } if (lastSentMessagesBubbles != null && lastSentMessagesBubbles.size() > 0) { for (BubbleChat bubble : lastSentMessagesBubbles) { if (bubble.getNativeMessageObject() == finalMessage) { bubble.updateStatusView(finalState); } } } adapter.notifyDataSetChanged(); } }
/** * Adds an add-on element to the model. * * @param name Name displayed in the list. * @param addonPanel Panel displayed, when the item is selected. */ public synchronized void addElement(@Nonnull String name, @Nonnull AddonPanel addonPanel) { if (!names.containsValue(name)) { names.put(idxCounter, name); addons.put(idxCounter, addonPanel); idxCounter++; } }
public static boolean trySitPlayer(Player player, Block block) { String coords = Methods.convertBlock(block, false); if (occupiedChairs.containsKey(player)) return false; if (occupiedChairs.containsValue(coords)) return false; occupiedChairs.put(player, coords); resitPlayer(player, block); startTask(player); return true; }
public void remIngredientePrato(Alimento alimento, String nomePrato) { if (alimento != null) { if (alimentos.containsValue(alimento)) { Prato tmp = pratos.get(nomePrato); tmp.remIngrediente(alimento); } } else { System.out.println("Imposs’vel adicionar!"); } }
/** * doLogout * * <p>loggs an user out * * @param ticket - validation-hash * @return if the check out was successful */ public boolean doLogout(String ticket) { if (tickets.containsValue(ticket)) { for (Date aKey : tickets.keySet()) { String s = tickets.get(aKey); if (s.equals(ticket)) tickets.remove(aKey); } return true; } return false; }
private static boolean isUnique( PsiParameter[] params, String newName, HashMap<PsiField, String> usedNames) { if (usedNames.containsValue(newName)) return false; for (PsiParameter parameter : params) { if (Comparing.strEqual(parameter.getName(), newName)) { return false; } } return true; }
public static boolean addRender(MachineRegistry m, RotaryTERenderer r) { if (!renders.containsValue(r)) { renders.put(m, r); return true; } else { MachineRegistry parent = ReikaJavaLibrary.getHashMapKeyByValue(renders, r); overrides.put(m, parent); return false; } }
@Override public boolean containsValue(Object value) { if (singleton_key != null) return singleton_value.equals(value); if (array_keys != null) { for (int i = 0; i < ARRAY_SIZE; i++) if (array_keys[i] != null && array_values[i].equals(value)) return true; return false; } if (hashmap != null) return hashmap.containsValue(value); return false; }
@Override public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); if (id == R.id.new_input) { try { final Button b = new Button(getApplicationContext()); b.setMaxEms(10); b.setText("Sensor"); Random rnd = new Random(); int color = Color.argb(255, rnd.nextInt(16) * 16, rnd.nextInt(16) * 16, rnd.nextInt(16) * 16); while (inputColorMap.containsValue(color)) { color = Color.argb(255, rnd.nextInt(16) * 16, rnd.nextInt(16) * 16, rnd.nextInt(16) * 16); } b.setBackgroundColor(color); inputColorMap.put(b, color); b.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View view) { if (selectedInput == b) { b.setEnabled(true); selectedInput = null; } else { b.setEnabled(false); if (selectedInput != null) { selectedInput.setEnabled(true); } selectedInput = b; } } }); inputs.addView(b); inputOutputMap.put(b, new HashSet<Button>()); return true; } catch (Exception e) { e.printStackTrace(); return false; } } if (id == R.id.new_output) { Intent i = new Intent( Intent.ACTION_PICK, android.provider.MediaStore.Audio.Media.EXTERNAL_CONTENT_URI); startActivityForResult(i, MUSIC_PICKER_CODE); return true; } return super.onOptionsItemSelected(item); }
/** * Adds a working set descriptor. * * @param descriptor working set descriptor to add. Must not exist in the registry yet. */ public void addWorkingSetDescriptor(WorkingSetDescriptor descriptor) { Assert.isTrue( !workingSetDescriptors.containsValue(descriptor), "working set descriptor already registered"); //$NON-NLS-1$ IExtensionTracker tracker = PlatformUI.getWorkbench().getExtensionTracker(); tracker.registerObject( descriptor.getConfigurationElement().getDeclaringExtension(), descriptor, IExtensionTracker.REF_WEAK); workingSetDescriptors.put(descriptor.getId(), descriptor); }
@Override public boolean contains(Object o) { if (o == null) { return false; } if (o instanceof Vehicle) { return VEHICLE_MAP.containsValue((Vehicle) o); } else if (o instanceof Integer) { return VEHICLE_MAP.containsKey((Integer) o); } return false; }
/** * Returns a HashSet with the operations that have data element 'data' as output element. * * @param data PDMDataElement * @return HashSet */ public HashSet getOperationsWithOutputElement(PDMDataElement data) { HashSet opso = new HashSet(); Object[] ops = operations.values().toArray(); for (int i = 0; i < ops.length; i++) { PDMOperation op = (PDMOperation) ops[i]; HashMap outputs = op.getOutputElements(); if (outputs.containsValue(data)) { opso.add(op); } } return opso; }
@Override public Iterator<AssemblyTask> getAvailableTasks(User user) { IteratorConverter<WorkPost> converter = new IteratorConverter<>(); HashMap<AssemblyTask, String> tasks = new HashMap<AssemblyTask, String>(); for (AssemblyLine line : this.getOrderManager().getMainScheduler().getAssemblyLines()) for (WorkPost post : converter.convert(line.getWorkPostsIterator())) for (AssemblyTask task : post.getResponsibleTasksClone()) if (task.canBeOrdered()) if (!tasks.containsValue(task.toString())) tasks.put(task, task.toString()); return tasks.keySet().iterator(); }
public boolean quicker() { HashMap<Integer, Integer> hs = new HashMap(); for (int i = 0; i < a.length; i++) { hs.put(a[i], sum - a[i]); } Iterator<Integer> i = hs.keySet().iterator(); while (i.hasNext()) { int tempKey = (int) i.next(); int diff = sum - tempKey; if (hs.containsValue(new Integer(diff))) return true; } return false; }
private static HashMap<String, CyRootNetwork> getRootNetworkMap( CyNetworkManager cyNetworkManager, CyRootNetworkManager cyRootNetworkManager) { HashMap<String, CyRootNetwork> name2RootMap = new HashMap<String, CyRootNetwork>(); for (CyNetwork net : cyNetworkManager.getNetworkSet()) { final CyRootNetwork rootNet = cyRootNetworkManager.getRootNetwork(net); if (!name2RootMap.containsValue(rootNet)) name2RootMap.put(rootNet.getRow(rootNet).get(CyRootNetwork.NAME, String.class), rootNet); } return name2RootMap; }
/** * Funcion encargada de modificar los colores de los cuadros de notificacion principal. * * @param v */ public void cambiarColorCuadroNotificacion(View v) { TextView tvVerde = (TextView) v.findViewById(R.id.avisoVerde); TextView tvRojo = (TextView) v.findViewById(R.id.avisoRojo); HashMap<String, Boolean> arrSincronizados = new HashMap<String, Boolean>(); arrSincronizados.putAll(arrSincronizadosEmpresa); arrSincronizados.putAll(arrSincronizadosEmpleado); // pintamos.. if (arrSincronizados.containsValue(true) && arrSincronizados.containsValue(false)) { tvRojo.setBackgroundResource(R.drawable.borde_rojo); tvVerde.setBackgroundResource(R.drawable.borde_blanco); } else if (arrSincronizados.containsValue(true)) { tvRojo.setBackgroundResource(R.drawable.borde_blanco); tvVerde.setBackgroundResource(R.drawable.borde_verde); } else if (arrSincronizados.containsValue(false)) { tvRojo.setBackgroundResource(R.drawable.borde_rojo); tvVerde.setBackgroundResource(R.drawable.borde_blanco); } }
public ThievesPlayer getThiefFromTarget(Player target) { ThievesPlayer thief = null; if (stealingPlayers.containsValue(plugin.getPlayerManager().getPlayer(target))) { for (Entry<ThievesPlayer, ThievesPlayer> couple : stealingPlayers.entrySet()) { if (couple.getValue().getDisplayName().equalsIgnoreCase(target.getDisplayName())) { thief = couple.getKey(); break; } } } return thief; }
// decryption public static String buildDecryptedMessage(String message) { decryptedMessage = ""; String delims = "[ ]+"; String[] words = message.split(delims); for (String word : words) { // word = word.toLowerCase(); // how many strings will this create? if (wordMap.containsValue(word.toLowerCase())) { decryptedMessage += decryptWord(word.toLowerCase()) + " "; } else { decryptedMessage += decryptChar(word.toLowerCase()) + " "; } } return decryptedMessage.trim(); }
public boolean wordPattern(String pattern, String str) { if (pattern == null || pattern == "") return true; String[] strArr = str.split(" "); if (strArr.length != pattern.length()) return false; HashMap<Character, String> map = new HashMap<>(); for (int i = 0; i < pattern.length(); i++) { if (!map.containsKey(pattern.charAt(i))) { if (map.containsValue(strArr[i])) return false; else map.put(pattern.charAt(i), strArr[i]); } else { if (!map.get(pattern.charAt(i)).equals(strArr[i])) return false; } } return true; }
/** val -> key (文字列→バイナリ値) */ private int convertMap(HashMap<Integer, String> map, String val) { if (CONTENTTYPES.containsValue(val)) { for (Iterator<Entry<Integer, String>> it = CONTENTTYPES.entrySet().iterator(); it.hasNext(); ) { Entry<Integer, String> entry = (Entry<Integer, String>) it.next(); Integer key = entry.getKey(); String value = entry.getValue(); if (value.equals(val)) { return key; } } } // unknown return 0; }
public static boolean moveSpot(NPC npc) { int key = npc.getTileHash(); Integer spot = moveSpots.get(key); if (spot == null && moveSpots.containsValue(key)) { for (Integer k : moveSpots.keySet()) { Integer v = moveSpots.get(k); if (v == key) { spot = k; break; } } } if (spot == null) return false; npc.setNextWorldTile(new WorldTile(spot)); return true; }