List of usage examples for java.lang Float valueOf
@HotSpotIntrinsicCandidate public static Float valueOf(float f)
From source file:com.fengduo.spark.commons.file.excel.ImportExcel.java
/** * ??/*from ww w . jav a2s. c o m*/ * * @param cls * @param groups */ public <E> List<E> getDataList(Class<E> cls, int... groups) throws InstantiationException, IllegalAccessException { List<Object[]> annotationList = Lists.newArrayList(); // Get annotation field Field[] fs = cls.getDeclaredFields(); for (Field f : fs) { ExcelField ef = f.getAnnotation(ExcelField.class); if (ef != null && (ef.type() == 0 || ef.type() == 2)) { if (groups != null && groups.length > 0) { boolean inGroup = false; for (int g : groups) { if (inGroup) { break; } for (int efg : ef.groups()) { if (g == efg) { inGroup = true; annotationList.add(new Object[] { ef, f }); break; } } } } else { annotationList.add(new Object[] { ef, f }); } } } // Get annotation method Method[] ms = cls.getDeclaredMethods(); for (Method m : ms) { ExcelField ef = m.getAnnotation(ExcelField.class); if (ef != null && (ef.type() == 0 || ef.type() == 2)) { if (groups != null && groups.length > 0) { boolean inGroup = false; for (int g : groups) { if (inGroup) { break; } for (int efg : ef.groups()) { if (g == efg) { inGroup = true; annotationList.add(new Object[] { ef, m }); break; } } } } else { annotationList.add(new Object[] { ef, m }); } } } // Field sorting Collections.sort(annotationList, new Comparator<Object[]>() { public int compare(Object[] o1, Object[] o2) { return new Integer(((ExcelField) o1[0]).sort()).compareTo(new Integer(((ExcelField) o2[0]).sort())); }; }); // log.debug("Import column count:"+annotationList.size()); // Get excel data List<E> dataList = Lists.newArrayList(); for (int i = this.getDataRowNum(); i < this.getLastDataRowNum(); i++) { E e = (E) cls.newInstance(); int column = 0; Row row = this.getRow(i); StringBuilder sb = new StringBuilder(); for (Object[] os : annotationList) { Object val = this.getCellValue(row, column++); if (val != null) { ExcelField ef = (ExcelField) os[0]; // If is dict type, get dict value // if (StringUtils.isNotBlank(ef.dictType())) { // val = DictUtils.getDictValue(val.toString(), ef.dictType(), ""); // log.debug("Dictionary type value: ["+i+","+colunm+"] " + val); // } // Get param type and type cast Class<?> valType = Class.class; if (os[1] instanceof Field) { valType = ((Field) os[1]).getType(); } else if (os[1] instanceof Method) { Method method = ((Method) os[1]); if ("get".equals(method.getName().substring(0, 3))) { valType = method.getReturnType(); } else if ("set".equals(method.getName().substring(0, 3))) { valType = ((Method) os[1]).getParameterTypes()[0]; } } // log.debug("Import value type: ["+i+","+column+"] " + valType); try { if (valType == String.class) { String s = String.valueOf(val.toString()); if (StringUtils.endsWith(s, ".0")) { val = StringUtils.substringBefore(s, ".0"); } else { val = String.valueOf(val.toString()); } } else if (valType == Integer.class) { val = Double.valueOf(val.toString()).intValue(); } else if (valType == Long.class) { val = Double.valueOf(val.toString()).longValue(); } else if (valType == Double.class) { val = Double.valueOf(val.toString()); } else if (valType == Float.class) { val = Float.valueOf(val.toString()); } else if (valType == Date.class) { val = DateUtil.getJavaDate((Double) val); } else { if (ef.fieldType() != Class.class) { val = ef.fieldType().getMethod("getValue", String.class).invoke(null, val.toString()); } else { val = Class .forName(this.getClass().getName().replaceAll( this.getClass().getSimpleName(), "fieldtype." + valType.getSimpleName() + "Type")) .getMethod("getValue", String.class).invoke(null, val.toString()); } } } catch (Exception ex) { log.info("Get cell value [" + i + "," + column + "] error: " + ex.toString()); val = null; } // set entity value if (os[1] instanceof Field) { Reflections.invokeSetter(e, ((Field) os[1]).getName(), val); } else if (os[1] instanceof Method) { String mthodName = ((Method) os[1]).getName(); if ("get".equals(mthodName.substring(0, 3))) { mthodName = "set" + StringUtils.substringAfter(mthodName, "get"); } Reflections.invokeMethod(e, mthodName, new Class[] { valType }, new Object[] { val }); } } sb.append(val + ", "); } dataList.add(e); log.debug("Read success: [" + i + "] " + sb.toString()); } return dataList; }
From source file:com.workday.autoparse.xml.demo.XmlParserTest.java
@Test public void testMissingAttributesAreNotSet() throws ParseException, UnexpectedChildException, UnknownElementException { XmlStreamParser parser = XmlStreamParserFactory.newXmlStreamParser(); InputStream in = getInputStreamOf("missing-attributes.xml"); DemoModel model = (DemoModel) parser.parseStream(in); assertTrue(model.myBoxedBoolean);/*from ww w .j ava2 s. c o m*/ assertTrue(model.myPrimitiveBoolean); assertEquals(BigDecimal.ONE, model.myBigDecimal); assertEquals(BigInteger.TEN, model.myBigInteger); assertEquals(-1, model.myPrimitiveByte); assertEquals(Byte.valueOf((byte) -1), model.myBoxedByte); assertEquals('a', model.myPrimitiveChar); assertEquals(Character.valueOf('a'), model.myBoxedChar); assertEquals(-1.0, model.myPrimitiveDouble, DOUBLE_E); assertEquals(Double.valueOf(-1.0), model.myBoxedDouble); assertEquals(-1f, model.myPrimitiveFloat, FLOAT_E); assertEquals(Float.valueOf(-1f), model.myBoxedFloat); assertEquals(-1, model.myPrimitiveInt); assertEquals(Integer.valueOf(-1), model.myBoxedInt); assertEquals(-1, model.myPrimitiveLong); assertEquals(Long.valueOf(-1), model.myBoxedLong); assertEquals(-1, model.myPrimitiveShort); assertEquals(Short.valueOf((short) -1), model.myBoxedShort); assertEquals("default", model.myString); assertEquals("default", model.myTextContent); }
From source file:com.wavemaker.commons.util.TypeConversionUtils.java
public static Object fromString(Class<?> type, String s, boolean isList) { if (isList || !isPrimitiveOrWrapper(type)) { if (s == null) { return null; }/*from w ww. ja v a 2s. c o m*/ ObjectLiteralParser p = new ObjectLiteralParser(s, type); Object o = p.parse(); return o; } if (s == null) { return null; } else if (type == AtomicInteger.class) { return null; } else if (type == AtomicLong.class) { return null; } else if (type == BigDecimal.class) { return new BigDecimal(s); } else if (type == BigInteger.class) { return new BigDecimal(s); } else if (type == Boolean.class || type == boolean.class) { return Boolean.valueOf(s); } else if (type == Byte.class || type == byte.class) { return Byte.valueOf(s); } else if (type == Date.class) { if (StringUtils.isNumber(s)) { return new Date(Long.parseLong(s)); } else { throw new IllegalArgumentException("Unable to convert " + s + " to " + Date.class.getName()); } } else if (type == java.sql.Date.class) { return WMDateDeSerializer.getDate(s); } else if (type == Time.class) { return WMDateDeSerializer.getDate(s); } else if (type == Timestamp.class) { if (StringUtils.isNumber(s)) { return new Timestamp(Long.valueOf(s)); } else { throw new IllegalArgumentException("Unable to convert " + s + " to " + Timestamp.class.getName()); } } else if (type == LocalDateTime.class) { return WMLocalDateTimeDeSerializer.getLocalDateTime(s); } else if (type == Double.class || type == double.class) { return Double.valueOf(s); } else if (type == Float.class || type == float.class) { return Float.valueOf(s); } else if (type == Integer.class || type == int.class) { return Integer.valueOf(s); } else if (type == Long.class || type == long.class) { return Long.valueOf(s); } else if (type == Short.class || type == short.class) { return Short.valueOf(s); } else if (type == String.class || type == StringBuffer.class) { return s; } else if (type == Character.class || type == char.class) { return Character.valueOf(s.charAt(0)); } else { throw new AssertionError("Unable to convert \"" + s + "\" to " + type + " - unknown type: " + type); } }
From source file:Pathway2Rdf.java
public static void addPathway2Rdf(String wpIdentifier, String wpRevision, String gpml) throws DOMException, XPathExpressionException, ServiceException, ConverterException, ParserConfigurationException, SAXException, IOException, ParseException, NullPointerException { Model model = ModelFactory.createDefaultModel(); // Declare the Prefixes // Model wikipathways level into RDF Resource wikipathwaysResource = model.createResource(WpNamespaces.nsWikipathways); Property xCoordinate = model.createProperty(WpNamespaces.nsWikipathways + "GPML/xCoordinate"); Property yCoordinate = model.createProperty(WpNamespaces.nsWikipathways + "GPML/yCoordinate"); Property color = model.createProperty(WpNamespaces.nsWikipathways + "GPML/color"); Property width = model.createProperty(WpNamespaces.nsWikipathways + "GPML/width"); Property height = model.createProperty(WpNamespaces.nsWikipathways + "GPML/height"); Resource wikiPathwaysPaperResource = model.createResource("http://www.ncbi.nlm.nih.gov/pubmed/18651794"); wikipathwaysResource.addProperty(DCTerms.bibliographicCitation, wikiPathwaysPaperResource); Resource wikiPathwaysSparqlEndpointResource = model .createResource("http://semantics.bigcat.unimaas.nl:8000/sparql"); wikipathwaysResource.addProperty(Void.sparqlEndpoint, wikiPathwaysSparqlEndpointResource); wikipathwaysResource.addProperty(RDF.type, Void.Dataset); String DefinitionURI = WpNamespaces.nsWikipathways + "Definition/"; Resource wikipathwaysGroupDefinitionResource = model.createResource(DefinitionURI + "Group/"); // State that GeneProduct can either be a Protein or DNA RDFNode[] geneProductelems = new RDFNode[] { Biopax_level3.Dna, Biopax_level3.Protein }; RDFList geneProductRDFNode = model.createList(geneProductelems); String pathwayURI = WpNamespaces.nsWikipathways + "Pathway/" + wpIdentifier + "/"; //System.out.println(); //System.out.print(wpIdentifier); Resource abstractPathwayResource = model.createResource(pathwayURI); //System.out.print(wpRevision); String pathwayResourceURI = pathwayURI + wpRevision + "/"; Resource centralPathwayResource = model.createResource(pathwayResourceURI); abstractPathwayResource.addProperty(DCTerms.hasVersion, centralPathwayResource); Resource pathwayResource = model.createResource(pathwayResourceURI); // A Pathway in Wikipathways is identified by its WP identifier and // its revision number; Resource pathwayIdentifierResource = model.createResource( WpNamespaces.nsIdentifiers + "/WikiPathways/" + wpIdentifier + "/" + wpRevision + "/"); pathwayIdentifierResource.addProperty(RDFS.label, wpIdentifier); pathwayResource.addProperty(DC.identifier, pathwayIdentifierResource); pathwayResource.addProperty(RDFS.label, wpIdentifier); // PARSE GPML if (!gpml.startsWith("{{deleted|") && isValidXML(gpml, wpIdentifier, wpRevision)) { DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder(); StringReader reader = new StringReader(gpml); InputSource inputSource = new InputSource(reader); Document doc = docBuilder.parse(inputSource); reader.close();// w w w. ja v a 2 s. c o m doc.getDocumentElement().normalize(); try { // Get the Pathway Nodes XPath xPath = XPathFactory.newInstance().newXPath(); Node pathwayLicense = ((Node) xPath.evaluate("/Pathway/@License", doc, XPathConstants.NODE)); Node pathwayName = ((Node) xPath.evaluate("/Pathway/@Name", doc, XPathConstants.NODE)); Node pathwayOrganism = ((Node) xPath.evaluate("/Pathway/@Organism", doc, XPathConstants.NODE)); // Map the organism to DbPedia if (pathwayOrganism != null) { Resource dbPediaSpeciesResource = model.createResource( "http://dbpedia.org/page/" + pathwayOrganism.getNodeValue().replace(" ", "_")); wikipathwaysResource.addProperty(DC.coverage, dbPediaSpeciesResource); } // Add pathway level details to the RDF model if (pathwayName != null) pathwayResource.addProperty(RDFS.label, pathwayName.getNodeValue()); if (pathwayIdentifierResource != null) pathwayResource.addProperty(DC.identifier, pathwayIdentifierResource); if (pathwayLicense != null) pathwayResource.addProperty(DCTerms.license, pathwayLicense.getNodeValue()); pathwayResource.addProperty(RDF.type, Biopax_level3.Pathway); pathwayResource.addProperty(DCTerms.isPartOf, wikipathwaysResource); // Get the Group References by calling the getGroupIds from // the // wikipathways webservices NodeList groupIdsNL = doc.getElementsByTagName("Group"); Set<String> groupIdsSet = new TreeSet<String>(); for (int t = 0; t < groupIdsNL.getLength(); t++) { groupIdsSet.add(groupIdsNL.item(t).getAttributes().getNamedItem("GroupId").getTextContent()); // System.out.println(groupIdsNL.item(t).getAttributes() // .getNamedItem("GroupId").getTextContent()); } for (String groupRef : groupIdsSet) { Resource groupResource = model.createResource(pathwayResourceURI + "Group/" + groupRef); groupResource.addProperty(RDF.type, wikipathwaysGroupDefinitionResource); } // Add pathwayElements to the RDF model NodeList dataNodeNL = doc.getElementsByTagName("DataNode"); // for (PathwayElement pwElm : pathway.getDataObjects()) { for (int dnlint = 0; dnlint < dataNodeNL.getLength(); dnlint++) { // Only take elements with type DATANODE (genes, // proteins, // metabolites) String datanodeType = null; if (dataNodeNL.item(dnlint).getAttributes().getNamedItem("Type") != null) { datanodeType = dataNodeNL.item(dnlint).getAttributes().getNamedItem("Type") .getTextContent(); } String datanodeTextLabel = dataNodeNL.item(dnlint).getAttributes().getNamedItem("TextLabel") .getTextContent(); String datanodeGraphId = dataNodeNL.item(dnlint).getAttributes().getNamedItem("GraphId") .getTextContent(); String datanodeGroupRef = null; if (dataNodeNL.item(dnlint).getAttributes().getNamedItem("GroupRef") != null) { datanodeGroupRef = dataNodeNL.item(dnlint).getAttributes().getNamedItem("GroupRef") .getTextContent(); } NodeList datanodeChilds = dataNodeNL.item(dnlint).getChildNodes(); // Get ChildNodes Xref, Graphics String datanodeXrefId = null; String datanodeXrefDatabase = null; String dataNodeGraphicsColor = null; Float dataNodeGraphicsCenterX = null; Float dataNodeGraphicsCenterY = null; Float dataNodeGraphicsWidth = null; Float dataNodeGraphicsHeight = null; for (int dnchildint = 0; dnchildint < datanodeChilds.getLength(); dnchildint++) { // Xref if (datanodeChilds.item(dnchildint).getNodeName().equals("Xref")) { datanodeXrefId = datanodeChilds.item(dnchildint).getAttributes().getNamedItem("ID") .getTextContent(); datanodeXrefDatabase = datanodeChilds.item(dnchildint).getAttributes() .getNamedItem("Database").getTextContent(); } //Graphics if (datanodeChilds.item(dnchildint).getNodeName().equals("Graphics")) { if (datanodeChilds.item(dnchildint).getAttributes().getNamedItem("Color") != null) { dataNodeGraphicsColor = datanodeChilds.item(dnchildint).getAttributes() .getNamedItem("Color").getTextContent(); } dataNodeGraphicsCenterX = Float.valueOf(datanodeChilds.item(dnchildint).getAttributes() .getNamedItem("CenterX").getTextContent()); dataNodeGraphicsCenterY = Float.valueOf(datanodeChilds.item(dnchildint).getAttributes() .getNamedItem("CenterY").getTextContent()); dataNodeGraphicsWidth = Float.valueOf(datanodeChilds.item(dnchildint).getAttributes() .getNamedItem("Width").getTextContent()); dataNodeGraphicsHeight = Float.valueOf(datanodeChilds.item(dnchildint).getAttributes() .getNamedItem("Height").getTextContent()); } } // if (pwElm.getObjectType() == ObjectType.DATANODE) { Resource pathwayEntity = model .createResource(pathwayResourceURI + "Datanode/" + datanodeGraphId); pathwayEntity.addProperty(DCTerms.isPartOf, pathwayResource); pathwayEntity.addProperty(RDF.type, Spatial.Feature); pathwayEntity.addLiteral(xCoordinate, dataNodeGraphicsCenterX); pathwayEntity.addLiteral(yCoordinate, dataNodeGraphicsCenterX); if (dataNodeGraphicsColor != null) { pathwayEntity.addLiteral(color, dataNodeGraphicsColor); } pathwayEntity.addLiteral(width, dataNodeGraphicsWidth); pathwayEntity.addLiteral(height, dataNodeGraphicsHeight); pathwayEntity.addProperty(RDFS.label, datanodeTextLabel); // System.out.println(pwElm.getDataNodeType().toString()); if (datanodeType != null) { if (datanodeType.equals("Metabolite")) { pathwayEntity.addProperty(RDF.type, Biopax_level3.SmallMolecule); } else if (datanodeType.equals("Gene")) { pathwayEntity.addProperty(RDF.type, Biopax_level3.Dna); } else if (datanodeType.equals("Protein")) { pathwayEntity.addProperty(RDF.type, Biopax_level3.Protein); } else if (datanodeType.equals("GeneProduct")) { pathwayEntity.addProperty(RDF.type, OWL.equivalentClass); // See // for // details: // http://answers.semanticweb.com/questions/12177/how-do-you-map-an-object-to-be-either-a-or-b-but-nothing-else-in-rdf pathwayEntity.addProperty(OWL.unionOf, geneProductRDFNode); } else if (datanodeType.equals("Pathway")) { Resource interactingPathwayResource = model .createResource(pathwayResourceURI + "Interaction/" + datanodeGraphId); interactingPathwayResource.addProperty(RDF.type, Biopax_level3.Interaction); interactingPathwayResource.addProperty(RDF.subject, pathwayResource); interactingPathwayResource.addProperty(RDF.object, model .createResource(WpNamespaces.nsWikipathways + "Pathway/" + datanodeXrefId)); } else if (datanodeType.equals("Pathway")) { pathwayEntity.addProperty(RDF.type, Biopax_level3.Pathway); } else if (datanodeType.equals("Complex")) { pathwayEntity.addProperty(RDF.type, Biopax_level3.Complex); } else { pathwayEntity.addProperty(RDF.type, Biopax_level3.Entity); } } if (datanodeXrefDatabase != null) { String xRefDataSource = datanodeXrefDatabase.toString().replace(" ", "_"); Resource pwElmIdentifierResource = model.createResource(WpNamespaces.nsIdentifiers + "WikiPathways/" + xRefDataSource + "/" + datanodeXrefId); pwElmIdentifierResource.addProperty(RDFS.label, datanodeXrefId); Resource pwElmSourceResource = model .createResource(WpNamespaces.nsIdentifiers + "WikiPathways/" + xRefDataSource); pwElmSourceResource.addProperty(RDFS.label, xRefDataSource); pathwayEntity.addProperty(DC.identifier, pwElmIdentifierResource); pathwayEntity.addProperty(DC.source, pwElmSourceResource); } if (datanodeGroupRef != null) { // Element is part of a // group pathwayEntity.addProperty(DCTerms.isPartOf, model.getResource(pathwayResourceURI + "Group/" + datanodeGroupRef)); } } NodeList lineNL = doc.getElementsByTagName("Line"); for (int llint = 0; llint < lineNL.getLength(); llint++) { // Only take elements with type DATANODE (genes, // proteins, // metabolites) if (lineNL.item(llint).getAttributes().getNamedItem("GraphId") != null) { String lineGraphId = lineNL.item(llint).getAttributes().getNamedItem("GraphId") .getTextContent(); // Xref Element LineGraphElement = (Element) lineNL.item(llint); NodeList pointGraphrefs = ((NodeList) xPath.evaluate("//Point/@GraphRef", LineGraphElement, XPathConstants.NODESET)); String leftLineGraphRefs = null; String rightLineGraphRefs = null; if ((pointGraphrefs.item(0) != null) && ((pointGraphrefs.item(1) != null))) { leftLineGraphRefs = pointGraphrefs.item(0).getTextContent(); rightLineGraphRefs = pointGraphrefs.item(1).getTextContent(); } if ((leftLineGraphRefs != null) && (rightLineGraphRefs != null)) { String startGroupOrDatanode; String endGroupOrDatanode; // if // (pwElm.getObjectType().equals(ObjectType.LINE)) { Resource pathwayLine = model .createResource(pathwayResourceURI + "Interaction/" + lineGraphId); pathwayLine.addProperty(RDF.type, Biopax_level3.Interaction); if (groupIdsSet.contains(leftLineGraphRefs)) { startGroupOrDatanode = "Group/"; } else { startGroupOrDatanode = "Datanode/"; } if (groupIdsSet.contains(rightLineGraphRefs)) { endGroupOrDatanode = "Group/"; } else { endGroupOrDatanode = "Datanode/"; } pathwayLine.addProperty(RDF.predicate, model .getResource(pathwayResourceURI + startGroupOrDatanode + leftLineGraphRefs)); pathwayLine.addProperty(RDF.predicate, model .getResource(pathwayResourceURI + endGroupOrDatanode + rightLineGraphRefs)); } } } // TODO Seek a pathway with a state /* * if (pwElm.getObjectType() == ObjectType.STATE) { Resource * pathwayEntity = model .createResource(pathwayResourceURI + * "State/" + pwElm.getGraphId()); pathwayEntity * .addProperty(DCTerms.isPartOf, pathwayResource); * pathwayEntity.addProperty(RDFS.label, pwElm.getTextLabel()); * } } */ // Get the Biopax References NodeList bpRef = doc.getElementsByTagName("BiopaxRef"); HashMap<String, String> bpRefmap = new HashMap<String, String>(); if (bpRef != null && bpRef.getLength() > 0) { for (int j = 0; j < bpRef.getLength(); j++) { if (bpRef.item(j).getParentNode().getNodeName().equals("DataNode")) { bpRefmap.put(bpRef.item(j).getTextContent(), pathwayResourceURI + "Datanode/" + bpRef.item(j).getParentNode().getAttributes() .getNamedItem("GraphId").getNodeValue()); } if (bpRef.item(j).getParentNode().getNodeName().equals("Pathway")) { bpRefmap.put(bpRef.item(j).getTextContent(), pathwayResourceURI); } if (bpRef.item(j).getParentNode().getNodeName().equals("Line")) { // TODO make sure every entity has a graphId if (bpRef.item(j).getParentNode().getAttributes().getNamedItem("GraphId") != null) bpRefmap.put(bpRef.item(j).getTextContent(), pathwayResourceURI + "Line/" + bpRef.item(j).getParentNode().getAttributes() .getNamedItem("GraphId").getNodeValue()); } if (bpRef.item(j).getParentNode().getNodeName().equals("State")) { bpRefmap.put(bpRef.item(j).getTextContent(), pathwayResourceURI + "State/" + bpRef.item(j).getParentNode().getAttributes() .getNamedItem("GraphId").getNodeValue()); } if (bpRef.item(j).getParentNode().getNodeName().equals("Group")) { bpRefmap.put(bpRef.item(j).getTextContent(), pathwayResourceURI + "Group/" + bpRef.item(j).getParentNode().getAttributes() .getNamedItem("GroupId").getNodeValue()); } } } NodeList cv = doc.getElementsByTagName("bp:openControlledVocabulary"); if (cv != null && cv.getLength() > 0) { for (int a = 0; a < cv.getLength(); a++) { NodeList cvList = cv.item(a).getChildNodes(); String OntologyName = cvList.item(2).getTextContent(); String OntologyId = cvList.item(1).getTextContent(); if (OntologyName.equals("Pathway Ontology")) { Resource ontologyResource = model .createResource("http://purl.org/obo/owl/PW#" + OntologyId.replace(":", "_")); pathwayResource.addProperty(RDF.type, ontologyResource); } System.out.println(OntologyName + ": " + OntologyId); } } NodeList nl = doc.getElementsByTagName("bp:PublicationXRef"); System.out.println("test" + nl.getLength()); if (nl != null && nl.getLength() > 0) { System.out.println("test"); for (int k = 0; k < nl.getLength(); k++) { NodeList refId = nl.item(k).getChildNodes(); if (refId.getLength() > 3) { if (refId.item(3).getTextContent().equals("PubMed") && (refId.item(1).getTextContent() != null)) { Resource pubmedEntity = model.createResource( "http://www.ncbi.nlm.nih.gov/pubmed/" + refId.item(1).getTextContent()); pubmedEntity.addProperty(RDF.type, Biopax_level3.Evidence); pubmedEntity.addProperty(DCTerms.identifier, refId.item(1).getTextContent()); if (bpRefmap.get(nl.item(k).getAttributes().item(0).getNodeValue()) != null) { Resource tempItem = model.getResource(bpRefmap .get(nl.item(k).getAttributes().item(0).getNodeValue()).toString()); tempItem.addProperty(DCTerms.bibliographicCitation, pubmedEntity); } } } else { System.out.println("PROBLEM with: " + wpIdentifier); } } } nl = doc.getElementsByTagName("bp:PublicationXref"); System.out.println("test" + nl.getLength()); if (nl != null && nl.getLength() > 0) { System.out.println("test"); for (int k = 0; k < nl.getLength(); k++) { NodeList refId = nl.item(k).getChildNodes(); if (refId.getLength() > 3) { if (refId.item(3).getTextContent().equals("PubMed") && (refId.item(1).getTextContent() != null)) { Resource pubmedEntity = model.createResource( "http://www.ncbi.nlm.nih.gov/pubmed/" + refId.item(1).getTextContent()); pubmedEntity.addProperty(RDF.type, Biopax_level3.Evidence); pubmedEntity.addProperty(DCTerms.identifier, refId.item(1).getTextContent()); if (bpRefmap.get(nl.item(k).getAttributes().item(0).getNodeValue()) != null) { Resource tempItem = model.getResource(bpRefmap .get(nl.item(k).getAttributes().item(0).getNodeValue()).toString()); tempItem.addProperty(DCTerms.bibliographicCitation, pubmedEntity); } } } else { System.out.println("PROBLEM with: " + wpIdentifier); } } } nl = doc.getElementsByTagName("bp:publicationXref"); System.out.println("test" + nl.getLength()); if (nl != null && nl.getLength() > 0) { System.out.println("test"); for (int k = 0; k < nl.getLength(); k++) { NodeList refId = nl.item(k).getChildNodes(); if (refId.getLength() > 3) { if (refId.item(3).getTextContent().equals("PubMed") && (refId.item(1).getTextContent() != null)) { Resource pubmedEntity = model.createResource( "http://www.ncbi.nlm.nih.gov/pubmed/" + refId.item(1).getTextContent()); pubmedEntity.addProperty(RDF.type, Biopax_level3.Evidence); pubmedEntity.addProperty(DCTerms.identifier, refId.item(1).getTextContent()); if (bpRefmap.get(nl.item(k).getAttributes().item(0).getNodeValue()) != null) { Resource tempItem = model.getResource(bpRefmap .get(nl.item(k).getAttributes().item(0).getNodeValue()).toString()); tempItem.addProperty(DCTerms.bibliographicCitation, pubmedEntity); } } } else { System.out.println("PROBLEM with: " + wpIdentifier); } } } } catch (Exception e) { e.printStackTrace(); } } FileOutputStream fout; fout = new FileOutputStream("/tmp/WpRDF/" + wpIdentifier + "_" + wpRevision + ".nt"); model.write(fout, "N-TRIPLE"); }
From source file:ch.cyberduck.ui.cocoa.controller.TransferController.java
@Action public void bandwidthPopupChanged(NSMenuItem sender) { final NSIndexSet selected = transferTable.selectedRowIndexes(); final float bandwidth = Float.valueOf(sender.representedObject()); for (NSUInteger index = selected.firstIndex(); !index.equals(NSIndexSet.NSNotFound); index = selected .indexGreaterThanIndex(index)) { final Transfer transfer = collection.get(index.intValue()); transfer.setBandwidth(bandwidth); if (transfer.isRunning()) { // Find matching background task for (BackgroundAction action : registry.toArray(new BackgroundAction[registry.size()])) { if (action instanceof TransferBackgroundAction) { final TransferBackgroundAction t = (TransferBackgroundAction) action; if (t.getTransfer().equals(transfer)) { final TransferSpeedometer meter = t.getMeter(); meter.reset();/*from w ww. j av a 2 s . co m*/ } } } } } }
From source file:org.hellojavaer.testcase.generator.TestCaseGenerator.java
@SuppressWarnings({ "unchecked", "rawtypes" }) private static <T> T produceBean(Class<T> clazz, ControlParam countrolParam, Stack<Class> parseClassList) { try {/*from w w w . j av a 2s . com*/ T item = clazz.newInstance(); for (PropertyDescriptor pd : BeanUtils.getPropertyDescriptors(clazz)) { Method writeMethod = pd.getWriteMethod(); if (writeMethod == null || pd.getReadMethod() == null || // countrolParam.getExcludeFieldList() != null && countrolParam.getExcludeFieldList().contains(pd.getName())// ) {// continue; } Class fieldClazz = pd.getPropertyType(); Long numIndex = countrolParam.getNumIndex(); // int enumIndex = countrolParam.getEnumIndex(); Random random = countrolParam.getRandom(); long strIndex = countrolParam.getStrIndex(); int charIndex = countrolParam.getCharIndex(); Calendar time = countrolParam.getTime(); if (TypeUtil.isBaseType(fieldClazz)) { if (TypeUtil.isNumberType(fieldClazz)) { if (fieldClazz == Byte.class) { writeMethod.invoke(item, Byte.valueOf((byte) (numIndex & 0x7F))); } else if (fieldClazz == Short.class) { writeMethod.invoke(item, Short.valueOf((short) (numIndex & 0x7FFF))); } else if (fieldClazz == Integer.class) { writeMethod.invoke(item, Integer.valueOf((int) (numIndex & 0x7FFFFFFF))); } else if (fieldClazz == Long.class) { writeMethod.invoke(item, Long.valueOf((long) numIndex)); } else if (fieldClazz == Float.class) { writeMethod.invoke(item, Float.valueOf((float) numIndex)); } else if (fieldClazz == Double.class) { writeMethod.invoke(item, Double.valueOf((double) numIndex)); } else if (fieldClazz == byte.class) {// writeMethod.invoke(item, (byte) (numIndex & 0x7F)); } else if (fieldClazz == short.class) { writeMethod.invoke(item, (short) (numIndex & 0x7FFF)); } else if (fieldClazz == int.class) { writeMethod.invoke(item, (int) (numIndex & 0x7FFFFFFF)); } else if (fieldClazz == long.class) { writeMethod.invoke(item, (long) numIndex); } else if (fieldClazz == float.class) { writeMethod.invoke(item, (float) numIndex); } else if (fieldClazz == double.class) { writeMethod.invoke(item, (double) numIndex); } numIndex++; if (numIndex < 0) { numIndex &= 0x7FFFFFFFFFFFFFFFL; } countrolParam.setNumIndex(numIndex); } else if (fieldClazz == boolean.class) { writeMethod.invoke(item, random.nextBoolean()); } else if (fieldClazz == Boolean.class) { writeMethod.invoke(item, Boolean.valueOf(random.nextBoolean())); } else if (fieldClazz == char.class) { writeMethod.invoke(item, CHAR_RANGE[charIndex]); charIndex++; if (charIndex >= CHAR_RANGE.length) { charIndex = 0; } countrolParam.setCharIndex(charIndex); } else if (fieldClazz == Character.class) { writeMethod.invoke(item, Character.valueOf(CHAR_RANGE[charIndex])); charIndex++; if (charIndex >= CHAR_RANGE.length) { charIndex = 0; } countrolParam.setCharIndex(charIndex); } else if (fieldClazz == String.class) { if (countrolParam.getUniqueFieldList() != null && countrolParam.getUniqueFieldList().contains(pd.getName())) { StringBuilder sb = new StringBuilder(); convertNum(strIndex, STRING_RANGE, countrolParam.getRandom(), sb); writeMethod.invoke(item, sb.toString()); strIndex += countrolParam.getStrStep(); if (strIndex < 0) { strIndex &= 0x7FFFFFFFFFFFFFFFL; } countrolParam.setStrIndex(strIndex); } else { writeMethod.invoke(item, String.valueOf(CHAR_RANGE[charIndex])); charIndex++; if (charIndex >= CHAR_RANGE.length) { charIndex = 0; } countrolParam.setCharIndex(charIndex); } } else if (fieldClazz == Date.class) { writeMethod.invoke(item, time.getTime()); time.add(Calendar.DAY_OF_YEAR, 1); } else if (fieldClazz.isEnum()) { int index = random.nextInt(fieldClazz.getEnumConstants().length); writeMethod.invoke(item, fieldClazz.getEnumConstants()[index]); } else { // throw new RuntimeException("out of countrol Class " + fieldClazz.getName()); } } else { parseClassList.push(fieldClazz); // TODO ? Set<Class> set = new HashSet<Class>(parseClassList); if (parseClassList.size() - set.size() <= countrolParam.getRecursiveCycleLimit()) { Object bean = produceBean(fieldClazz, countrolParam, parseClassList); writeMethod.invoke(item, bean); } parseClassList.pop(); } } return item; } catch (Exception e) { throw new RuntimeException(e); } }
From source file:com.ecofactor.qa.automation.consumerapi.ThermostatRuntimeSavings_Test.java
/** * APPS-203 Monthly runtime hours actual not exceeds max month hours. * @param username the username/*from www . j av a 2 s . co m*/ * @param password the password * @param thermostatId the thermostat id */ @Test(groups = { Groups.SANITY1, Groups.BROWSER }, dataProvider = HVAC_SYSTEMS, dataProviderClass = ApiDataProvider.class, priority = 7) public void monthlyRuntimeHoursActualNotExceedsMaxMonthHours(final String username, final String password, final String thermostatId) { final Response response = consumerApiURL.getThermostatRuntimeSavings(thermostatId, securityCookie); setLogString("Response :'" + response + "'", true); final String content = response.readEntity(String.class); setLogString(JSON_RESPONSE, true, CustomLogLevel.MEDIUM); setLogString(content, true, CustomLogLevel.MEDIUM); final JSONObject jsonObject = JsonUtil.parseObject(content); final JSONObject mesgs = (JSONObject) jsonObject.get(MONTHS); final Object[] runtimes = mesgs.values().toArray(); for (final Object runtime : runtimes) { setLogString("Verify that runtime_hours_actual cannot exceed 31 (days) * 24 ( hours)", true); final JSONObject json = (JSONObject) runtime; final JSONObject jsonRuntimeCool = (JSONObject) json.get(COOL); final JSONObject jsonRuntimeHeat = (JSONObject) json.get(HEAT); final float coolRuntimeHrsActual = Float.valueOf(jsonRuntimeCool.get(RUNTIME_HRS_ACTUAL).toString()); final float heatRuntimeHrsActual = Float.valueOf(jsonRuntimeHeat.get(RUNTIME_HRS_ACTUAL).toString()); setLogString("coolRuntimeHrsActual: " + coolRuntimeHrsActual, true); Assert.assertTrue(coolRuntimeHrsActual < 744, "Cool run time hours actual is greater than maximum month hours"); setLogString("heatRuntimeHrsActual: " + heatRuntimeHrsActual, true); Assert.assertTrue(heatRuntimeHrsActual < 744, "Heat run time hours actual is greater than maximum month hours"); } }
From source file:cn.afterturn.easypoi.excel.imports.CellValueService.java
/** * ??//from w w w . j ava2 s. c o m * * @param classFullName * @param result * @param entity * @param clazz * @return */ private Object getValueByType(String classFullName, Object result, ExcelImportEntity entity, Class clazz) { try { //,null,?? if (result == null || StringUtils.isBlank(result.toString())) { return null; } if ("class java.util.Date".equals(classFullName) && result instanceof String) { return DateUtils.parseDate(result.toString(), entity.getFormat()); } if ("class java.lang.Boolean".equals(classFullName) || "boolean".equals(classFullName)) { return Boolean.valueOf(String.valueOf(result)); } if ("class java.lang.Double".equals(classFullName) || "double".equals(classFullName)) { return Double.valueOf(String.valueOf(result)); } if ("class java.lang.Long".equals(classFullName) || "long".equals(classFullName)) { try { return Long.valueOf(String.valueOf(result)); } catch (Exception e) { //?,double,??Int return Double.valueOf(String.valueOf(result)).longValue(); } } if ("class java.lang.Float".equals(classFullName) || "float".equals(classFullName)) { return Float.valueOf(String.valueOf(result)); } if ("class java.lang.Integer".equals(classFullName) || "int".equals(classFullName)) { try { return Integer.valueOf(String.valueOf(result)); } catch (Exception e) { //?,double,??Int return Double.valueOf(String.valueOf(result)).intValue(); } } if ("class java.math.BigDecimal".equals(classFullName)) { return new BigDecimal(String.valueOf(result)); } if ("class java.lang.String".equals(classFullName)) { //String ,Excel????String,Double, if (result instanceof String) { return result; } // double if (result instanceof Double) { return PoiPublicUtil.doubleToString((Double) result); } return String.valueOf(result); } if (clazz != null && clazz.isEnum()) { if (StringUtils.isNotEmpty(entity.getEnumImportMethod())) { return PoiReflectorUtil.fromCache(clazz).execEnumStaticMethod(entity.getEnumImportMethod(), result); } else { return Enum.valueOf(clazz, result.toString()); } } return result; } catch (Exception e) { LOGGER.error(e.getMessage(), e); throw new ExcelImportException(ExcelImportEnum.GET_VALUE_ERROR); } }
From source file:com.funtl.framework.smoke.core.commons.excel.ImportExcel.java
/** * ??/*from w ww.j a v a 2s . c o m*/ * * @param cls * @param groups */ public <E> List<E> getDataList(Class<E> cls, int... groups) throws InstantiationException, IllegalAccessException { List<Object[]> annotationList = Lists.newArrayList(); // Get annotation field Field[] fs = cls.getDeclaredFields(); for (Field f : fs) { ExcelField ef = f.getAnnotation(ExcelField.class); if (ef != null && (ef.type() == 0 || ef.type() == 2)) { if (groups != null && groups.length > 0) { boolean inGroup = false; for (int g : groups) { if (inGroup) { break; } for (int efg : ef.groups()) { if (g == efg) { inGroup = true; annotationList.add(new Object[] { ef, f }); break; } } } } else { annotationList.add(new Object[] { ef, f }); } } } // Get annotation method Method[] ms = cls.getDeclaredMethods(); for (Method m : ms) { ExcelField ef = m.getAnnotation(ExcelField.class); if (ef != null && (ef.type() == 0 || ef.type() == 2)) { if (groups != null && groups.length > 0) { boolean inGroup = false; for (int g : groups) { if (inGroup) { break; } for (int efg : ef.groups()) { if (g == efg) { inGroup = true; annotationList.add(new Object[] { ef, m }); break; } } } } else { annotationList.add(new Object[] { ef, m }); } } } // Field sorting Collections.sort(annotationList, new Comparator<Object[]>() { public int compare(Object[] o1, Object[] o2) { return new Integer(((ExcelField) o1[0]).sort()).compareTo(new Integer(((ExcelField) o2[0]).sort())); } ; }); //log.debug("Import column count:"+annotationList.size()); // Get excel data List<E> dataList = Lists.newArrayList(); for (int i = this.getDataRowNum(); i < this.getLastDataRowNum(); i++) { E e = (E) cls.newInstance(); int column = 0; Row row = this.getRow(i); StringBuilder sb = new StringBuilder(); for (Object[] os : annotationList) { Object val = this.getCellValue(row, column++); if (val != null) { ExcelField ef = (ExcelField) os[0]; // If is dict type, get dict value if (StringUtils.isNotBlank(ef.dictType())) { val = DictUtils.getDictValue(val.toString(), ef.dictType(), ""); //log.debug("Dictionary type value: ["+i+","+colunm+"] " + val); } // Get param type and type cast Class<?> valType = Class.class; if (os[1] instanceof Field) { valType = ((Field) os[1]).getType(); } else if (os[1] instanceof Method) { Method method = ((Method) os[1]); if ("get".equals(method.getName().substring(0, 3))) { valType = method.getReturnType(); } else if ("set".equals(method.getName().substring(0, 3))) { valType = ((Method) os[1]).getParameterTypes()[0]; } } //log.debug("Import value type: ["+i+","+column+"] " + valType); try { if (valType == String.class) { String s = String.valueOf(val.toString()); if (StringUtils.endsWith(s, ".0")) { val = StringUtils.substringBefore(s, ".0"); } else { val = String.valueOf(val.toString()); } } else if (valType == Integer.class) { val = Double.valueOf(val.toString()).intValue(); } else if (valType == Long.class) { val = Double.valueOf(val.toString()).longValue(); } else if (valType == Double.class) { val = Double.valueOf(val.toString()); } else if (valType == Float.class) { val = Float.valueOf(val.toString()); } else if (valType == Date.class) { val = DateUtil.getJavaDate((Double) val); } else { if (ef.fieldType() != Class.class) { val = ef.fieldType().getMethod("getValue", String.class).invoke(null, val.toString()); } else { val = Class .forName(this.getClass().getName().replaceAll( this.getClass().getSimpleName(), "fieldtype." + valType.getSimpleName() + "Type")) .getMethod("getValue", String.class).invoke(null, val.toString()); } } } catch (Exception ex) { log.info("Get cell value [" + i + "," + column + "] error: " + ex.toString()); val = null; } // set entity value if (os[1] instanceof Field) { Reflections.invokeSetter(e, ((Field) os[1]).getName(), val); } else if (os[1] instanceof Method) { String mthodName = ((Method) os[1]).getName(); if ("get".equals(mthodName.substring(0, 3))) { mthodName = "set" + StringUtils.substringAfter(mthodName, "get"); } Reflections.invokeMethod(e, mthodName, new Class[] { valType }, new Object[] { val }); } } sb.append(val + ", "); } dataList.add(e); log.debug("Read success: [" + i + "] " + sb.toString()); } return dataList; }
From source file:cn.orignzmn.shopkepper.common.utils.excel.ImportExcel.java
/** * ??//from w w w. ja va 2 s .co m * @param cls * @param groups */ public <E> List<E> getDataList(Class<E> cls, Map<String, Object> inportInfo, int... groups) throws InstantiationException, IllegalAccessException { List<Object[]> annotationList = Lists.newArrayList(); // Get annotation field Field[] fs = cls.getDeclaredFields(); ExcelSheet esarr = cls.getAnnotation(ExcelSheet.class); String annTitle = ""; if (esarr == null) return Lists.newArrayList(); annTitle = esarr.value(); for (Field f : fs) { ExcelField ef = f.getAnnotation(ExcelField.class); if (ef != null && (ef.type() == 0 || ef.type() == 2)) { if (groups != null && groups.length > 0) { boolean inGroup = false; for (int g : groups) { if (inGroup) { break; } for (int efg : ef.groups()) { if (g == efg) { inGroup = true; annotationList.add(new Object[] { ef, f }); break; } } } } else { annotationList.add(new Object[] { ef, f }); } } } // Get annotation method Method[] ms = cls.getDeclaredMethods(); for (Method m : ms) { ExcelField ef = m.getAnnotation(ExcelField.class); if (ef != null && (ef.type() == 0 || ef.type() == 2)) { if (groups != null && groups.length > 0) { boolean inGroup = false; for (int g : groups) { if (inGroup) { break; } for (int efg : ef.groups()) { if (g == efg) { inGroup = true; annotationList.add(new Object[] { ef, m }); break; } } } } else { annotationList.add(new Object[] { ef, m }); } } } // Field sorting Collections.sort(annotationList, new Comparator<Object[]>() { public int compare(Object[] o1, Object[] o2) { return new Integer(((ExcelField) o1[0]).sort()).compareTo(new Integer(((ExcelField) o2[0]).sort())); }; }); //log.debug("Import column count:"+annotationList.size()); // Get excel data List<E> dataList = Lists.newArrayList(); //??? if (!"".equals(annTitle)) { String title = StringUtils.trim(this.getCellValue(this.getRow(0), 0).toString()); if (!annTitle.equals(title)) { inportInfo.put("success", false); inportInfo.put("message", "??"); return Lists.newArrayList(); } } for (int i = this.getDataRowNum(); i < this.getLastDataRowNum(); i++) { E e = (E) cls.newInstance(); int column = 0; Row row = this.getRow(i); StringBuilder sb = new StringBuilder(); for (Object[] os : annotationList) { Object val = this.getCellValue(row, column++); if (val != null) { ExcelField ef = (ExcelField) os[0]; // If is dict type, get dict value // if (StringUtils.isNotBlank(ef.dictType())){ // val = DictUtils.getDictValue(val.toString(), ef.dictType(), ""); // //log.debug("Dictionary type value: ["+i+","+colunm+"] " + val); // } // Get param type and type cast Class<?> valType = Class.class; if (os[1] instanceof Field) { valType = ((Field) os[1]).getType(); } else if (os[1] instanceof Method) { Method method = ((Method) os[1]); if ("get".equals(method.getName().substring(0, 3))) { valType = method.getReturnType(); } else if ("set".equals(method.getName().substring(0, 3))) { valType = ((Method) os[1]).getParameterTypes()[0]; } } //log.debug("Import value type: ["+i+","+column+"] " + valType); try { if (valType == String.class) { String s = String.valueOf(val.toString()); if (StringUtils.endsWith(s, ".0")) { val = StringUtils.substringBefore(s, ".0"); } else { val = String.valueOf(val.toString()); } } else if (valType == Integer.class) { val = Double.valueOf(val.toString()).intValue(); } else if (valType == Long.class) { val = Double.valueOf(val.toString()).longValue(); } else if (valType == Double.class) { val = Double.valueOf(val.toString()); } else if (valType == Float.class) { val = Float.valueOf(val.toString()); } else if (valType == Date.class) { val = DateUtil.getJavaDate((Double) val); } else { if (ef.fieldType() != Class.class) { val = ef.fieldType().getMethod("getValue", String.class).invoke(null, val.toString()); } else { val = Class .forName(this.getClass().getName().replaceAll( this.getClass().getSimpleName(), "fieldtype." + valType.getSimpleName() + "Type")) .getMethod("getValue", String.class).invoke(null, val.toString()); } } } catch (Exception ex) { log.info("Get cell value [" + i + "," + column + "] error: " + ex.toString()); val = null; } // set entity value if (os[1] instanceof Field) { Reflections.invokeSetter(e, ((Field) os[1]).getName(), val); } else if (os[1] instanceof Method) { String mthodName = ((Method) os[1]).getName(); if ("get".equals(mthodName.substring(0, 3))) { mthodName = "set" + StringUtils.substringAfter(mthodName, "get"); } Reflections.invokeMethod(e, mthodName, new Class[] { valType }, new Object[] { val }); } } sb.append(val + ", "); } dataList.add(e); log.debug("Read success: [" + i + "] " + sb.toString()); } return dataList; }