List of usage examples for java.util Hashtable put
public synchronized V put(K key, V value)
From source file:unalcol.termites.boxplots.SucessfulRatesGlobal.java
private static CategoryDataset createDataset(ArrayList<Double> Pf) { DefaultCategoryDataset defaultcategorydataset = new DefaultCategoryDataset(); String sDirectorio = "..\\results\\"; File f = new File(sDirectorio); String extension;/*from ww w. j a v a 2 s .c om*/ File[] files = f.listFiles(); Hashtable<String, String> Pop = new Hashtable<>(); PrintWriter escribir; Scanner sc = null; double sucessfulExp = 0.0; Hashtable<String, List> info = new Hashtable(); //String[] aMode = {"levywalk", "lwphevap", "hybrid", "hybrid3", "hybrid4"}; info.put("levywalk", new ArrayList()); info.put("lwphevap", new ArrayList()); info.put("hybrid", new ArrayList()); //info.put("hybrid3", new ArrayList()); //info.put("hybrid4", new ArrayList()); info.put("sequential", new ArrayList()); for (File file : files) { extension = ""; int i = file.getName().lastIndexOf('.'); int p = Math.max(file.getName().lastIndexOf('/'), file.getName().lastIndexOf('\\')); if (i > p) { extension = file.getName().substring(i + 1); } // System.out.println(file.getName() + "extension" + extension); if (file.isFile() && extension.equals("csv") && file.getName().startsWith("dataCollected") && file.getName().contains("mazeon")) { System.out.println(file.getName()); System.out.println("get: " + file.getName()); String[] filenamep = file.getName().split(Pattern.quote("+")); System.out.println("file" + filenamep[8]); int popsize = Integer.valueOf(filenamep[3]); double pf = Double.valueOf(filenamep[5]); String mode = filenamep[7]; int maxIter = -1; //if (!filenamep[8].isEmpty()) { maxIter = Integer.valueOf(filenamep[9]); //} System.out.println("psize:" + popsize); System.out.println("pf:" + pf); System.out.println("mode:" + mode); System.out.println("maxIter:" + maxIter); //String[] aMode = {"random", "levywalk", "sandc", "sandclw"}; //String[] aMode = {"lwphclwevap", "lwsandc2", "lwsandc", "lwphevap2", "lwphevap"}; // String[] aMode = {"levywalk", "lwphevap", "hybrid"}; //String[] aMode = {"levywalk", "lwphevap", "hybrid", "hybrid3", "hybrid4", "sequential"}; String[] aMode = { "levywalk", "lwphevap", "hybrid", "sequential" }; if (isInMode(aMode, mode)) { final List list = new ArrayList(); try { sc = new Scanner(file); } catch (FileNotFoundException ex) { Logger.getLogger(DataCollectedLatexConsolidatorSASOMessagesSend1.class.getName()) .log(Level.SEVERE, null, ex); } int roundNumber = 0; double globalInfoCollected = 0; String[] data = null; while (sc.hasNext()) { String line = sc.nextLine(); data = line.split(","); //System.out.println("data"); roundNumber = Integer.valueOf(data[0]); globalInfoCollected = Double.valueOf(data[4]); if (globalInfoCollected >= 90 && Pf.contains(pf)) { info.get(mode).add(roundNumber); break; } } } } } for (String key : info.keySet()) { System.out.println(key + ":" + info.get(key).size() / 30 * 100.0); defaultcategorydataset.addValue(info.get(key).size() / 30.0 * 100.0, "", getTechniqueName(key)); } return defaultcategorydataset; }
From source file:de.tbuchloh.kiskis.gui.AbstractAccountDetailView.java
/** * initializes the map which stores (Class, Class)-pairs. The key is the * model class, the value is the view class. * /*from w ww .ja v a 2 s. c o m*/ * @return the map */ private static Hashtable<Class, Class> initNodeMap() { final Hashtable<Class, Class> map = new Hashtable<Class, Class>(); map.put(BankAccount.class, BankAccountView.class); map.put(CreditCard.class, CreditCardView.class); map.put(GenericAccount.class, GenericAccountView.class); map.put(NetAccount.class, NetAccountView.class); map.put(SecuredFile.class, SecuredFileView.class); return map; }
From source file:com.mirth.connect.connectors.jms.JmsMessageUtils.java
public static Object getObjectForMessage(Message source) throws JMSException { Object result = null;/*ww w . j av a2 s. c om*/ try { if (source instanceof ObjectMessage) { result = ((ObjectMessage) source).getObject(); } else if (source instanceof MapMessage) { Hashtable map = new Hashtable(); MapMessage m = (MapMessage) source; for (Enumeration e = m.getMapNames(); e.hasMoreElements();) { String name = (String) e.nextElement(); Object obj = m.getObject(name); map.put(name, obj); } result = map; } else if (source instanceof javax.jms.BytesMessage) { javax.jms.BytesMessage bm = (javax.jms.BytesMessage) source; java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream(); byte[] buffer = new byte[1024 * 4]; int len = 0; bm.reset(); while ((len = bm.readBytes(buffer)) != -1) { baos.write(buffer, 0, len); } baos.flush(); result = baos.toByteArray(); baos.close(); if (result != null) { if (logger.isDebugEnabled()) logger.debug("JMSToObject: extracted " + ((byte[]) result).length + " bytes from JMS BytesMessage"); } } else if (source instanceof TextMessage) { result = ((TextMessage) source).getText(); } else if (source instanceof BytesMessage) { byte[] bytes = getBytesFromMessage(source); return CompressionHelper.uncompressByteArray(bytes); } else if (source instanceof StreamMessage) { StreamMessage sm = (javax.jms.StreamMessage) source; result = new java.util.Vector(); try { Object obj = null; while ((obj = sm.readObject()) != null) { ((java.util.Vector) result).addElement(obj); } } catch (MessageEOFException eof) { } catch (Exception e) { throw new JMSException("Failed to extract information from JMS Stream Message: " + e); } } else { result = source; } } catch (Exception e) { throw new JMSException("Failed to transform message: " + e.getMessage()); } return result; }
From source file:com.aegiswallet.utils.BasicUtils.java
public static Bitmap encodeAsBitmap(String contents, BarcodeFormat format, int dimension) { Bitmap bitmap = null;/*w w w.ja v a 2s .c o m*/ try { final Hashtable<EncodeHintType, Object> hints = new Hashtable<EncodeHintType, Object>(); //hints.put(EncodeHintType.MARGIN, 0); hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H); final BitMatrix result = qrCodeWriter.encode(contents, BarcodeFormat.QR_CODE, dimension, dimension, hints); final int width = result.getWidth(); final int height = result.getHeight(); final int[] pixels = new int[width * height]; for (int y = 0; y < height; y++) { final int offset = y * width; for (int x = 0; x < width; x++) { pixels[offset + x] = result.get(x, y) ? Color.BLACK : Color.WHITE; } } bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); bitmap.setPixels(pixels, 0, width, 0, 0, width, height); return bitmap; } catch (WriterException e) { Log.e("Basic Utils", "cannot write to bitmap " + e.getMessage()); } return bitmap; }
From source file:Main.java
public static Hashtable<String, Element> getChildHash(Element elem, String elementName, String attrName) { if (elem == null) return null; NodeList nl = elem.getChildNodes(); if (nl == null) return null; Hashtable<String, Element> retlist = new Hashtable<String, Element>(100); for (int n = 0; n < nl.getLength(); n++) { Node child = nl.item(n);/* w ww . j ava 2s. c om*/ if (child instanceof Element) { Element element = (Element) child; if (!elementName.equals(element.getTagName())) continue; String keyValue = element.getAttribute(attrName); if (keyValue == null) continue; retlist.put(keyValue, element); } } if (retlist.size() == 0) return null; return retlist; }
From source file:Main.java
/** * Method getHashtableFromVector./*from w w w .j a v a 2 s.c o m*/ * @param vector Vector * @param keyGetter String * @return Hashtable * @throws NoSuchMethodException * @throws InvocationTargetException * @throws IllegalAccessException */ public static Hashtable getHashtableFromVector(Vector vector, String keyGetter) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { Hashtable hashtable = new Hashtable(vector.size()); Object vectorElement = null; Object keyObject = null; Method keyGetterMethod = null; Class[] clsParms = new Class[0]; Object[] objParms = new Object[0]; for (int i = 0; i < vector.size(); i++) { vectorElement = vector.elementAt(i); keyGetterMethod = vectorElement.getClass().getMethod(keyGetter, clsParms); keyObject = keyGetterMethod.invoke(vectorElement, objParms); hashtable.put(keyObject, vectorElement); } return hashtable; }
From source file:net.grinder.util.NetworkUtils.java
public static List<String> getDnsServers() throws NamingException { Hashtable<String, String> env = new Hashtable<String, String>(); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.dns.DnsContextFactory"); DirContext ctx = null;/*from www . j a v a2 s .c o m*/ List<String> dnsServers = new ArrayList<String>(); try { ctx = new InitialDirContext(env); String dnsString = (String) ctx.getEnvironment().get("java.naming.provider.url"); for (String each : dnsString.split(" ")) { dnsServers.add(each.replace("dns://", "")); } } catch (Exception e) { NoOp.noOp(); } finally { if (ctx != null) { ctx.close(); } } return dnsServers; }
From source file:ReflectClass.java
static String tName(String nm, Hashtable ht) { String yy;/*from www . j a v a 2s . c om*/ String arr; if (nm.charAt(0) != '[') { int i = nm.lastIndexOf("."); if (i == -1) return nm; // It's a primitive type, ignore it. else { yy = nm.substring(i + 1); if (ht != null) ht.put(nm, yy); // note class types in the hashtable. return yy; } } arr = "[]"; if (nm.charAt(1) == '[') yy = tName(nm.substring(1), ht); else { switch (nm.charAt(1)) { case 'L': yy = tName(nm.substring(nm.indexOf("L") + 1, nm.indexOf(";")), ht); break; case 'I': yy = "int"; break; case 'V': yy = "void"; break; case 'C': yy = "char"; break; case 'D': yy = "double"; break; case 'F': yy = "float"; break; case 'J': yy = "long"; break; case 'S': yy = "short"; break; case 'Z': yy = "boolean"; break; case 'B': yy = "byte"; break; default: yy = "BOGUS:" + nm; break; } } return yy + arr; }
From source file:com.kevinquan.google.activityrecoginition.model.MotionHelper.java
public static List<MotionSnapshot> parseMotionSnapshots(Cursor result, final boolean sortDescending) { if (!CursorUtils.hasResults(result)) { Log.d(TAG, "No results were provided to parse motion snapshots from"); return new ArrayList<MotionSnapshot>(); }/*from w w w . j av a 2 s . c o m*/ Hashtable<Long, MotionSnapshot> snapshots = new Hashtable<Long, MotionSnapshot>(); do { Motion thisMotion = new Motion(result); if (thisMotion.getTimestamp() == 0) { Log.w(TAG, "Current motion seems corrupt: " + thisMotion); continue; } if (!snapshots.containsKey(thisMotion.getTimestamp())) { MotionSnapshot snapshot = new MotionSnapshot(thisMotion); snapshots.put(snapshot.getTimestamp(), snapshot); } else { if (!snapshots.get(thisMotion.getTimestamp()).addMotion(thisMotion)) { Log.w(TAG, "Could not add motion to snapshot: " + thisMotion.toString()); } } } while (result.moveToNext()); List<MotionSnapshot> results = new ArrayList<MotionSnapshot>(); results.addAll(snapshots.values()); Collections.sort(results, new Comparator<MotionSnapshot>() { @Override public int compare(MotionSnapshot lhs, MotionSnapshot rhs) { int result = ((Long) lhs.getTimestamp()).compareTo((Long) rhs.getTimestamp()); return sortDescending ? -1 * result : result; } }); return results; }
From source file:com.flexive.shared.FxArrayUtils.java
/** * Removes dupicated entries from the list. * * @param list the list//from w w w .jav a 2s . c om * @return the list without any duplicated entries */ public static long[] removeDuplicates(long[] list) { if (list == null || list.length == 0) { return new long[0]; } Hashtable<Long, Boolean> tbl = new Hashtable<Long, Boolean>(list.length); for (long ele : list) { tbl.put(ele, Boolean.FALSE); } long[] result = new long[tbl.size()]; int pos = 0; for (long element : Collections.list(tbl.keys())) { result[pos++] = element; } return result; }