List of usage examples for java.util Hashtable put
public synchronized V put(K key, V value)
From source file:Main.java
/** * Create a Hashtable by pairing the given keys with the given values. * Equivalent to python code <code>dict(zip(keys, values))</code> *//* ww w . j a v a 2 s. c om*/ public static Hashtable createHashtable(Vector keys, Vector values) { Enumeration keyEnum = keys.elements(); Enumeration valEnum = values.elements(); Hashtable result = new Hashtable(); while (keyEnum.hasMoreElements() && valEnum.hasMoreElements()) result.put(keyEnum.nextElement(), valEnum.nextElement()); return result; }
From source file:Main.java
/** * return unified reference.//from w w w . j av a2 s. com * * @param hash * the hash * @param object * the object * @return the object */ public static Object unifyReferences(final Hashtable hash, Object object) { final Object itemAtHash = hash.get(object.hashCode()); if (itemAtHash == null) { hash.put(object.hashCode(), object); } else { object = itemAtHash; } return object; }
From source file:Main.java
static Hashtable hashtableClone(Hashtable ht) { if (ht == null) return null; Hashtable htresp = new Hashtable(); Enumeration e = ht.keys();// ww w . j av a 2 s . c o m while (e.hasMoreElements()) { Object element = e.nextElement(); htresp.put(element, ht.get(element)); } return htresp; }
From source file:com.emobtech.facebook.api.graph.Friends.java
/** * <p>/*from w ww . jav a2s . com*/ * Parses the JSON content. * </p> * @param json Content; * @return Array of data. * @throws JSONException If any error occurs during parsing. */ private static Hashtable[] parseJSON(String json) throws JSONException { JSONObject jo = new JSONObject(json); JSONArray ja = jo.getJSONArray("data"); Hashtable[] fa = new Hashtable[ja.length()]; // for (int i = 0; i < fa.length; i++) { jo = (JSONObject) ja.get(i); Hashtable fo = new Hashtable(2); // fo.put("id", jo.get("id")); fo.put("name", jo.get("name")); // fa[i] = fo; } // return fa; }
From source file:Utils.java
/** * Renders a paragraph of text (line breaks ignored) to an image (created and returned). * * @param font The font to use/* www.j av a 2s .c o m*/ * @param textColor The color of the text * @param text The message * @param width The width the text should be limited to * @return An image with the text rendered into it */ public static BufferedImage renderTextToImage(Font font, Color textColor, String text, int width) { Hashtable map = new Hashtable(); map.put(TextAttribute.FONT, font); AttributedString attributedString = new AttributedString(text, map); AttributedCharacterIterator paragraph = attributedString.getIterator(); FontRenderContext frc = new FontRenderContext(null, false, false); int paragraphStart = paragraph.getBeginIndex(); int paragraphEnd = paragraph.getEndIndex(); LineBreakMeasurer lineMeasurer = new LineBreakMeasurer(paragraph, frc); float drawPosY = 0; //First time around, just determine the height while (lineMeasurer.getPosition() < paragraphEnd) { TextLayout layout = lineMeasurer.nextLayout(width); // Move it down drawPosY += layout.getAscent() + layout.getDescent() + layout.getLeading(); } BufferedImage image = createCompatibleImage(width, (int) drawPosY); Graphics2D graphics = (Graphics2D) image.getGraphics(); graphics.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); drawPosY = 0; lineMeasurer.setPosition(paragraphStart); while (lineMeasurer.getPosition() < paragraphEnd) { TextLayout layout = lineMeasurer.nextLayout(width); // Move y-coordinate by the ascent of the layout. drawPosY += layout.getAscent(); /* Compute pen x position. If the paragraph is right-to-left, we want to align the TextLayouts to the right edge of the panel. */ float drawPosX; if (layout.isLeftToRight()) { drawPosX = 0; } else { drawPosX = width - layout.getAdvance(); } // Draw the TextLayout at (drawPosX, drawPosY). layout.draw(graphics, drawPosX, drawPosY); // Move y-coordinate in preparation for next layout. drawPosY += layout.getDescent() + layout.getLeading(); } graphics.dispose(); return image; }
From source file:QRCode.java
public static String createQRCode(String arg) { int size = 125; String fileType = "png"; File myFile = null;/*from w w w . j a v a 2 s .co m*/ UUID uuid = UUID.nameUUIDFromBytes(arg.getBytes()); try { myFile = File.createTempFile("temp-file-name", ".png"); Hashtable<EncodeHintType, ErrorCorrectionLevel> hintMap = new Hashtable<EncodeHintType, ErrorCorrectionLevel>(); hintMap.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.L); QRCodeWriter qrCodeWriter = new QRCodeWriter(); BitMatrix byteMatrix = qrCodeWriter.encode(uuid.toString(), BarcodeFormat.QR_CODE, size, size, hintMap); int CrunchifyWidth = byteMatrix.getWidth(); BufferedImage image = new BufferedImage(CrunchifyWidth, CrunchifyWidth, BufferedImage.TYPE_INT_RGB); image.createGraphics(); Graphics2D graphics = (Graphics2D) image.getGraphics(); graphics.setColor(Color.WHITE); graphics.fillRect(0, 0, CrunchifyWidth, CrunchifyWidth); graphics.setColor(Color.BLACK); for (int i = 0; i < CrunchifyWidth; i++) { for (int j = 0; j < CrunchifyWidth; j++) { if (byteMatrix.get(i, j)) { graphics.fillRect(i, j, 1, 1); } } } ImageIO.write(image, fileType, myFile); //System.out.println("\n\nYou have successfully created QR Code " + myFile.getCanonicalPath()); return myFile.getCanonicalPath(); } catch (WriterException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return null; }
From source file:com.church.tools.ChartTools.java
/** * Generate pie chart.//from www.ja v a2 s.co m * * @param title the title * @param values the values * @param captions the captions * @param width the width * @param height the height * @param color the color * * @return the buffered image */ public static BufferedImage GeneratePieChart(String title, double[] values, String[] captions, int width, int height, Color color) { BufferedImage bufferedImage = null; DefaultPieDataset pieDataset = new DefaultPieDataset(); Hashtable<String, String> ht = new Hashtable<String, String>(); for (int i = 0; i < values.length; i++) ht.put(captions[i], Double.toString(values[i])); Enumeration<String> enu = ht.keys(); int i = 0; while (enu.hasMoreElements()) { String str = (String) enu.nextElement(); pieDataset.setValue(str, new Double(Double.parseDouble((String) ht.get(str)))); i++; } JFreeChart chart = ChartFactory.createPieChart(title, pieDataset, false, false, false); chart.setBackgroundPaint(color); bufferedImage = chart.createBufferedImage(width, height); return bufferedImage; }
From source file:Main.java
/** * Create a Hash table from supplied Map, this is passed to Hessian encoder * to create Hessian encoded request body. * /* w w w . j a va2 s . c om*/ * @param map The source map. * @return Hash table from supplied Map. */ protected static Hashtable<String, Object> createHashTable(Map<String, List<String>> map) { Hashtable<String, Object> hashtable = new Hashtable<String, Object>(); Set<Map.Entry<String, List<String>>> set = map.entrySet(); for (Map.Entry<String, List<String>> obj : set) { hashtable.put(obj.getKey(), new Vector<String>(obj.getValue())); } return hashtable; }
From source file:Main.java
/** * Loads an index (Hashtable) from a file. * //from w w w. j a va 2 s. com * @param root_ * The file where the index is stored in. * @return The indextable. * @exception IOException * If an internal error prevents the file from being read. */ public static Hashtable loadIndex(File root_, String name) throws IOException { File indexfile = new File(root_, name); Hashtable index = new Hashtable(); if (indexfile.exists()) { LineNumberReader in = new LineNumberReader(new FileReader(indexfile)); while (in.ready()) index.put(in.readLine(), new Long(in.readLine())); in.close(); } return index; }
From source file:Main.java
public static Hashtable<Character, Integer> createHashtable(String text) { Hashtable<Character, Integer> textHashTable = new Hashtable<Character, Integer>(); for (char c : text.toCharArray()) { if (textHashTable.get(c) != null) { Integer temp = textHashTable.get(c); textHashTable.put(c, temp + 1); } else {/* w ww . ja v a2 s . co m*/ textHashTable.put(c, new Integer(1)); } } return textHashTable; }