DBase
Posted: Sat Feb 28, 2004 8:53 pm
Anyone have DBase experience? I need to build one to house my historical data and snatch it out to run sims.
Code: Select all
for(int i = 0, length = quotes.length ; i < length ; ++i) {
Quote q = quotes[i] ;
float close = q.close ;
float high = q.high ;
float low = q.low ;
// here starts the interesting bits
...
}
Code: Select all
package com.yourcompany.yourstuff.storage ;
import com.yourcompany.yourstuff.Quote ;
import java.io.FileOutputStream ;
import java.io.ObjectOutputStream ;
import java.io.FileInputStream ;
import java.io.ObjectInputStream ;
import java.io.IOException ;
import java.io.FileNotFoundException ;
public class QuoteStore {
private static final String dataStore = "datastore.bin" ;
private static Quote[]
get(ObjectInputStream s) {
Quote[] quotes = null ;
try {
quotes = (Quote[]) s.readObject() ;
} catch(IOException e) {
} catch(Throwable t) {
} finally {
return quotes ;
}
}
public static Quote[]
get() {
Quote[] quotes = null ;
try {
FileInputStream in = new FileInputStream(dataStore);
ObjectInputStream s = new ObjectInputStream(in);
quotes = get(s) ;
s.close() ;
} catch (FileNotFoundException e) {
} catch (IOException e) {
} finally {
return quotes ;
}
}
private static void
put(Quote[] quotes, ObjectOutputStream s) {
try {
s.writeObject(quotes) ;
} catch(IOException e) {
}
}
public static void
put(Quote[] quotes) {
try {
FileOutputStream out = new FileOutputStream(dataStore) ;
ObjectOutputStream s = new ObjectOutputStream(out) ;
put(quotes, s) ;
s.close() ;
} catch (FileNotFoundException e) {
} catch (IOException e) {
}
}
}
Code: Select all
Quote[] quotes = QuoteStore.get() ;
for(int i = 0, length = quotes.length ; i < length ; ++i) {
Quote q = quotes[i] ;
// as before ...
Code: Select all
class Quote {
public float open ;
public float high ;
public float low ;
public float close ;
}