cimbstockformat.java
来自「JStock是一个免费股市软件」· Java 代码 · 共 363 行 · 第 1/2 页
JAVA
363 行
/*
* CIMBStockFormat.java
*
* Created on April 16, 2007, 12:43 AM
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* Copyright (C) 2007 Cheok YanCheng <yccheok@yahoo.com>
*/
package org.yccheok.jstock.engine;
import java.util.*;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
*
* @author yccheok
*/
public class CIMBStockFormat implements StockFormat {
/** Creates a new instance of CIMBStockFormat */
private CIMBStockFormat() {
}
public java.util.List<Stock> parse(String source)
{
java.util.List<Stock> stocks = new java.util.ArrayList<Stock>();
// We will use current time in client computer, if we are unable to retrieve time
// information from the server.
java.util.Calendar calendar = Calendar.getInstance();
String time = Utils.subString(source, "--_BeginFeedTime_", "--_EndFeedTime_").trim();
if(time.length() != 0) {
try {
java.text.SimpleDateFormat dateFormat = (java.text.SimpleDateFormat)java.text.DateFormat.getInstance();
dateFormat.applyPattern("HH:mm:ss");
java.util.Date serverDate = dateFormat.parse(time);
Calendar container = new GregorianCalendar();
container.setTime(serverDate);
// After setTime, container only contains correct time, but not date.
// calendar only contains correct date, but not time. Now, let's make calendar
// contain both correct date and time,
calendar.set(Calendar.HOUR_OF_DAY, container.get(Calendar.HOUR_OF_DAY));
calendar.set(Calendar.MINUTE, container.get(Calendar.MINUTE));
calendar.set(Calendar.SECOND, container.get(Calendar.SECOND));
}
catch(java.text.ParseException exp) {
log.error("", exp);
}
}
String data = Utils.subString(source, "--_BeginData_", "--_EndData_").trim();
if(data.length() != 0) {
String[] stockDatas = data.split("\\r\\n");
for(String stockData :stockDatas) {
final String trimedStockData = stockData.trim();
if(trimedStockData.length() != 0) {
String[] stockFields = trimedStockData.split("\\|");
Code code;
Symbol symbol;
String name;
Stock.Board board;
Stock.Industry industry;
double openPrice;
double lastPrice;
double highPrice;
double lowPrice;
int volume;
double changePrice;
double changePricePercentage;
int lastVolume;
double buyPrice;
int buyQuantity;
double sellPrice;
int sellQuantity;
double secondBuyPrice;
int secondBuyQuantity;
double secondSellPrice;
int secondSellQuantity;
double thirdBuyPrice;
int thirdBuyQuantity;
double thirdSellPrice;
int thirdSellQuantity;
if(stockFields.length > THIRD_SELL_QUANTITY_TOKEN_INDEX) {
try
{
// 4065 |PPB|PPB GROUP BHD |0101|CONSUMER |A|Y|MYL4065OO008|N|R|1|7.5|7.75|7.75|7.5|Y|3905|0.25|3.33|1|7.7|1|7.75|68|7.6|196|7.8|750|7.55|20|7.85|165|0901|7.5|7.75|0100|1185499882|0|0|0|1324|2581|38|45|2961230.0|1.0
final String tmp = stockFields[3];
if(tmp.length() < 4) continue;
Stock.Board tmpBoard = stringToBoardMap.get(tmp.substring(0, 2));
Stock.Industry tmpIndustry = stringToIndustryMap.get(tmp.substring(2, 4));
if(tmpBoard == null) tmpBoard = Stock.Board.Unknown;
if(tmpIndustry == null) tmpIndustry = Stock.Industry.Unknown;
// Yahoo format is our key reference format. This is to avoid problem occur for different
// stock code format found in different stock servers.
code = Utils.toYahooFormat(Code.newInstance(stockFields[CODE_TOKEN_INDEX].trim()), Country.Malaysia);
symbol = Symbol.newInstance(stockFields[SYMBOL_TOKEN_INDEX].trim());
name = stockFields[NAME_TOKEN_INDEX].trim();
board = tmpBoard;
industry = tmpIndustry;
// industry = stockFields[INDUSTRY_TOKEN_INDEX].trim();
openPrice = Double.parseDouble(stockFields[OPEN_PRICE_TOKEN_INDEX]);
lastPrice = Double.parseDouble(stockFields[LAST_PRICE_TOKEN_INDEX]);
highPrice = Double.parseDouble(stockFields[HIGH_PRICE_TOKEN_INDEX]);
lowPrice = Double.parseDouble(stockFields[LOW_PRICE_TOKEN_INDEX]);
volume = Integer.parseInt(stockFields[VOLUME_TOKEN_INDEX]);
changePrice = Double.parseDouble(stockFields[CHANGE_PRICE_TOKEN_INDEX]);
changePricePercentage = Double.parseDouble(stockFields[CHANGE_PRICE_PERCENTAGE_TOKEN_INDEX]);
lastVolume = Integer.parseInt(stockFields[LAST_VOLUME_TOKEN_INDEX]);
buyPrice = Double.parseDouble(stockFields[BUY_PRICE_TOKEN_INDEX]);
buyQuantity = Integer.parseInt(stockFields[BUY_QUANTITY_TOKEN_INDEX]);
sellPrice = Double.parseDouble(stockFields[SELL_PRICE_TOKEN_INDEX]);
sellQuantity = Integer.parseInt(stockFields[SELL_QUANTITY_TOKEN_INDEX]);
secondBuyPrice = Double.parseDouble(stockFields[SECOND_BUY_PRICE_TOKEN_INDEX]);
secondBuyQuantity = Integer.parseInt(stockFields[SECOND_BUY_QUANTITY_TOKEN_INDEX]);
secondSellPrice = Double.parseDouble(stockFields[SECOND_SELL_PRICE_TOKEN_INDEX]);
secondSellQuantity = Integer.parseInt(stockFields[SECOND_SELL_QUANTITY_TOKEN_INDEX]);
thirdBuyPrice = Double.parseDouble(stockFields[THIRD_BUY_PRICE_TOKEN_INDEX]);
thirdBuyQuantity = Integer.parseInt(stockFields[THIRD_BUY_QUANTITY_TOKEN_INDEX]);
thirdSellPrice = Double.parseDouble(stockFields[THIRD_SELL_PRICE_TOKEN_INDEX]);
thirdSellQuantity = Integer.parseInt(stockFields[THIRD_SELL_QUANTITY_TOKEN_INDEX]);
Stock stock = new Stock(
code,
symbol,
name,
board,
industry,
openPrice,
lastPrice,
highPrice,
lowPrice,
volume,
changePrice,
changePricePercentage,
lastVolume,
buyPrice,
buyQuantity,
sellPrice,
sellQuantity,
secondBuyPrice,
secondBuyQuantity,
secondSellPrice,
secondSellQuantity,
thirdBuyPrice,
thirdBuyQuantity,
thirdSellPrice,
thirdSellQuantity,
calendar
);
stocks.add(stock);
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?