Android Open Source - makler Quote






From Project

Back to project page makler.

License

The source code is released under:

GNU General Public License

If you think the Android project makler listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package pl.net.newton.Makler.db.quote;
/*w  ww  .  ja va2 s.c o m*/
import java.math.BigDecimal;
import java.util.Arrays;
import java.util.Calendar;
import java.util.EnumMap;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;

import android.content.ContentValues;
import android.database.Cursor;
import pl.net.newton.Makler.common.DateFormatUtils;
import pl.net.newton.Makler.common.GpwUtils;
import pl.net.newton.Makler.common.NumberFormatUtils;
import static pl.net.newton.Makler.db.quote.QuoteField.*;

public class Quote {
  private final Map<QuoteField, String> map = new EnumMap<QuoteField, String>(QuoteField.class);

  public Quote(Cursor cursor) {
    for (QuoteField f : QuoteField.values()) {
      final String columnName = f.getDatabaseField();
      final int columnIndex = cursor.getColumnIndex(columnName);
      if (columnIndex != -1) {
        map.put(f, cursor.getString(columnIndex));
      }
    }
  }

  public Quote(String line) {
    final String[] split = StringUtils.split(line, '|');
    for (int i = 0; i < split.length; i++) {
      map.put(QuoteField.values()[i], split[i]);
    }
  }

  public String get(QuoteField field) {
    return map.get(field);
  }

  public BigDecimal getAsDecimal(QuoteField field) {
    return NumberFormatUtils.parseOrNull(get(field));
  }

  public int getAsInt(QuoteField field) {
    return NumberFormatUtils.parseIntOrZero(get(field));
  }

  public Calendar getAsCalendar(QuoteField field) {
    return DateFormatUtils.safeParseTime(get(field));
  }

  public boolean getAsBoolean(QuoteField field) {
    return Boolean.parseBoolean(get(field));
  }

  public BigDecimal chooseKurs() {
    if (get(TKO) != null && GpwUtils.isOvertime(getAsCalendar(UPDATED))) {
      return getAsDecimal(TKO);
    }
    for (QuoteField field : Arrays.asList(QUOTE, TKO, OPEN, REFERENCE)) {
      final BigDecimal v = getAsDecimal(field);
      if (v != null) {
        return v;
      }
    }
    return null;
  }

  public BigDecimal chooseZmiana() {
    if (get(TKO_PERCENT) != null && GpwUtils.isOvertime(getAsCalendar(UPDATED))) {
      return getAsDecimal(TKO_PERCENT);
    }
    for (QuoteField field : Arrays.asList(CHANGE, TKO_PERCENT)) {
      final BigDecimal v = getAsDecimal(field);
      if (v != null) {
        return v;
      }
    }
    return null;
  }

  public String formatAskBid(QuoteField field) {
    final BigDecimal value = getAsDecimal(field);
    if (value != null) {
      switch (value.intValue()) {
        case -1:
          return "PCRO";
        case -2:
          return "PKC";
        default:
          break;
      }
    }
    return NumberFormatUtils.formatNumber(value);
  }

  public ContentValues getContentValue() {
    final ContentValues cv = new ContentValues();
    for (QuoteField f : QuoteField.values()) {
      if (!f.isIncludeInCv()) {
        continue;
      }
      final String v = get(f);
      final String escapedColumn = String.format("`%s`", f.getDatabaseField());
      if (v == null) {
        cv.putNull(escapedColumn);
      } else {
        cv.put(escapedColumn, v);
      }
    }
    return cv;
  }

  @Override
  public String toString() {
    return String.format("%s %s", get(SYMBOL), get(QUOTE));
  }

}




Java Source Code List

pl.net.newton.Makler.common.Configuration.java
pl.net.newton.Makler.common.DateFormatUtils.java
pl.net.newton.Makler.common.GpwUtils.java
pl.net.newton.Makler.common.LocaleUtils.java
pl.net.newton.Makler.common.NumberFormatUtils.java
pl.net.newton.Makler.db.Constants.java
pl.net.newton.Makler.db.DbHelper.java
pl.net.newton.Makler.db.SqlConnection.java
pl.net.newton.Makler.db.alert.AlertBuilder.java
pl.net.newton.Makler.db.alert.AlertChecker.java
pl.net.newton.Makler.db.alert.AlertValue.java
pl.net.newton.Makler.db.alert.Alert.java
pl.net.newton.Makler.db.alert.AlertsDao.java
pl.net.newton.Makler.db.alert.Event.java
pl.net.newton.Makler.db.alert.Subject.java
pl.net.newton.Makler.db.quote.QuoteField.java
pl.net.newton.Makler.db.quote.Quote.java
pl.net.newton.Makler.db.quote.QuotesDao.java
pl.net.newton.Makler.db.service.SqlProvider.java
pl.net.newton.Makler.db.symbol.SymbolBuilder.java
pl.net.newton.Makler.db.symbol.Symbol.java
pl.net.newton.Makler.db.symbol.SymbolsDb.java
pl.net.newton.Makler.db.wallet.WalletDb.java
pl.net.newton.Makler.db.wallet.WalletItemBuilder.java
pl.net.newton.Makler.db.wallet.WalletItem.java
pl.net.newton.Makler.gpw.DefaultQuotesReceiver.java
pl.net.newton.Makler.gpw.QuotesReceiver.java
pl.net.newton.Makler.gpw.ex.GpwException.java
pl.net.newton.Makler.gpw.service.QuotesListener.java
pl.net.newton.Makler.gpw.service.QuotesService.java
pl.net.newton.Makler.gpw.service.UpdatingThread.java
pl.net.newton.Makler.history.BossaProvider.java
pl.net.newton.Makler.history.ByteArrayUtils.java
pl.net.newton.Makler.history.Cache.java
pl.net.newton.Makler.history.ChannelTools.java
pl.net.newton.Makler.history.EntryListWithIndexes.java
pl.net.newton.Makler.history.EntryList.java
pl.net.newton.Makler.history.HistoryFilter.java
pl.net.newton.Makler.history.HistoryProvider.java
pl.net.newton.Makler.history.service.HistoryListener.java
pl.net.newton.Makler.history.service.HistoryService.java
pl.net.newton.Makler.httpClient.Connector.java
pl.net.newton.Makler.receivers.QuotesAlarmReceiver.java
pl.net.newton.Makler.receivers.StartupReceiver.java
pl.net.newton.Makler.service.ServiceManager.java
pl.net.newton.Makler.ui.About.java
pl.net.newton.Makler.ui.AbstractActivity.java
pl.net.newton.Makler.ui.Alerts.java
pl.net.newton.Makler.ui.FullScreenGraph.java
pl.net.newton.Makler.ui.Preferences.java
pl.net.newton.Makler.ui.QuoteDetails.java
pl.net.newton.Makler.ui.Quotes.java
pl.net.newton.Makler.ui.Symbols.java
pl.net.newton.Makler.ui.WalletForm.java
pl.net.newton.Makler.ui.WalletItemCalculator.java
pl.net.newton.Makler.ui.Wallet.java
pl.net.newton.Makler.ui.adapter.AlertsAdapter.java
pl.net.newton.Makler.ui.adapter.QuotesAdapter.java
pl.net.newton.Makler.ui.adapter.SymbolsAdapter.java
pl.net.newton.Makler.ui.adapter.WalletAdapter.java
pl.net.newton.Makler.ui.graph.GraphView.java
pl.net.newton.Makler.ui.graph.MaklerGraphicalView.java