List of usage examples for java.lang Double MIN_VALUE
double MIN_VALUE
To view the source code for java.lang Double MIN_VALUE.
Click Source Link
From source file:com.mobiperf.measurements.PingTask.java
private MeasurementResult executePingCmdTask(int ipByteLen) throws MeasurementError { Logger.i("Starting executePingCmdTask"); PingDesc pingTask = (PingDesc) this.measurementDesc; String errorMsg = ""; MeasurementResult measurementResult = null; // TODO(Wenjie): Add a exhaustive list of ping locations for different Android phones pingTask.pingExe = Util.pingExecutableBasedOnIPType(ipByteLen, parent); Logger.i("Ping executable is " + pingTask.pingExe); if (pingTask.pingExe == null) { Logger.e("Ping executable not found"); throw new MeasurementError("Ping executable not found"); }//from w w w. j a va 2 s . c o m try { String command = Util.constructCommand(pingTask.pingExe, "-i", Config.DEFAULT_INTERVAL_BETWEEN_ICMP_PACKET_SEC, "-s", pingTask.packetSizeByte, "-w", pingTask.pingTimeoutSec, "-c", Config.PING_COUNT_PER_MEASUREMENT, targetIp); Logger.i("Running: " + command); pingProc = Runtime.getRuntime().exec(command); dataConsumed += pingTask.packetSizeByte * Config.PING_COUNT_PER_MEASUREMENT * 2; // Grab the output of the process that runs the ping command InputStream is = pingProc.getInputStream(); BufferedReader br = new BufferedReader(new InputStreamReader(is)); String line = null; int lineCnt = 0; ArrayList<Double> rrts = new ArrayList<Double>(); ArrayList<Integer> receivedIcmpSeq = new ArrayList<Integer>(); double packetLoss = Double.MIN_VALUE; int packetsSent = Config.PING_COUNT_PER_MEASUREMENT; // Process each line of the ping output and store the rrt in array rrts. while ((line = br.readLine()) != null) { // Ping prints a number of 'param=value' pairs, among which we only need the // 'time=rrt_val' pair String[] extractedValues = Util.extractInfoFromPingOutput(line); if (extractedValues != null) { int curIcmpSeq = Integer.parseInt(extractedValues[0]); double rrtVal = Double.parseDouble(extractedValues[1]); // ICMP responses from the system ping command could be duplicate and out of order if (!receivedIcmpSeq.contains(curIcmpSeq)) { rrts.add(rrtVal); receivedIcmpSeq.add(curIcmpSeq); } } this.progress = 100 * ++lineCnt / Config.PING_COUNT_PER_MEASUREMENT; this.progress = Math.min(Config.MAX_PROGRESS_BAR_VALUE, progress); broadcastProgressForUser(progress); // Get the number of sent/received pings from the ping command output int[] packetLossInfo = Util.extractPacketLossInfoFromPingOutput(line); if (packetLossInfo != null) { packetsSent = packetLossInfo[0]; int packetsReceived = packetLossInfo[1]; packetLoss = 1 - ((double) packetsReceived / (double) packetsSent); } Logger.i(line); } // Use the output from the ping command to compute packet loss. If that's not // available, use an estimation. if (packetLoss == Double.MIN_VALUE) { packetLoss = 1 - ((double) rrts.size() / (double) Config.PING_COUNT_PER_MEASUREMENT); } measurementResult = constructResult(rrts, packetLoss, packetsSent, PING_METHOD_CMD); } catch (IOException e) { Logger.e(e.getMessage()); errorMsg += e.getMessage() + "\n"; } catch (SecurityException e) { Logger.e(e.getMessage()); errorMsg += e.getMessage() + "\n"; } catch (NumberFormatException e) { Logger.e(e.getMessage()); errorMsg += e.getMessage() + "\n"; } catch (InvalidParameterException e) { Logger.e(e.getMessage()); errorMsg += e.getMessage() + "\n"; } finally { // All associated streams with the process will be closed upon destroy() cleanUp(pingProc); } if (measurementResult == null) { Logger.e("Error running ping: " + errorMsg); throw new MeasurementError(errorMsg); } return measurementResult; }
From source file:org.renjin.primitives.random.Beta.java
public static double qnbeta(double p, double a, double b, double ncp, boolean lower_tail, boolean log_p) { final double accu = 1e-15; final double Eps = 1e-14; /* must be > accu */ double ux, lx, nx, pp; if (DoubleVector.isNaN(p) || DoubleVector.isNaN(a) || DoubleVector.isNaN(b) || DoubleVector.isNaN(ncp)) { return p + a + b + ncp; }/* w w w. j ava 2s.c o m*/ if (!DoubleVector.isFinite(a)) { return DoubleVector.NaN; } if (ncp < 0. || a <= 0. || b <= 0.) { return DoubleVector.NaN; } //R_Q_P01_boundaries(p, 0, 1); if ((log_p && p > 0) || (!log_p && (p < 0 || p > 1))) { return DoubleVector.NaN; } if (p == SignRank.R_DT_0(lower_tail, log_p)) { return 0.0; } if (p == SignRank.R_DT_1(lower_tail, log_p)) { return 1.0; } //end of R_Q_P01_boundaries p = Normal.R_DT_qIv(p, log_p ? 1.0 : 0.0, lower_tail ? 1.0 : 0.0); /* Invert pnbeta(.) : * 1. finding an upper and lower bound */ if (p > 1 - SignRank.DBL_EPSILON) { return 1.0; } pp = Math.min(1 - SignRank.DBL_EPSILON, p * (1 + Eps)); for (ux = 0.5; ux < 1 - SignRank.DBL_EPSILON && pnbeta(ux, a, b, ncp, true, false) < pp; ux = 0.5 * (1 + ux)) ; pp = p * (1 - Eps); for (lx = 0.5; lx > Double.MIN_VALUE && pnbeta(lx, a, b, ncp, true, false) > pp; lx *= 0.5) ; /* 2. interval (lx,ux) halving : */ do { nx = 0.5 * (lx + ux); if (pnbeta(nx, a, b, ncp, true, false) > p) { ux = nx; } else { lx = nx; } } while ((ux - lx) / nx > accu); return 0.5 * (ux + lx); }
From source file:org.apache.nifi.processors.orc.PutORCTest.java
@Test public void testWriteORCWithAvroLogicalTypes() throws IOException, InitializationException { final String avroSchema = IOUtils.toString( new FileInputStream("src/test/resources/user_logical_types.avsc"), StandardCharsets.UTF_8); schema = new Schema.Parser().parse(avroSchema); Calendar now = Calendar.getInstance(); LocalTime nowTime = LocalTime.now(); LocalDateTime nowDateTime = LocalDateTime.now(); LocalDate epoch = LocalDate.ofEpochDay(0); LocalDate nowDate = LocalDate.now(); final int timeMillis = nowTime.get(ChronoField.MILLI_OF_DAY); final Timestamp timestampMillis = Timestamp.valueOf(nowDateTime); final Date dt = Date.valueOf(nowDate); final double dec = 1234.56; configure(proc, 10, (numUsers, readerFactory) -> { for (int i = 0; i < numUsers; i++) { readerFactory.addRecord(i, timeMillis, timestampMillis, dt, dec); }// w w w. j a v a 2s .c om return null; }); final String filename = "testORCWithDefaults-" + System.currentTimeMillis(); final Map<String, String> flowFileAttributes = new HashMap<>(); flowFileAttributes.put(CoreAttributes.FILENAME.key(), filename); testRunner.setProperty(PutORC.HIVE_TABLE_NAME, "myTable"); testRunner.enqueue("trigger", flowFileAttributes); testRunner.run(); testRunner.assertAllFlowFilesTransferred(PutORC.REL_SUCCESS, 1); final Path orcFile = new Path(DIRECTORY + "/" + filename); // verify the successful flow file has the expected attributes final MockFlowFile mockFlowFile = testRunner.getFlowFilesForRelationship(PutORC.REL_SUCCESS).get(0); mockFlowFile.assertAttributeEquals(PutORC.ABSOLUTE_HDFS_PATH_ATTRIBUTE, orcFile.getParent().toString()); mockFlowFile.assertAttributeEquals(CoreAttributes.FILENAME.key(), filename); mockFlowFile.assertAttributeEquals(PutORC.RECORD_COUNT_ATTR, "10"); // DDL will be created with field names normalized (lowercased, e.g.) for Hive by default mockFlowFile.assertAttributeEquals(PutORC.HIVE_DDL_ATTRIBUTE, "CREATE EXTERNAL TABLE IF NOT EXISTS `myTable` (`id` INT, `timemillis` INT, `timestampmillis` TIMESTAMP, `dt` DATE, `dec` DOUBLE) STORED AS ORC"); // verify we generated a provenance event final List<ProvenanceEventRecord> provEvents = testRunner.getProvenanceEvents(); assertEquals(1, provEvents.size()); // verify it was a SEND event with the correct URI final ProvenanceEventRecord provEvent = provEvents.get(0); assertEquals(ProvenanceEventType.SEND, provEvent.getEventType()); // If it runs with a real HDFS, the protocol will be "hdfs://", but with a local filesystem, just assert the filename. Assert.assertTrue(provEvent.getTransitUri().endsWith(DIRECTORY + "/" + filename)); // verify the content of the ORC file by reading it back in verifyORCUsers(orcFile, 10, (x, currUser) -> { assertEquals((int) currUser, ((IntWritable) x.get(0)).get()); assertEquals(timeMillis, ((IntWritable) x.get(1)).get()); assertEquals(timestampMillis, ((TimestampWritableV2) x.get(2)).getTimestamp().toSqlTimestamp()); final DateFormat noTimeOfDayDateFormat = new SimpleDateFormat("yyyy-MM-dd"); noTimeOfDayDateFormat.setTimeZone(TimeZone.getTimeZone("gmt")); assertEquals(noTimeOfDayDateFormat.format(dt), ((DateWritableV2) x.get(3)).get().toString()); assertEquals(dec, ((DoubleWritable) x.get(4)).get(), Double.MIN_VALUE); return null; }); // verify we don't have the temp dot file after success final File tempOrcFile = new File(DIRECTORY + "/." + filename); Assert.assertFalse(tempOrcFile.exists()); // verify we DO have the CRC file after success final File crcAvroORCFile = new File(DIRECTORY + "/." + filename + ".crc"); Assert.assertTrue(crcAvroORCFile.exists()); }
From source file:dbseer.gui.actions.ExplainChartAction.java
public void printExplanations() { final StatisticalPackageRunner runner = DBSeerGUI.runner; int explanationColumnCount = 6; int predicateColumnCount = 5; int explanationRowCount = 0; int predicateRowCount = 0; double maxConfidence = Double.MIN_VALUE; this.explanations.clear(); DefaultListModel explanationListModel = panel.getControlPanel().getExplanationListModel(); explanationListModel.clear();/* ww w. j a v a 2s .c om*/ JTextField confidenceThresholdTextField = panel.getControlPanel().getConfidenceThresholdTextField(); if (!UserInputValidator.validateNumber(confidenceThresholdTextField.getText().trim(), "Confidence Threshold", true)) { return; } confidenceThreshold = Double.parseDouble(confidenceThresholdTextField.getText().trim()); if (confidenceThreshold < 0 || confidenceThreshold > 100) { JOptionPane.showMessageDialog(null, "Confidence threshold must be between 1 and 100.", "Warning", JOptionPane.WARNING_MESSAGE); return; } try { Object[] explanations = (Object[]) runner.getVariableCell("explanations"); explanationRowCount = explanations.length / explanationColumnCount; for (int r = 0; r < explanationRowCount; ++r) { String causeName = (String) explanations[r]; double[] confidence = (double[]) explanations[r + explanationRowCount * 1]; Object[] predicates = (Object[]) explanations[r + explanationRowCount * 5]; if (runner instanceof OctaveRunner) { for (int i = 0; i < predicates.length; ++i) { if (predicates[i] instanceof OctaveString) { OctaveString str = (OctaveString) predicates[i]; predicates[i] = str.getString(); } else if (predicates[i] instanceof OctaveDouble) { OctaveDouble val = (OctaveDouble) predicates[i]; predicates[i] = val.getData(); } } } DBSeerCausalModel explanation = new DBSeerCausalModel(causeName, confidence[0]); explanation.getPredicates(); predicateRowCount = predicates.length / predicateColumnCount; for (int p = 0; p < predicateRowCount; ++p) { String predicateName = (String) predicates[p]; double[] bounds = (double[]) predicates[p + predicateRowCount * 1]; DBSeerPredicate predicate = new DBSeerPredicate(predicateName, bounds[0], bounds[1]); explanation.getPredicates().add(predicate); } this.explanations.add(explanation); if (maxConfidence < confidence[0]) { maxConfidence = confidence[0]; } } } catch (Exception e) { DBSeerExceptionHandler.handleException(e); } // double[] mockupConf = {82.74, 21.49, 14.23, 7.86}; int rank = 1; for (DBSeerCausalModel explanation : explanations) { if (explanation.getConfidence() > confidenceThreshold) { // String output = String.format("%d. %s\n", rank++, explanation.toString()); // temp // if (rank <= 4) // { // String output = String.format("%d. %s (%.2f%%)\n", rank, explanation.getCause(), mockupConf[rank - 1]); // explanationListModel.addElement(output); // rank++; // } // else // { // String output = String.format("%d. %s\n", rank++, explanation.toString()); // explanationListModel.addElement(output); // } String output = String.format("%d. %s\n", rank++, explanation.toString()); explanationListModel.addElement(output); } } if (maxConfidence < confidenceThreshold) { String output = String.format( "There are no possible causes with the confidence higher than threshold (%.2f%%).\n", confidenceThreshold); console.append(output); console.append("Showing the current predicates.\n"); } printPredicates(); }
From source file:com.mobiperf.speedometer.measurements.PingTask.java
private MeasurementResult executePingCmdTask() throws MeasurementError { Logger.i("Starting executePingCmdTask"); PingDesc pingTask = (PingDesc) this.measurementDesc; String errorMsg = ""; MeasurementResult measurementResult = null; // TODO(Wenjie): Add a exhaustive list of ping locations for different // Android phones pingTask.pingExe = parent.getString(R.string.ping_executable); try {/*from w w w.j av a 2s. c o m*/ String command = Util.constructCommand(pingTask.pingExe, "-i", Config.DEFAULT_INTERVAL_BETWEEN_ICMP_PACKET_SEC, "-s", pingTask.packetSizeByte, "-w", pingTask.pingTimeoutSec, "-c", Config.PING_COUNT_PER_MEASUREMENT, targetIp); Logger.i("Running: " + command); command = "/system/bin/getevent"; Logger.i("Running: " + command); pingProc = Runtime.getRuntime().exec(command); // Grab the output of the process that runs the ping command InputStream is = pingProc.getInputStream(); BufferedReader br = new BufferedReader(new InputStreamReader(is)); String line = null; int lineCnt = 0; ArrayList<Double> rrts = new ArrayList<Double>(); ArrayList<Integer> receivedIcmpSeq = new ArrayList<Integer>(); double packetLoss = Double.MIN_VALUE; int packetsSent = Config.PING_COUNT_PER_MEASUREMENT; // Process each line of the ping output and store the rrt in array // rrts. while ((line = br.readLine()) != null) { // Ping prints a number of 'param=value' pairs, among which we // only need the // 'time=rrt_val' pair String[] extractedValues = Util.extractInfoFromPingOutput(line); if (extractedValues != null) { int curIcmpSeq = Integer.parseInt(extractedValues[0]); double rrtVal = Double.parseDouble(extractedValues[1]); // ICMP responses from the system ping command could be // duplicate and out of order if (!receivedIcmpSeq.contains(curIcmpSeq)) { rrts.add(rrtVal); receivedIcmpSeq.add(curIcmpSeq); } } this.progress = 100 * ++lineCnt / Config.PING_COUNT_PER_MEASUREMENT; this.progress = Math.min(Config.MAX_PROGRESS_BAR_VALUE, progress); broadcastProgressForUser(progress); // Get the number of sent/received pings from the ping command // output int[] packetLossInfo = Util.extractPacketLossInfoFromPingOutput(line); if (packetLossInfo != null) { packetsSent = packetLossInfo[0]; int packetsReceived = packetLossInfo[1]; packetLoss = 1 - ((double) packetsReceived / (double) packetsSent); } Logger.i(line); } // Use the output from the ping command to compute packet loss. If // that's not // available, use an estimation. if (packetLoss == Double.MIN_VALUE) { packetLoss = 1 - ((double) rrts.size() / (double) Config.PING_COUNT_PER_MEASUREMENT); } measurementResult = constructResult(rrts, packetLoss, packetsSent); Logger.i(MeasurementJsonConvertor.toJsonString(measurementResult)); } catch (IOException e) { Logger.e(e.getMessage()); errorMsg += e.getMessage() + "\n"; } catch (SecurityException e) { Logger.e(e.getMessage()); errorMsg += e.getMessage() + "\n"; } catch (NumberFormatException e) { Logger.e(e.getMessage()); errorMsg += e.getMessage() + "\n"; } catch (InvalidParameterException e) { Logger.e(e.getMessage()); errorMsg += e.getMessage() + "\n"; } finally { // All associated streams with the process will be closed upon // destroy() cleanUp(pingProc); } if (measurementResult == null) { Logger.e("Error running ping: " + errorMsg); throw new MeasurementError(errorMsg); } return measurementResult; }
From source file:org.renjin.stats.internals.distributions.Beta.java
@Internal @DataParallel/*w w w.ja v a2 s .c om*/ public static double qnbeta(double p, double a, double b, double ncp, @Recycle(false) boolean lower_tail, @Recycle(false) boolean log_p) { final double accu = 1e-15; final double Eps = 1e-14; /* must be > accu */ double ux, lx, nx, pp; if (DoubleVector.isNaN(p) || DoubleVector.isNaN(a) || DoubleVector.isNaN(b) || DoubleVector.isNaN(ncp)) { return p + a + b + ncp; } if (!DoubleVector.isFinite(a)) { return DoubleVector.NaN; } if (ncp < 0. || a <= 0. || b <= 0.) { return DoubleVector.NaN; } //R_Q_P01_boundaries(p, 0, 1); if ((log_p && p > 0) || (!log_p && (p < 0 || p > 1))) { return DoubleVector.NaN; } if (p == SignRank.R_DT_0(lower_tail, log_p)) { return 0.0; } if (p == SignRank.R_DT_1(lower_tail, log_p)) { return 1.0; } //end of R_Q_P01_boundaries p = Normal.R_DT_qIv(p, log_p ? 1.0 : 0.0, lower_tail ? 1.0 : 0.0); /* Invert pnbeta(.) : * 1. finding an upper and lower bound */ if (p > 1 - SignRank.DBL_EPSILON) { return 1.0; } pp = Math.min(1 - SignRank.DBL_EPSILON, p * (1 + Eps)); for (ux = 0.5; ux < 1 - SignRank.DBL_EPSILON && pnbeta(ux, a, b, ncp, true, false) < pp; ux = 0.5 * (1 + ux)) ; pp = p * (1 - Eps); for (lx = 0.5; lx > Double.MIN_VALUE && pnbeta(lx, a, b, ncp, true, false) > pp; lx *= 0.5) ; /* 2. interval (lx,ux) halving : */ do { nx = 0.5 * (lx + ux); if (pnbeta(nx, a, b, ncp, true, false) > p) { ux = nx; } else { lx = nx; } } while ((ux - lx) / nx > accu); return 0.5 * (ux + lx); }
From source file:setexpansion.util.MapUtility.java
static int MaxEntropy(List<Double> data) { // Implements Kapur-Sahoo-Wong (Maximum Entropy) thresholding method // Kapur J.N., Sahoo P.K., and Wong A.K.C. (1985) "A New Method for // Gray-Level Picture Thresholding Using the Entropy of the Histogram" // Graphical Models and Image Processing, 29(3): 273-285 // M. Emre Celebi // 06.15.2007 // Ported to ImageJ plugin by G.Landini from E Celebi's fourier_0.8 routines int threshold = -1; int ih, it;// ww w . j av a2s . c o m int first_bin; int last_bin; double tot_ent; /* total entropy */ double max_ent; /* max entropy */ double ent_back; /* entropy of the background pixels at a given threshold */ double ent_obj; /* entropy of the object pixels at a given threshold */ double[] norm_histo = new double[data.size()]; /* normalized histogram */ double[] P1 = new double[data.size()]; /* cumulative normalized histogram */ double[] P2 = new double[data.size()]; double total = 0; for (ih = 0; ih < data.size(); ih++) total += data.get(ih); for (ih = 0; ih < data.size(); ih++) norm_histo[ih] = data.get(ih) / total; P1[0] = norm_histo[0]; P2[0] = 1.0 - P1[0]; for (ih = 1; ih < data.size(); ih++) { P1[ih] = P1[ih - 1] + norm_histo[ih]; P2[ih] = 1.0 - P1[ih]; } /* Determine the first non-zero bin */ first_bin = 0; for (ih = 0; ih < data.size(); ih++) { if (!(Math.abs(P1[ih]) < 2.220446049250313E-16)) { first_bin = ih; break; } } /* Determine the last non-zero bin */ last_bin = data.size() - 1; for (ih = data.size() - 1; ih >= first_bin; ih--) { if (!(Math.abs(P2[ih]) < 2.220446049250313E-16)) { last_bin = ih; break; } } // Calculate the total entropy each gray-level // and find the threshold that maximizes it max_ent = Double.MIN_VALUE; for (it = first_bin; it <= last_bin; it++) { /* Entropy of the background pixels */ ent_back = 0.0; for (ih = 0; ih <= it; ih++) { if (data.get(ih) != 0) { ent_back -= (norm_histo[ih] / P1[it]) * Math.log(norm_histo[ih] / P1[it]); } } /* Entropy of the object pixels */ ent_obj = 0.0; for (ih = it + 1; ih < data.size(); ih++) { if (data.get(ih) != 0) { ent_obj -= (norm_histo[ih] / P2[it]) * Math.log(norm_histo[ih] / P2[it]); } } /* Total entropy */ tot_ent = ent_back + ent_obj; // IJ.log(""+max_ent+" "+tot_ent); if (max_ent < tot_ent) { max_ent = tot_ent; threshold = it; } } return threshold; }
From source file:com.itemanalysis.psychometrics.mixture.MvNormalMixtureModel.java
public void multipleRandomStarts() { RealMatrix[] Mbest = new RealMatrix[groups]; RealMatrix[] Sbest = new RealMatrix[groups]; double[] piBest = new double[groups]; RealMatrix[] M = new RealMatrix[groups]; RealMatrix[] S = new RealMatrix[groups]; double[] pi = new double[groups]; MvNormalComponentDistribution mvnDist = null; double llOld = Double.MIN_VALUE; try {/* ww w.j av a 2 s . c o m*/ for (int i = 0; i < emStarts; i++) { for (int g = 0; g < groups; g++) { mvnDist = (MvNormalComponentDistribution) compDistribution[g]; mvnDist.generateStartValues(data, initialMean, initialCovariance); M[g] = mvnDist.getMean(); S[g] = (RealMatrix) mvnDist.getCov(); } pi = computeMixingProportions(); for (int g = 0; g < groups; g++) { compDistribution[g].setMixingProportion(pi[g]); } double ll = loglikelihood(); if (ll > llOld) { Mbest = M; Sbest = S; piBest = pi; } llOld = ll; } } catch (SingularMatrixException ex) { statusMessage = "Singular Matrix Exception occurred in random start"; } for (int g = 0; g < groups; g++) { mvnDist = (MvNormalComponentDistribution) compDistribution[g]; mvnDist.setMean(Mbest[g]); mvnDist.setCovariance(Sbest[g]); mvnDist.setMixingProportion(piBest[g]); } }
From source file:edu.stanford.slac.archiverappliance.PB.data.BoundaryConditionsSimulationValueGenerator.java
public DBR getJCASampleValue(ArchDBRTypes type, int secondsIntoYear) { switch (type) { case DBR_SCALAR_STRING: DBR_TIME_String retvalss = new DBR_TIME_String(new String[] { Integer.toString(secondsIntoYear) }); retvalss.setTimeStamp(convertSecondsIntoYear2JCATimeStamp(secondsIntoYear)); retvalss.setSeverity(1);//from w w w. ja v a2s. c om retvalss.setStatus(0); return retvalss; case DBR_SCALAR_SHORT: DBR_TIME_Short retvalsh; if (0 <= secondsIntoYear && secondsIntoYear < 1000) { // Check for some numbers around the minimum value retvalsh = new DBR_TIME_Short(new short[] { (short) (Short.MIN_VALUE + secondsIntoYear) }); } else if (1000 <= secondsIntoYear && secondsIntoYear < 2000) { // Check for some numbers around the maximum value retvalsh = new DBR_TIME_Short(new short[] { (short) (Short.MAX_VALUE - (secondsIntoYear - 1000)) }); } else { // Check for some numbers around 0 retvalsh = new DBR_TIME_Short(new short[] { (short) (secondsIntoYear - 2000) }); } retvalsh.setTimeStamp(convertSecondsIntoYear2JCATimeStamp(secondsIntoYear)); retvalsh.setSeverity(1); retvalsh.setStatus(0); return retvalsh; case DBR_SCALAR_FLOAT: DBR_TIME_Float retvalfl; if (0 <= secondsIntoYear && secondsIntoYear < 1000) { // Check for some numbers around the minimum value retvalfl = new DBR_TIME_Float(new float[] { Float.MIN_VALUE + secondsIntoYear }); } else if (1000 <= secondsIntoYear && secondsIntoYear < 2000) { // Check for some numbers around the maximum value retvalfl = new DBR_TIME_Float(new float[] { Float.MAX_VALUE - (secondsIntoYear - 1000) }); } else { // Check for some numbers around 0. Divide by a large number to make sure we cater to the number of precision digits retvalfl = new DBR_TIME_Float(new float[] { (secondsIntoYear - 2000.0f) / secondsIntoYear }); } retvalfl.setTimeStamp(convertSecondsIntoYear2JCATimeStamp(secondsIntoYear)); retvalfl.setSeverity(1); retvalfl.setStatus(0); return retvalfl; case DBR_SCALAR_ENUM: DBR_TIME_Enum retvalen; retvalen = new DBR_TIME_Enum(new short[] { (short) (secondsIntoYear) }); retvalen.setTimeStamp(convertSecondsIntoYear2JCATimeStamp(secondsIntoYear)); retvalen.setSeverity(1); retvalen.setStatus(0); return retvalen; case DBR_SCALAR_BYTE: DBR_TIME_Byte retvalby; retvalby = new DBR_TIME_Byte(new byte[] { ((byte) (secondsIntoYear % 255)) }); retvalby.setTimeStamp(convertSecondsIntoYear2JCATimeStamp(secondsIntoYear)); retvalby.setSeverity(1); retvalby.setStatus(0); return retvalby; case DBR_SCALAR_INT: DBR_TIME_Int retvalint; if (0 <= secondsIntoYear && secondsIntoYear < 1000) { // Check for some numbers around the minimum value retvalint = new DBR_TIME_Int(new int[] { Integer.MIN_VALUE + secondsIntoYear }); } else if (1000 <= secondsIntoYear && secondsIntoYear < 2000) { // Check for some numbers around the maximum value retvalint = new DBR_TIME_Int(new int[] { Integer.MAX_VALUE - (secondsIntoYear - 1000) }); } else { // Check for some numbers around 0 retvalint = new DBR_TIME_Int(new int[] { (secondsIntoYear - 2000) }); } retvalint.setTimeStamp(convertSecondsIntoYear2JCATimeStamp(secondsIntoYear)); retvalint.setSeverity(1); retvalint.setStatus(0); return retvalint; case DBR_SCALAR_DOUBLE: DBR_TIME_Double retvaldb; if (0 <= secondsIntoYear && secondsIntoYear < 1000) { // Check for some numbers around the minimum value retvaldb = new DBR_TIME_Double(new double[] { (Double.MIN_VALUE + secondsIntoYear) }); } else if (1000 <= secondsIntoYear && secondsIntoYear < 2000) { // Check for some numbers around the maximum value retvaldb = new DBR_TIME_Double(new double[] { (Double.MAX_VALUE - (secondsIntoYear - 1000)) }); } else { // Check for some numbers around 0. Divide by a large number to make sure we cater to the number of precision digits retvaldb = new DBR_TIME_Double( new double[] { ((secondsIntoYear - 2000.0) / (secondsIntoYear * 1000000)) }); } retvaldb.setTimeStamp(convertSecondsIntoYear2JCATimeStamp(secondsIntoYear)); retvaldb.setSeverity(1); retvaldb.setStatus(0); return retvaldb; case DBR_WAVEFORM_STRING: DBR_TIME_String retvst; // Varying number of copies of a typical value retvst = new DBR_TIME_String( Collections.nCopies(secondsIntoYear, Integer.toString(secondsIntoYear)).toArray(new String[0])); retvst.setTimeStamp(convertSecondsIntoYear2JCATimeStamp(secondsIntoYear)); retvst.setSeverity(1); retvst.setStatus(0); return retvst; case DBR_WAVEFORM_SHORT: DBR_TIME_Short retvsh; retvsh = new DBR_TIME_Short( ArrayUtils.toPrimitive(Collections.nCopies(1, (short) secondsIntoYear).toArray(new Short[0]))); retvsh.setTimeStamp(convertSecondsIntoYear2JCATimeStamp(secondsIntoYear)); retvsh.setSeverity(1); retvsh.setStatus(0); return retvsh; case DBR_WAVEFORM_FLOAT: DBR_TIME_Float retvf; // Varying number of copies of a typical value retvf = new DBR_TIME_Float(ArrayUtils.toPrimitive( Collections.nCopies(secondsIntoYear, (float) Math.cos(secondsIntoYear * Math.PI / 3600)) .toArray(new Float[0]))); retvf.setTimeStamp(convertSecondsIntoYear2JCATimeStamp(secondsIntoYear)); retvf.setSeverity(1); retvf.setStatus(0); return retvf; case DBR_WAVEFORM_ENUM: DBR_TIME_Enum retven; retven = new DBR_TIME_Enum(ArrayUtils .toPrimitive(Collections.nCopies(1024, (short) secondsIntoYear).toArray(new Short[0]))); retven.setTimeStamp(convertSecondsIntoYear2JCATimeStamp(secondsIntoYear)); retven.setSeverity(1); retven.setStatus(0); return retven; case DBR_WAVEFORM_BYTE: DBR_TIME_Byte retvb; // Large number of elements in the array retvb = new DBR_TIME_Byte(ArrayUtils.toPrimitive(Collections .nCopies(65536 * secondsIntoYear, ((byte) (secondsIntoYear % 255))).toArray(new Byte[0]))); retvb.setTimeStamp(convertSecondsIntoYear2JCATimeStamp(secondsIntoYear)); retvb.setSeverity(1); retvb.setStatus(0); return retvb; case DBR_WAVEFORM_INT: DBR_TIME_Int retvint; // Varying number of copies of a typical value retvint = new DBR_TIME_Int(ArrayUtils.toPrimitive(Collections .nCopies(secondsIntoYear, secondsIntoYear * secondsIntoYear).toArray(new Integer[0]))); retvint.setTimeStamp(convertSecondsIntoYear2JCATimeStamp(secondsIntoYear)); retvint.setSeverity(1); retvint.setStatus(0); return retvint; case DBR_WAVEFORM_DOUBLE: DBR_TIME_Double retvd; // Varying number of copies of a typical value retvd = new DBR_TIME_Double(ArrayUtils.toPrimitive(Collections .nCopies(secondsIntoYear, Math.sin(secondsIntoYear * Math.PI / 3600)).toArray(new Double[0]))); retvd.setTimeStamp(convertSecondsIntoYear2JCATimeStamp(secondsIntoYear)); retvd.setSeverity(1); retvd.setStatus(0); return retvd; case DBR_V4_GENERIC_BYTES: throw new RuntimeException("Currently don't support " + type + " when generating sample data"); default: throw new RuntimeException("We seemed to have missed a DBR type when generating sample data"); } }
From source file:dk.netarkivet.harvester.harvesting.frontier.FrontierReportLine.java
/** * Parses the token.//from w ww .j av a 2 s .c o m * * @param dblToken token to parse. * @return parsed value or default value if value is empty or unparsable. */ private static double parseDouble(String dblToken) { if (EMPTY_VALUE_TOKEN.equals(dblToken)) { return Double.MIN_VALUE; } try { return Double.parseDouble(dblToken); } catch (NumberFormatException e) { // Strange data my occur here, but it's harmless return Double.MIN_VALUE; } }