List of usage examples for java.util Arrays binarySearch
public static int binarySearch(Object[] a, Object key)
From source file:com.indeed.lsmtree.core.TestStore.java
public void testStore(StorageType storageType, CompressionCodec codec) throws Exception { File indexDir = new File(tmpDir, "index"); indexDir.mkdirs();//from ww w . ja va2 s .co m File indexLink = new File(tmpDir, "indexlink"); PosixFileOperations.link(indexDir, indexLink); File storeDir = new File(indexLink, "store"); Store<Integer, Long> store = new StoreBuilder<Integer, Long>(storeDir, new IntSerializer(), new LongSerializer()).setMaxVolatileGenerationSize(8 * 1024 * 1024).setStorageType(storageType) .setCodec(codec).build(); final Random r = new Random(0); final int[] ints = new int[treeSize]; for (int i = 0; i < ints.length; i++) { ints[i] = r.nextInt(); } for (final int i : ints) { store.put(i, (long) i); assertTrue(store.get(i) == i); } for (final int i : ints) { assertTrue(store.get(i) == i); } store.close(); store.waitForCompactions(); store = new StoreBuilder<Integer, Long>(storeDir, new IntSerializer(), new LongSerializer()) .setMaxVolatileGenerationSize(8 * 1024 * 1024).setStorageType(storageType).setCodec(codec).build(); Arrays.sort(ints); Iterator<Store.Entry<Integer, Long>> iterator = store.iterator(); int index = 0; while (iterator.hasNext()) { Store.Entry<Integer, Long> next = iterator.next(); int current = ints[index]; assertTrue(next.getKey() == ints[index]); assertTrue(next.getValue() == ints[index]); while (index < ints.length && ints[index] == current) { index++; } } assertTrue(index == ints.length); final BitSet deleted = new BitSet(); for (int i = 0; i < ints.length / 10; i++) { int deletionIndex = r.nextInt(ints.length); deleted.set(deletionIndex, true); for (int j = deletionIndex - 1; j >= 0; j--) { if (ints[j] == ints[deletionIndex]) { deleted.set(j, true); } else { break; } } for (int j = deletionIndex + 1; j < ints.length; j++) { if (ints[j] == ints[deletionIndex]) { deleted.set(j, true); } else { break; } } store.delete(ints[deletionIndex]); assertNull(store.get(ints[deletionIndex])); } iterator = store.iterator(); index = 0; while (iterator.hasNext()) { Store.Entry<Integer, Long> next = iterator.next(); while (deleted.get(index)) index++; int current = ints[index]; assertTrue(next.getKey() == ints[index]); assertTrue(next.getValue() == ints[index]); while (index < ints.length && ints[index] == current) { index++; } } while (deleted.get(index)) index++; assertTrue(index == ints.length); final int max = ints[ints.length - 1]; final AtomicInteger done = new AtomicInteger(8); for (int i = 0; i < done.get(); i++) { final int thread = i; final Store<Integer, Long> finalStore = store; new Thread(new Runnable() { @Override public void run() { try { Random r = new Random(thread); for (int i = 0; i < treeSize; i++) { int rand = r.nextInt(); int insertionindex = Arrays.binarySearch(ints, rand); Store.Entry<Integer, Long> next = finalStore.ceil(rand); boolean found = next != null; if (insertionindex >= 0 && deleted.get(insertionindex)) { assertNull(finalStore.get(ints[insertionindex])); } else { assertTrue(found == (rand <= max)); if (found) { assertTrue(next.getKey() >= rand); assertTrue(next.getKey().longValue() == next.getValue()); if (insertionindex >= 0) { assertTrue(rand == ints[insertionindex]); assertTrue(next.getKey() == rand); Long result = finalStore.get(rand); assertTrue(result == rand); } else { int nextIndex = ~insertionindex; while (deleted.get(nextIndex) && nextIndex < ints.length) nextIndex++; if (nextIndex < ints.length) { if (insertionindex != -1) assertTrue(ints[(~insertionindex) - 1] < rand); assertTrue(ints[nextIndex] + " != " + next.getKey(), ints[nextIndex] == next.getKey()); } Long result = finalStore.get(rand); assertTrue(result == null); } } } } } catch (IOException e) { throw new RuntimeException(e); } finally { done.decrementAndGet(); } } }).start(); } while (done.get() > 0) { Thread.yield(); } store.close(); }
From source file:com.xpn.xwiki.plugin.graphviz.GraphVizMacro.java
/** * {@inheritDoc}// w ww . j a va2s. com * * @see org.radeox.macro.BaseMacro#execute(Writer, MacroParameter) */ @Override public void execute(Writer writer, MacroParameter params) throws IllegalArgumentException, IOException { RenderContext context = params.getContext(); RenderEngine engine = context.getRenderEngine(); XWikiContext xcontext = ((XWikiRadeoxRenderEngine) engine).getXWikiContext(); XWiki xwiki = xcontext.getWiki(); GraphVizPlugin plugin = (GraphVizPlugin) xwiki.getPlugin("graphviz", xcontext); // If the plugin is not loaded if (plugin == null) { writer.write("Graphviz plugin not loaded"); return; } boolean dot = !("neato").equals(params.get("type")); String title = nullifyBadParameter(params.get("title", 0)); String height = nullifyBadParameter(params.get("height", 1)); String width = nullifyBadParameter(params.get("width", 2)); String alt = nullifyBadParameter(params.get("alt", 3)); String format = nullifyBadParameter(params.get("format", 4)); if (StringUtils.isBlank(format)) { format = "png"; } String dottext = params.getContent(); // please KEEP THE ARRAYS SORTED final String[] embedTagFormats = new String[] { "svg", "svgz" }; final String[] plainTextFormats = new String[] { "canon", "cmapx", "cmapx_np", "dot", "imap", "imap_np", "plain", "plain-ext", "xdot" }; if (Arrays.binarySearch(plainTextFormats, format) >= 0) { // Producing plain text output byte[] graphvizOutput = plugin.getDotImage(dottext, format, dot); writer.write(new String(graphvizOutput)); } else if (Arrays.binarySearch(embedTagFormats, format) >= 0) { // Producing object tag output final String resultURL = plugin.getDotResultURL(dottext, dot, format, xcontext); writeObject(writer, height, width, title, alt, resultURL, plugin); } else { // Producing img tag output writeImage(writer, dottext, dot, format, height, width, title, alt, params, plugin, xcontext); } }
From source file:CharMap.java
/** * Returns the value to which the specified key is mapped, or {@code null} * if this map contains no mapping for the key. *///from ww w . j a va 2 s . c o m @SuppressWarnings("unchecked") public V get(char key) { int pos = Arrays.binarySearch(keyIndices, key); return (pos >= 0) ? (V) (values[pos]) : null; }
From source file:com.opengamma.analytics.financial.interestrate.swaption.provider.SwaptionPhysicalFixedIborLMMDDMethod.java
/** * Computes the present value of the Physical delivery swaption. * @param swaption The swaption./*from w w w.ja v a2 s . c o m*/ * @param lmmData The LMM and multi-curves provider. * @return The present value. */ public MultipleCurrencyAmount presentValue(final SwaptionPhysicalFixedIbor swaption, final LiborMarketModelDisplacedDiffusionProviderInterface lmmData) { ArgumentChecker.notNull(swaption, "Swaption"); ArgumentChecker.notNull(lmmData, "LMM provider"); final Currency ccy = swaption.getCurrency(); final MulticurveProviderInterface multicurves = lmmData.getMulticurveProvider(); final LiborMarketModelDisplacedDiffusionParameters parameters = lmmData.getLMMParameters(); // 1. Swaption CFE preparation final AnnuityPaymentFixed cfe = swaption.getUnderlyingSwap().accept(CFEC, multicurves); final int nbCFInit = cfe.getNumberOfPayments(); final double multFact = Math.signum(cfe.getNthPayment(0).getAmount()); final boolean isCall = (cfe.getNthPayment(0).getAmount() < 0); final double[] cftInit = new double[nbCFInit]; final double[] cfaInit = new double[nbCFInit]; for (int loopcf = 0; loopcf < nbCFInit; loopcf++) { cftInit[loopcf] = cfe.getNthPayment(loopcf).getPaymentTime(); cfaInit[loopcf] = cfe.getNthPayment(loopcf).getAmount() * -multFact; } final double timeToExpiry = swaption.getTimeToExpiry(); // 2. Model data final int nbFactor = parameters.getNbFactor(); final double[][] volLMM = parameters.getVolatility(); final double[] timeLMM = parameters.getIborTime(); // 3. Link cfe dates to lmm final int[] indCFDate = new int[nbCFInit]; int indStart = nbCFInit - 1; int indEnd = 0; for (int loopcf = 0; loopcf < nbCFInit; loopcf++) { indCFDate[loopcf] = Arrays.binarySearch(timeLMM, cftInit[loopcf]); if (indCFDate[loopcf] < 0) { if (timeLMM[-indCFDate[loopcf] - 1] - cftInit[loopcf] < TIME_TOLERANCE) { indCFDate[loopcf] = -indCFDate[loopcf] - 1; } else { if (cftInit[loopcf] - timeLMM[-indCFDate[loopcf] - 2] < TIME_TOLERANCE) { indCFDate[loopcf] = -indCFDate[loopcf] - 2; } else { Validate.isTrue(true, "Instrument time incompatible with LMM parametrisation"); } } } if (indCFDate[loopcf] < indStart) { indStart = indCFDate[loopcf]; } if (indCFDate[loopcf] > indEnd) { indEnd = indCFDate[loopcf]; } } final int nbCF = indEnd - indStart + 1; final double[] cfa = new double[nbCF]; for (int loopcf = 0; loopcf < nbCFInit; loopcf++) { cfa[indCFDate[loopcf] - indStart] = cfaInit[loopcf]; } final double[] cft = new double[nbCF]; System.arraycopy(timeLMM, indStart, cft, 0, nbCF); final double[] dfLMM = new double[nbCF]; for (int loopcf = 0; loopcf < nbCF; loopcf++) { dfLMM[loopcf] = multicurves.getDiscountFactor(ccy, cft[loopcf]); } final double[][] gammaLMM = new double[nbCF - 1][nbFactor]; final double[] deltaLMM = new double[nbCF - 1]; System.arraycopy(parameters.getAccrualFactor(), indStart, deltaLMM, 0, nbCF - 1); final double[] aLMM = new double[nbCF - 1]; System.arraycopy(parameters.getDisplacement(), indStart, aLMM, 0, nbCF - 1); final double[] liborLMM = new double[nbCF - 1]; final double amr = parameters.getMeanReversion(); for (int loopcf = 0; loopcf < nbCF - 1; loopcf++) { gammaLMM[loopcf] = volLMM[indStart + loopcf]; liborLMM[loopcf] = (dfLMM[loopcf] / dfLMM[loopcf + 1] - 1.0d) / deltaLMM[loopcf]; } // TODO: 4. cfe modification (for roller coasters) final double[] cfaMod = new double[nbCF + 1]; final double cfaMod0 = cfa[0]; cfaMod[0] = cfaMod0; // modified strike cfaMod[1] = 0.0; System.arraycopy(cfa, 1, cfaMod, 2, nbCF - 1); // 5. Pricing algorithm final double[] p0 = new double[nbCF]; final double[] dP = new double[nbCF]; double b0 = 0; for (int loopcf = 0; loopcf < nbCF; loopcf++) { p0[loopcf] = dfLMM[loopcf] / dfLMM[0]; dP[loopcf] = cfaMod[loopcf + 1] * p0[loopcf]; b0 += dP[loopcf]; } final double bK = -cfaMod0; final double bM = (b0 + bK) / 2.0d; final double meanReversionImpact = Math.abs(amr) < 1.0E-6 ? timeToExpiry : (Math.exp(2.0d * amr * timeToExpiry) - 1.0d) / (2.0d * amr); // To handle 0 mean reversion. final double[] rate0Ratio = new double[nbCF - 1]; final double[][] mu0 = new double[nbCF - 1][nbFactor]; for (int loopcf = 0; loopcf < nbCF - 1; loopcf++) { rate0Ratio[loopcf] = (liborLMM[loopcf] + aLMM[loopcf]) / (liborLMM[loopcf] + 1 / deltaLMM[loopcf]); } for (int loopfact = 0; loopfact < nbFactor; loopfact++) { mu0[0][loopfact] = rate0Ratio[0] * gammaLMM[0][loopfact]; } for (int loopcf = 1; loopcf < nbCF - 1; loopcf++) { for (int loopfact = 0; loopfact < nbFactor; loopfact++) { mu0[loopcf][loopfact] = mu0[loopcf - 1][loopfact] + rate0Ratio[loopcf] * gammaLMM[loopcf][loopfact]; } } final double[] tau = new double[nbCF]; final double[] tau2 = new double[nbCF]; for (int loopcf = 0; loopcf < nbCF - 1; loopcf++) { for (int loopfact = 0; loopfact < nbFactor; loopfact++) { tau2[loopcf + 1] += mu0[loopcf][loopfact] * mu0[loopcf][loopfact]; } tau2[loopcf + 1] = tau2[loopcf + 1] * meanReversionImpact; tau[loopcf + 1] = Math.sqrt(tau2[loopcf + 1]); } double sumNum = -bM; double sumDen = 0; for (int loopcf = 0; loopcf < nbCF; loopcf++) { sumNum += dP[loopcf] - dP[loopcf] * tau2[loopcf] / 2.0; sumDen += dP[loopcf] * tau[loopcf]; } final double xBar = sumNum / sumDen; final double[] pM = new double[nbCF]; for (int loopcf = 0; loopcf < nbCF; loopcf++) { pM[loopcf] = p0[loopcf] * (1 - xBar * tau[loopcf] - tau2[loopcf] / 2.0); } final double[] liborM = new double[nbCF - 1]; final double[] alphaM = new double[nbCF]; for (int loopcf = 0; loopcf < nbCF - 1; loopcf++) { liborM[loopcf] = (pM[loopcf] / pM[loopcf + 1] - 1.0d) / deltaLMM[loopcf]; } for (int loopcf = 0; loopcf < nbCF; loopcf++) { alphaM[loopcf] = cfaMod[loopcf + 1] * pM[loopcf] / bM; } final double[] rateMRatio = new double[nbCF - 1]; final double[][] muM = new double[nbCF - 1][nbFactor]; for (int loopcf = 0; loopcf < nbCF - 1; loopcf++) { rateMRatio[loopcf] = (liborM[loopcf] + aLMM[loopcf]) / (liborM[loopcf] + 1 / deltaLMM[loopcf]); } for (int loopfact = 0; loopfact < nbFactor; loopfact++) { muM[0][loopfact] = rateMRatio[0] * gammaLMM[0][loopfact]; } for (int loopcf = 1; loopcf < nbCF - 1; loopcf++) { for (int loopfact = 0; loopfact < nbFactor; loopfact++) { muM[loopcf][loopfact] = muM[loopcf - 1][loopfact] + rateMRatio[loopcf] * gammaLMM[loopcf][loopfact]; } } double normSigmaM = 0; final double[] sigmaM = new double[nbFactor]; for (int loopfact = 0; loopfact < nbFactor; loopfact++) { for (int loopcf = 0; loopcf < nbCF - 1; loopcf++) { sigmaM[loopfact] += alphaM[loopcf + 1] * muM[loopcf][loopfact]; } normSigmaM += sigmaM[loopfact] * sigmaM[loopfact]; } final double impliedBlackVol = Math.sqrt(normSigmaM * meanReversionImpact); final EuropeanVanillaOption option = new EuropeanVanillaOption(bK, 1, isCall); final BlackPriceFunction blackFunction = new BlackPriceFunction(); final BlackFunctionData dataBlack = new BlackFunctionData(b0, 1.0, impliedBlackVol); final Function1D<BlackFunctionData, Double> func = blackFunction.getPriceFunction(option); final double pv = dfLMM[0] * func.evaluate(dataBlack); return MultipleCurrencyAmount.of(swaption.getUnderlyingSwap().getFirstLeg().getCurrency(), pv * (swaption.isLong() ? 1.0 : -1.0)); }
From source file:com.opengamma.analytics.math.surface.InterpolatedFromCurvesSurfaceAdditiveShiftFunction.java
/** * {@inheritDoc}//from ww w . j ava2 s. co m * @throws UnsupportedOperationException If the <i>x</i> (<i>y</i>) positions of the shifts do not coincide with one of the <i>x</i> (<i>y</i>) intersections * of the curves with the axis */ @Override public InterpolatedFromCurvesDoublesSurface evaluate(final InterpolatedFromCurvesDoublesSurface surface, final double[] xShift, final double[] yShift, final double[] shift, final String newName) { Validate.notNull(surface, "surface"); Validate.notNull(xShift, "x shifts"); Validate.notNull(yShift, "y shifts"); Validate.notNull(shift, "shifts"); final int n = xShift.length; if (n == 0) { return InterpolatedFromCurvesDoublesSurface.from(surface.isXZCurves(), surface.getPoints(), surface.getCurves(), surface.getInterpolator(), newName); } Validate.isTrue(n == yShift.length && n == shift.length); final boolean xzCurves = surface.isXZCurves(); final double[] points = surface.getPoints(); if (xzCurves) { final Curve<Double, Double>[] newCurves = Arrays.copyOf(surface.getCurves(), points.length); for (int i = 0; i < n; i++) { final int index = Arrays.binarySearch(points, yShift[i]); boolean foundValue = false; if (index >= 0) { newCurves[index] = CurveShiftFunctionFactory.getShiftedCurve(newCurves[index], xShift[i], shift[i]); foundValue = true; } if (!foundValue) { throw new UnsupportedOperationException( "Cannot get shift for y-value not in original list of curves: asked for " + yShift[i]); } } return InterpolatedFromCurvesDoublesSurface.fromSorted(xzCurves, points, newCurves, surface.getInterpolator(), newName); } final Curve<Double, Double>[] newCurves = Arrays.copyOf(surface.getCurves(), points.length); for (int i = 0; i < n; i++) { final int index = Arrays.binarySearch(points, xShift[i]); boolean foundValue = false; if (index >= 0) { newCurves[index] = CurveShiftFunctionFactory.getShiftedCurve(newCurves[index], yShift[i], shift[i]); foundValue = true; } if (!foundValue) { throw new UnsupportedOperationException( "Cannot get shift for x-value not in original list of curves: asked for " + xShift[i]); } } return InterpolatedFromCurvesDoublesSurface.fromSorted(xzCurves, points, newCurves, surface.getInterpolator(), newName); }
From source file:org.jtheque.movies.services.MoviesServiceTest.java
License:asdf
@Test public void getMoviesOfCategory() { Collection<Movie> movies = moviesService.getMovies(daoCategories.getCategory("Category 4"), false); assertEquals(2, movies.size());/*w w w.j a v a 2 s. c o m*/ String[] moviesCategory4 = { "Movie 3", "Movie 4" }; for (Movie movie : movies) { if (Arrays.binarySearch(moviesCategory4, movie.getTitle()) == -1) { fail("Movie not in results"); } } }
From source file:Main.java
/** * @param source//from w w w. j a v a 2 s . c om * @param escapedChars * @param escapeChar * @return the String escaped * @since 1.5.1 */ public static String escape(String source, final char[] escapedChars, char escapeChar) { if (source == null) { return null; } char[] eqc = new char[escapedChars.length]; System.arraycopy(escapedChars, 0, eqc, 0, escapedChars.length); Arrays.sort(eqc); StringBuilder buffer = new StringBuilder(source.length()); @SuppressWarnings("unused") int escapeCount = 0; for (int i = 0; i < source.length(); i++) { final char c = source.charAt(i); int result = Arrays.binarySearch(eqc, c); if (result > -1) { buffer.append(escapeChar); escapeCount++; } buffer.append(c); } return buffer.toString(); }
From source file:com.opengamma.util.timeseries.fast.integer.FastArrayIntDoubleTimeSeries.java
@Override public FastIntDoubleTimeSeries subSeriesFast(final int startTime, final int endTime) { if (isEmpty()) { return EMPTY_SERIES; }//from w ww .j av a 2 s. c om // throw new NoSuchElementException("Series is empty") int startPos = Arrays.binarySearch(_times, startTime); int endPos = (endTime == Integer.MIN_VALUE) ? _times.length : Arrays.binarySearch(_times, endTime); // if either is -1, make it zero startPos = startPos >= 0 ? startPos : -(startPos + 1); endPos = endPos >= 0 ? endPos : -(endPos + 1); final int length = endPos - startPos; // trying it out anyway. if (endPos >= _times.length) { endPos--; } final int[] resultTimes = new int[length]; final double[] resultValues = new double[length]; System.arraycopy(_times, startPos, resultTimes, 0, length); System.arraycopy(_values, startPos, resultValues, 0, length); return new FastArrayIntDoubleTimeSeries(getEncoding(), resultTimes, resultValues); }
From source file:com.linkedin.pinot.core.segment.index.readers.ImmutableDictionaryReaderTest.java
@Test public void testIntDictionary() throws Exception { try (IntDictionary intDictionary = new IntDictionary( PinotDataBuffer.fromFile(new File(TEMP_DIR, INT_COLUMN_NAME + V1Constants.Dict.FILE_EXTENSION), ReadMode.mmap, FileChannel.MapMode.READ_ONLY, INT_COLUMN_NAME), NUM_VALUES)) {// ww w . j ava 2s. c o m for (int i = 0; i < NUM_VALUES; i++) { Assert.assertEquals(intDictionary.get(i).intValue(), _intValues[i]); Assert.assertEquals(intDictionary.getIntValue(i), _intValues[i]); Assert.assertEquals(intDictionary.getLongValue(i), _intValues[i]); Assert.assertEquals(intDictionary.getFloatValue(i), _intValues[i], 0.0f); Assert.assertEquals(intDictionary.getDoubleValue(i), _intValues[i], 0.0); Assert.assertEquals(Integer.parseInt(intDictionary.getStringValue(i)), _intValues[i]); Assert.assertEquals(intDictionary.indexOf(_intValues[i]), i); int randomInt = RANDOM.nextInt(); Assert.assertEquals(intDictionary.insertionIndexOf(randomInt), Arrays.binarySearch(_intValues, randomInt)); } } }
From source file:geovista.readers.csv.GeogCSVReader_old.java
public Object[] readFileStreaming(InputStream is, ArrayList<Integer> columns) { BufferedReader in = new BufferedReader(new InputStreamReader(is)); Iterable<CSVRecord> parser = null; try {/*from ww w. j a v a 2s . co m*/ parser = CSVFormat.DEFAULT.withDelimiter(this.delimiter).parse(in); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } int count = 0; for (CSVRecord rec : parser) { // eDays.add(rec.get(0)); // type.add(rec.get(10) + " - " + rec.get(8)); System.out.println(rec.get(0)); System.out.println(rec.toString()); count++; } // CSVParser shredder = new CSVParser() // CSVParser shredder = new CSVParser(is); // shredder.setCommentStart("#;!"); // shredder.setEscapes("nrtf", "\n\r\t\f"); String[] headers = null; String[] types = null; int[] dataTypes = null; String[][] fileContent = null; int dataBegin; Object[] data; try { // fileContent = shredder.getAllValues(); } catch (Exception ex) { ex.printStackTrace(); } types = fileContent[0];// first line tells us types dataTypes = new int[types.length]; int len; if (types[0].equalsIgnoreCase("int") || types[0].equalsIgnoreCase("double") || types[0].equalsIgnoreCase("string")) { dataBegin = 2; headers = fileContent[1]; data = new Object[headers.length + 1];// plus one for the headers // themselves len = fileContent.length - dataBegin; for (int i = 0; i < headers.length; i++) { if (types[i].equalsIgnoreCase("int")) { data[i + 1] = new int[len]; dataTypes[i] = GeogCSVReader_old.DATA_TYPE_INT; } else if (types[i].equalsIgnoreCase("double")) { data[i + 1] = new double[len]; dataTypes[i] = GeogCSVReader_old.DATA_TYPE_DOUBLE; } else if (types[i].equalsIgnoreCase("string")) { data[i + 1] = new String[len]; dataTypes[i] = GeogCSVReader_old.DATA_TYPE_STRING; } else { throw new IllegalArgumentException("GeogCSVReader.readFile, unknown type = " + types[i]); } } } else { dataBegin = 1; headers = fileContent[0]; data = new Object[headers.length + 1];// plus one for the headers // themselves len = fileContent.length - dataBegin; for (int i = 0; i < headers.length; i++) { String firstString = fileContent[1][i]; String secondString = fileContent[2][i]; String thirdString = fileContent[3][i]; String lastString = fileContent[fileContent[0].length][i]; if (isNumeric(firstString) && isNumeric(secondString) && isNumeric(thirdString) && isNumeric(lastString)) { if (isInt(fileContent, i) == false) { // if (isDouble(firstString) || isDouble(secondString) // || isDouble(thirdString) || isDouble(lastString)) { data[i + 1] = new double[len]; dataTypes[i] = GeogCSVReader_old.DATA_TYPE_DOUBLE; } else { data[i + 1] = new int[len]; dataTypes[i] = GeogCSVReader_old.DATA_TYPE_INT; } } else { data[i + 1] = new String[len]; dataTypes[i] = GeogCSVReader_old.DATA_TYPE_STRING; } } } data[0] = headers; String[] line = null; for (int row = dataBegin; row < len + dataBegin; row++) { line = fileContent[row]; int[] ints = null; double[] doubles = null; String[] strings = null; for (int column = 0; column < line.length; column++) { String item = line[column]; if (dataTypes[column] == GeogCSVReader_old.DATA_TYPE_INT) { if (Arrays.binarySearch(GeogCSVReader_old.NULL_STRINGS, item) >= 0) { ints = (int[]) data[column + 1]; ints[row - dataBegin] = GeogCSVReader_old.NULL_INT; } else { ints = (int[]) data[column + 1]; try { ints[row - dataBegin] = Integer.parseInt(item); } catch (NumberFormatException nfe) { logger.warning("could not parse " + item + " in column " + column); // nfe.printStackTrace(); ints[row - dataBegin] = GeogCSVReader_old.NULL_INT; } } } else if (dataTypes[column] == GeogCSVReader_old.DATA_TYPE_DOUBLE) { if (Arrays.binarySearch(GeogCSVReader_old.NULL_STRINGS, item) >= 0) { doubles = (double[]) data[column + 1]; doubles[row - dataBegin] = GeogCSVReader_old.NULL_DOUBLE; } else { doubles = (double[]) data[column + 1]; doubles[row - dataBegin] = parseDouble(item); } } else if (dataTypes[column] == GeogCSVReader_old.DATA_TYPE_STRING) { strings = (String[]) data[column + 1]; strings[row - dataBegin] = item; } else { throw new IllegalArgumentException("GeogCSVReader.readFile, unknown type = " + types[row]); } // end if } // next column } // next row return data; }