List of usage examples for java.util Hashtable Hashtable
public Hashtable()
From source file:com.pmarlen.model.controller.EntityJPAToPlainPojoTransformer.java
public static void copyPlainValues(Entity entity, Object plain) { final Class entityClass; entityClass = entity.getClass();//from www . j av a 2s. c o m final String entityClassName = entityClass.getName(); Hashtable<String, Object> propertiesToCopy = new Hashtable<String, Object>(); Hashtable<String, Object> propertiesM2MToCopy = new Hashtable<String, Object>(); List<String> propertiesWithNULLValueToCopy = new ArrayList<String>(); List<String> propertiesKey = new ArrayList<String>(); try { final Field[] declaredFields = entityClass.getDeclaredFields(); for (Field f : declaredFields) { logger.trace("->create: \tcopy: " + entityClassName + "." + f.getName() + " accesible ? " + (f.isAccessible())); if (!f.isAccessible()) { if (f.isAnnotationPresent(javax.persistence.Id.class)) { propertiesKey.add(f.getName()); } if (f.isAnnotationPresent(javax.persistence.Id.class) && !f.isAnnotationPresent(javax.persistence.GeneratedValue.class) && !Modifier.isStatic(f.getModifiers())) { Object valueCopyed = PropertyUtils.getProperty(entity, f.getName()); if (valueCopyed != null) { propertiesToCopy.put(f.getName(), valueCopyed); } else { propertiesWithNULLValueToCopy.add(f.getName()); } logger.trace("->create:\t\t ID elegible 2 be copied, added to copy list: " + f.getName() + " = " + valueCopyed + ", is really null?" + (valueCopyed == null)); } else if (!f.isAnnotationPresent(javax.persistence.Id.class) && !f.isAnnotationPresent(javax.persistence.OneToMany.class) && !f.isAnnotationPresent(javax.persistence.ManyToMany.class) && !Modifier.isStatic(f.getModifiers())) { Object valueCopyed = PropertyUtils.getProperty(entity, f.getName()); if (valueCopyed != null) { propertiesToCopy.put(f.getName(), valueCopyed); } else { propertiesWithNULLValueToCopy.add(f.getName()); } logger.trace("->create:\t\t elegible 2 be copied, added to copy list: " + f.getName() + " = " + valueCopyed + ", is really null?" + (valueCopyed == null)); } else if (!f.isAnnotationPresent(javax.persistence.Id.class) && f.isAnnotationPresent(javax.persistence.ManyToMany.class)) { Object valueCopyed = PropertyUtils.getProperty(entity, f.getName()); if (valueCopyed != null) { propertiesM2MToCopy.put(f.getName(), valueCopyed); } else { propertiesWithNULLValueToCopy.add(f.getName()); } logger.trace("->create:\t\t M2M elegible 2 be copied, added to copy list: " + f.getName() + " = " + valueCopyed + ", is really null?" + (valueCopyed == null)); } } } logger.trace("->create:copy values ?"); for (String p2c : propertiesToCopy.keySet()) { Object valueCopyed = propertiesToCopy.get(p2c); logger.trace("->create:\t\t copy value with SpringUtils: " + p2c + " = " + valueCopyed + ", is null?" + (valueCopyed == null)); BeanUtils.copyProperty(plain, p2c, valueCopyed); } for (String p2c : propertiesWithNULLValueToCopy) { logger.trace("->create:\t\t copy null with SpringUtils"); BeanUtils.copyProperty(plain, p2c, null); } } catch (Exception e) { logger.error("..in copy", e); } }
From source file:Main.java
/** * Applies a stylesheet to a given xml document. * /*from w w w . j av a 2s .c o m*/ * @param xmlDocument * the xml document to be transformed * @param xsltFilename * the filename of the stylesheet * @return the transformed xml document * @throws Exception */ public static Document transformDocument(Document xmlDocument, String xsltFilename) throws Exception { return transformDocument(xmlDocument, new Hashtable(), xsltFilename); }
From source file:Main.java
/** * Convert to hashtable./*from w ww .j a v a 2 s .co m*/ * * @param data the data * * @return the hashtable */ private static Hashtable convertToHashtable(Object[] data) { Hashtable h = new Hashtable(); for (int i = 0; i < data.length; i++) { h.put(i + "", data[i]); } return h; }
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 ava2 s.c o m*/ 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:edu.harvard.hul.ois.fits.tools.utils.XsltTransformMap.java
public static Hashtable getMap(String config) throws FitsConfigurationException { Hashtable mappings = new Hashtable(); XMLConfiguration conf = null;/*www . j a va2 s .co m*/ try { conf = new XMLConfiguration(config); } catch (ConfigurationException e) { throw new FitsConfigurationException("Error reading " + config + "fits.xml", e); } List fields = conf.configurationsAt("map"); for (Iterator it = fields.iterator(); it.hasNext();) { HierarchicalConfiguration sub = (HierarchicalConfiguration) it.next(); // sub contains now all data about a single field String format = sub.getString("[@format]"); String transform = sub.getString("[@transform]"); mappings.put(format, transform); } return mappings; }
From source file:QRCode.java
public static String createQRCode(String arg) { int size = 125; String fileType = "png"; File myFile = null;//from w w w . ja va 2 s . c o 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:Main.java
/** * Loads an index (Hashtable) from a file. * // www .j a v a 2 s .c o m * @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:gessi.ossecos.graph.GraphModel.java
public static void IStarJsonToGraphFile(String iStarModel, String layout, String typeGraph) throws ParseException { JSONParser parser = new JSONParser(); JSONObject jsonObject = (JSONObject) parser.parse(iStarModel); JSONArray jsonArrayNodes = (JSONArray) jsonObject.get("nodes"); JSONArray jsonArrayEdges = (JSONArray) jsonObject.get("edges"); String modelType = jsonObject.get("modelType").toString(); // System.out.println(modelType); // System.out.println(jsonArrayNodes.toJSONString()); // System.out.println(jsonArrayEdges.toJSONString()); System.out.println(jsonObject.toJSONString()); Hashtable<String, String> nodesHash = new Hashtable<String, String>(); Hashtable<String, String> boundaryHash = new Hashtable<String, String>(); Hashtable<String, Integer> countNodes = new Hashtable<String, Integer>(); ArrayList<String> boundaryItems = new ArrayList<String>(); ArrayList<String> actorItems = new ArrayList<String>(); GraphViz gv = new GraphViz(); gv.addln(gv.start_graph());/*from w w w . j a v a2 s . c om*/ String nodeType; String nodeName; String nodeBoundary; for (int i = 0; i < jsonArrayNodes.size(); i++) { jsonObject = (JSONObject) jsonArrayNodes.get(i); nodeName = jsonObject.get("name").toString().replace(" ", "_"); // .replace("(", "").replace(")", ""); nodeName = nodeName.replaceAll("[\\W]|`[_]", ""); nodeType = jsonObject.get("elemenType").toString(); nodeBoundary = jsonObject.get("boundary").toString(); // TODO: Verify type of diagram // if (!nodeType.equals("actor") & !nodeBoundary.equals("boundary")) // { if (countNodes.get(nodeName) == null) { countNodes.put(nodeName, 0); } else { countNodes.put(nodeName, countNodes.get(nodeName) + 1); nodeName += "_" + countNodes.put(nodeName, 0); } gv.addln(renderNode(nodeName, nodeType)); // } nodesHash.put(jsonObject.get("id").toString(), nodeName); boundaryHash.put(jsonObject.get("id").toString(), nodeBoundary); if (nodeType.equals("actor")) { actorItems.add(nodeName); } } String edgeType = ""; String source = ""; String target = ""; String edgeSubType = ""; int subgraphCount = 0; boolean hasCluster = false; nodeBoundary = "na"; String idSource; String idTarget; for (int i = 0; i < jsonArrayEdges.size(); i++) { jsonObject = (JSONObject) jsonArrayEdges.get(i); edgeSubType = jsonObject.get("linksubtype").toString(); edgeType = renderEdge(edgeSubType, jsonObject.get("linktype").toString()); idSource = jsonObject.get("source").toString(); idTarget = jsonObject.get("target").toString(); source = nodesHash.get(idSource); target = nodesHash.get(idTarget); if (!boundaryHash.get(idSource).toString().equals("boundary") && !boundaryHash.get(idTarget).toString().equals("boundary")) { if (!boundaryHash.get(idSource).toString().equals(nodeBoundary)) { nodeBoundary = boundaryHash.get(idSource).toString(); if (hasCluster) { gv.addln(gv.end_subgraph()); hasCluster = false; } else { hasCluster = true; } gv.addln(gv.start_subgraph(subgraphCount)); gv.addln(actorItems.get(subgraphCount++)); gv.addln("style=filled;"); gv.addln("color=lightgrey;"); } gv.addln(source + "->" + target + edgeType); } else { boundaryItems.add(source + "->" + target + edgeType); } } if (subgraphCount > 0) { gv.addln(gv.end_subgraph()); } for (String boundaryE : boundaryItems) { gv.addln(boundaryE); } gv.addln(gv.end_graph()); String type = typeGraph; // String type = "dot"; // String type = "fig"; // open with xfig // String type = "pdf"; // String type = "ps"; // String type = "svg"; // open with inkscape // String type = "png"; // String type = "plain"; String repesentationType = layout; // String repesentationType= "neato"; // String repesentationType= "fdp"; // String repesentationType= "sfdp"; // String repesentationType= "twopi"; // String repesentationType= "circo"; // //File out = new File("/tmp/out"+gv.getImageDpi()+"."+ type); // // Linux File out = new File("Examples/out." + type); // Windows gv.writeGraphToFile(gv.getGraph(gv.getDotSource(), type, repesentationType), out); }
From source file:com.icesoft.applications.faces.auctionMonitor.AddAuctionItem.java
public static Hashtable parseFile(Reader reader) { BufferedReader in = new BufferedReader(reader); Hashtable params = new Hashtable(); String line;/*from w w w .ja v a 2 s. c o m*/ try { String name; String value; while (null != (line = in.readLine())) { int index = line.indexOf(' '); name = line.substring(0, index); value = line.substring(index + 1); params.put(name, value); } } catch (IOException e) { if (log.isErrorEnabled()) { log.error("Error while parsing an auction item file into the hashtable"); } } return params; }
From source file:CutPasteSample.java
private static Action findAction(Action actions[], String key) { Hashtable<Object, Action> commands = new Hashtable<Object, Action>(); for (int i = 0; i < actions.length; i++) { Action action = actions[i]; commands.put(action.getValue(Action.NAME), action); }/* w w w . j a v a 2 s .c o m*/ return commands.get(key); }