List of usage examples for java.lang Double equals
public boolean equals(Object obj)
From source file:com.hbc.api.gateway.alizhifu.TransferSummary.java
public static String getTransferDetails(List<TransInfo> transInfoList, Double totalAmount) { StringBuilder transferDetails = new StringBuilder(); final String comm = "|"; Double checkPrice = 0.00d;//from www . jav a 2 s .c o m for (TransInfo transInfo : transInfoList) { checkPrice = DoubleUtil.addDouble(checkPrice, transInfo.getActualAmount()); transferDetails.append(transInfo.getTransNo()).append("^").append(transInfo.getPayeeAccount()) .append("^").append(transInfo.getPayeeName()).append("^").append(transInfo.getActualAmount()) .append("^").append(transInfo.getTransSubject()).append(comm); } if (!totalAmount.equals(checkPrice)) { throw new GatewayException(GatewayReturnCodeEnum.ERR_TRANS_PRICE_NOT_MATCH); } return StringUtils.removeEnd(transferDetails.toString(), comm); }
From source file:org.neo4j.nlp.impl.util.VectorUtil.java
public static List<LinkedHashMap<String, Object>> getPhrasesForClass(GraphDatabaseService db, String className) {/*from w w w. j a v a2s . c om*/ // This method trains a model on a supplied label and text content VsmCacheModel vsmCacheModel = new VsmCacheModel(db).invoke(); List<Integer> longs = vsmCacheModel.getDocuments().get(className).stream() .map(a -> ((Integer) a.get("feature"))).collect(Collectors.toList()); Map<Long, LinkedHashMap<Long, Integer>> pageRankGraph = new HashMap<>(); // PageRank Map<Long, Double> pageRank = getPageRankOnFeatures(db, longs, pageRankGraph); // Translate map to phrases List<LinkedHashMap<String, Object>> results = longs.stream().map(a -> { LinkedHashMap<String, Object> linkHashMap = new LinkedHashMap<>(); linkHashMap.put("feature", NodeManager.getNodeFromGlobalCache(a.longValue()).get("phrase")); linkHashMap.put("affinity", (pageRank.get(a.longValue()) + getFeatureMatchDistribution(db, a.longValue())) / 2.0); return linkHashMap; }).collect(Collectors.toList()); results.sort((a, b) -> { Double diff = (((Double) a.get("affinity")) * 100) - (((Double) b.get("affinity")) * 100); return diff > 0.0 ? -1 : diff.equals(0.0) ? 0 : 1; }); return results; }
From source file:org.neo4j.nlp.impl.util.VectorUtil.java
public static Map<String, List<LinkedHashMap<String, Object>>> similarDocumentMapForClass( GraphDatabaseService db, String className) { Map<String, List<LinkedHashMap<String, Object>>> documents; Map<String, List<LinkedHashMap<String, Object>>> results = new HashMap<>(); List<Integer> featureIndexList; VsmCacheModel vsmCacheModel = new VsmCacheModel(db).invoke(); featureIndexList = vsmCacheModel.getFeatureIndexList(); documents = vsmCacheModel.getDocuments(); final String key = className; List<LinkedHashMap<String, Object>> resultList = new ArrayList<>(); LinkedHashMap<String, Double> classMap = new LinkedHashMap<>(); List<Double> v1 = getFeatureVectorForDocumentClass(documents, featureIndexList, key); documents.keySet().stream().filter(otherKey -> !key.equals(otherKey)).forEach(otherKey -> { List<Double> v2 = getBinaryFeatureVectorForDocumentClass(documents, featureIndexList, otherKey); classMap.put(otherKey, cosineSimilarity(v1, v2)); });/*www .j a va 2 s. co m*/ classMap.keySet().forEach(ks -> { if (!ks.equals(key) && classMap.get(ks) > 0.0) { LinkedHashMap<String, Object> localMap = new LinkedHashMap<>(); localMap.put("class", ks); localMap.put("similarity", classMap.get(ks)); resultList.add(localMap); } }); resultList.sort((a, b) -> { Double diff = (((double) a.get("similarity")) - ((double) b.get("similarity"))); return diff > 0 ? -1 : diff.equals(0.0) ? 0 : 1; }); results.put("classes", resultList); return results; }
From source file:org.neo4j.nlp.impl.util.VectorUtil.java
public static Map<String, List<LinkedHashMap<String, Object>>> similarDocumentMapForVector( GraphDatabaseService db, GraphManager graphManager, String input, DecisionTree<Long> decisionTree) { Map<String, List<LinkedHashMap<String, Object>>> documents; Map<String, List<LinkedHashMap<String, Object>>> results = new HashMap<>(); List<Integer> featureIndexList; VsmCacheModel vsmCacheModel = new VsmCacheModel(db).invoke(); featureIndexList = vsmCacheModel.getFeatureIndexList(); documents = vsmCacheModel.getDocuments(); List<Double> features = getFeatureVector(db, graphManager, input, featureIndexList, decisionTree); List<LinkedHashMap<String, Object>> resultList = new ArrayList<>(); LinkedHashMap<String, Double> classMap = new LinkedHashMap<>(); documents.keySet().stream().forEach(otherKey -> { List<Double> v2 = getWeightVectorForClass(documents, otherKey, featureIndexList, db); classMap.put(otherKey, cosineSimilarity(features, v2)); });//from www .j a v a 2 s. co m classMap.keySet().stream().forEach(ks -> { if (classMap.get(ks) > 0.0) { LinkedHashMap<String, Object> localMap = new LinkedHashMap<>(); localMap.put("class", ks); localMap.put("similarity", classMap.get(ks)); resultList.add(localMap); } }); try { resultList.sort((a, b) -> { Double diff = (((double) a.get("similarity")) - ((double) b.get("similarity"))); return diff > 0 ? -1 : diff.equals(0.0) ? 0 : 1; }); } catch (NullPointerException ex) { // resultList is empty or null } results.put("classes", resultList); return results; }
From source file:msi.gaml.operators.Maths.java
@operator(value = IKeyword.DIVIDE, can_be_const = true, category = { IOperatorCategory.ARITHMETIC }) @doc(value = "Returns a float, equal to the division of the left-hand operand by the rigth-hand operand.", see = "*") public static Double opDivide(final Double a, final Double b) throws GamaRuntimeException { if (b.equals(0.0)) { throw GamaRuntimeException.error("Division by zero"); }//from ww w . j a v a 2s .co m return a / b; }
From source file:msi.gaml.operators.Maths.java
@operator(value = IKeyword.DIVIDE, can_be_const = true, category = { IOperatorCategory.ARITHMETIC }) @doc(value = "Returns a float, equal to the division of the left-hand operand by the rigth-hand operand.", see = "*") public static Double opDivide(final Integer a, final Double b) throws GamaRuntimeException { if (b.equals(0.0)) { throw GamaRuntimeException.error("Division by zero"); }// w w w .ja v a2 s .c o m return a.doubleValue() / b.doubleValue(); }
From source file:msi.gaml.operators.Maths.java
@operator(value = "div", can_be_const = true, category = { IOperatorCategory.ARITHMETIC }) @doc(value = "an int, equal to the truncation of the division of the left-hand operand by the right-hand operand.", usages = @usage(value = "if the right-hand operand is equal to zero, raises an exception."), examples = @example(value = "40 div 4.1", equals = "9")) public static Integer div(final Integer a, final Double b) throws GamaRuntimeException { if (b.equals(0.0)) { throw GamaRuntimeException.error("Division by zero"); }// ww w . ja v a2 s .c o m return (int) (a / b); }
From source file:msi.gaml.operators.Maths.java
@operator(value = "div", can_be_const = true, category = { IOperatorCategory.ARITHMETIC }) @doc(value = "an int, equal to the truncation of the division of the left-hand operand by the right-hand operand.", examples = @example(value = "40.1 div 4.5", equals = "8")) public static Integer div(final Double a, final Double b) throws GamaRuntimeException { if (b.equals(0.0)) { throw GamaRuntimeException.error("Division by zero"); }//from w ww .jav a 2 s .c o m return (int) (a / b); }
From source file:org.cloudfoundry.client.v2.ApplicationsTest.java
private static boolean isIdentical(Double expected, Double actual) { return expected == null ? actual == null : expected.equals(actual); }
From source file:com.xqdev.jam.MLJAM.java
private static void sendXQueryResponse(HttpServletResponse res, Object o) throws IOException { // Make sure to leave the status code alone. It defaults to 200, but sometimes // callers of this method will have set it to a custom code. res.setContentType("x-marklogic/xquery; charset=UTF-8"); //res.setContentType("text/plain"); Writer writer = res.getWriter(); // care to handle errors later? if (o == null) { writer.write("()"); }// w w w . ja va 2 s . com else if (o instanceof byte[]) { writer.write("binary {'"); writer.write(hexEncode((byte[]) o)); writer.write("'}"); } else if (o instanceof Object[]) { Object[] arr = (Object[]) o; writer.write("("); for (int i = 0; i < arr.length; i++) { sendXQueryResponse(res, arr[i]); if (i + 1 < arr.length) writer.write(", "); } writer.write(")"); } else if (o instanceof String) { writer.write("'"); writer.write(escapeSingleQuotes(o.toString())); writer.write("'"); } else if (o instanceof Integer) { writer.write("xs:int("); writer.write(o.toString()); writer.write(")"); } else if (o instanceof Long) { writer.write("xs:integer("); writer.write(o.toString()); writer.write(")"); } else if (o instanceof Float) { Float flt = (Float) o; writer.write("xs:float("); if (flt.equals(Float.POSITIVE_INFINITY)) { writer.write("'INF'"); } else if (flt.equals(Float.NEGATIVE_INFINITY)) { writer.write("'-INF'"); } else if (flt.equals(Float.NaN)) { writer.write("fn:number(())"); // poor man's way to write NaN } else { writer.write(o.toString()); } writer.write(")"); } else if (o instanceof Double) { Double dbl = (Double) o; writer.write("xs:double("); if (dbl.equals(Double.POSITIVE_INFINITY)) { writer.write("'INF'"); } else if (dbl.equals(Double.NEGATIVE_INFINITY)) { writer.write("'-INF'"); } else if (dbl.equals(Double.NaN)) { writer.write("fn:number(())"); // poor man's way to write NaN } else { writer.write(o.toString()); } writer.write(")"); } else if (o instanceof Boolean) { writer.write("xs:boolean('"); writer.write(o.toString()); writer.write("')"); } else if (o instanceof BigDecimal) { writer.write("xs:decimal("); writer.write(o.toString()); writer.write(")"); } else if (o instanceof Date) { // We want something like: 2006-04-30T01:28:30.499-07:00 // We format to get: 2006-04-30T01:28:30.499-0700 // Then we add in the colon writer.write("xs:dateTime('"); String d = dateFormat.format((Date) o); writer.write(d.substring(0, d.length() - 2)); writer.write(":"); writer.write(d.substring(d.length() - 2)); writer.write("')"); } else if (o instanceof XMLGregorianCalendar) { XMLGregorianCalendar greg = (XMLGregorianCalendar) o; QName type = greg.getXMLSchemaType(); if (type.equals(DatatypeConstants.DATETIME)) { writer.write("xs:dateTime('"); } else if (type.equals(DatatypeConstants.DATE)) { writer.write("xs:date('"); } else if (type.equals(DatatypeConstants.TIME)) { writer.write("xs:time('"); } else if (type.equals(DatatypeConstants.GYEARMONTH)) { writer.write("xs:gYearMonth('"); } else if (type.equals(DatatypeConstants.GMONTHDAY)) { writer.write("xs:gMonthDay('"); } else if (type.equals(DatatypeConstants.GYEAR)) { writer.write("xs:gYear('"); } else if (type.equals(DatatypeConstants.GMONTH)) { writer.write("xs:gMonth('"); } else if (type.equals(DatatypeConstants.GDAY)) { writer.write("xs:gDay('"); } writer.write(greg.toXMLFormat()); writer.write("')"); } else if (o instanceof Duration) { Duration dur = (Duration) o; /* // The following fails on Xerces QName type = dur.getXMLSchemaType(); if (type.equals(DatatypeConstants.DURATION)) { writer.write("xs:duration('"); } else if (type.equals(DatatypeConstants.DURATION_DAYTIME)) { writer.write("xdt:dayTimeDuration('"); } else if (type.equals(DatatypeConstants.DURATION_YEARMONTH)) { writer.write("xdt:yearMonthDuration('"); } */ // If no years or months, must be DURATION_DAYTIME if (dur.getYears() == 0 && dur.getMonths() == 0) { writer.write("xdt:dayTimeDuration('"); } // If has years or months but nothing else, must be DURATION_YEARMONTH else if (dur.getDays() == 0 && dur.getHours() == 0 && dur.getMinutes() == 0 && dur.getSeconds() == 0) { writer.write("xdt:yearMonthDuration('"); } else { writer.write("xs:duration('"); } writer.write(dur.toString()); writer.write("')"); } else if (o instanceof org.jdom.Element) { org.jdom.Element elt = (org.jdom.Element) o; writer.write("xdmp:unquote('"); // Because "<" in XQuery is the same as "<" I need to double escape any ampersands writer.write(new org.jdom.output.XMLOutputter().outputString(elt).replaceAll("&", "&") .replaceAll("'", "''")); writer.write("')/*"); // make sure to return the root elt } else if (o instanceof org.jdom.Document) { org.jdom.Document doc = (org.jdom.Document) o; writer.write("xdmp:unquote('"); writer.write(new org.jdom.output.XMLOutputter().outputString(doc).replaceAll("&", "&") .replaceAll("'", "''")); writer.write("')"); } else if (o instanceof org.jdom.Text) { org.jdom.Text text = (org.jdom.Text) o; writer.write("text {'"); writer.write(escapeSingleQuotes(text.getText())); writer.write("'}"); } else if (o instanceof org.jdom.Attribute) { // <fake xmlns:pref="http://uri.com" pref:attrname="attrvalue"/>/@*:attrname // <fake xmlns="http://uri.com" attrname="attrvalue"/>/@*:attrname org.jdom.Attribute attr = (org.jdom.Attribute) o; writer.write("<fake xmlns"); if ("".equals(attr.getNamespacePrefix())) { writer.write("=\""); } else { writer.write(":" + attr.getNamespacePrefix() + "=\""); } writer.write(attr.getNamespaceURI()); writer.write("\" "); writer.write(attr.getQualifiedName()); writer.write("=\""); writer.write(escapeSingleQuotes(attr.getValue())); writer.write("\"/>/@*:"); writer.write(attr.getName()); } else if (o instanceof org.jdom.Comment) { org.jdom.Comment com = (org.jdom.Comment) o; writer.write("comment {'"); writer.write(escapeSingleQuotes(com.getText())); writer.write("'}"); } else if (o instanceof org.jdom.ProcessingInstruction) { org.jdom.ProcessingInstruction pi = (org.jdom.ProcessingInstruction) o; writer.write("processing-instruction "); writer.write(pi.getTarget()); writer.write(" {'"); writer.write(escapeSingleQuotes(pi.getData())); writer.write("'}"); } else if (o instanceof QName) { QName q = (QName) o; writer.write("fn:expanded-QName('"); writer.write(escapeSingleQuotes(q.getNamespaceURI())); writer.write("','"); writer.write(q.getLocalPart()); writer.write("')"); } else { writer.write("error('XQuery tried to retrieve unsupported type: " + o.getClass().getName() + "')"); } writer.flush(); }