Made sortable types private

master
Michael Dvorkin 11 years ago
parent 8f55a6acf7
commit c514053803
  1. 187
      sorter.go

@ -1,6 +1,7 @@
// Copyright (c) 2013 by Michael Dvorkin. All Rights Reserved. // Copyright (c) 2013 by Michael Dvorkin. All Rights Reserved.
// Use of this source code is governed by a MIT-style // Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
//-----------------------------------------------------------------------------
package mop package mop
@ -10,73 +11,73 @@ import (
`strconv` `strconv`
) )
type Sortable []Stock type sortable []Stock
func (list Sortable) Len() int { return len(list) } func (list sortable) Len() int { return len(list) }
func (list Sortable) Swap(i, j int) { list[i], list[j] = list[j], list[i] } func (list sortable) Swap(i, j int) { list[i], list[j] = list[j], list[i] }
type ByTickerAsc struct { Sortable } type byTickerAsc struct { sortable }
type ByLastTradeAsc struct { Sortable } type byLastTradeAsc struct { sortable }
type ByChangeAsc struct { Sortable } type byChangeAsc struct { sortable }
type ByChangePctAsc struct { Sortable } type byChangePctAsc struct { sortable }
type ByOpenAsc struct { Sortable } type byOpenAsc struct { sortable }
type ByLowAsc struct { Sortable } type byLowAsc struct { sortable }
type ByHighAsc struct { Sortable } type byHighAsc struct { sortable }
type ByLow52Asc struct { Sortable } type byLow52Asc struct { sortable }
type ByHigh52Asc struct { Sortable } type byHigh52Asc struct { sortable }
type ByVolumeAsc struct { Sortable } type byVolumeAsc struct { sortable }
type ByAvgVolumeAsc struct { Sortable } type byAvgVolumeAsc struct { sortable }
type ByPeRatioAsc struct { Sortable } type byPeRatioAsc struct { sortable }
type ByDividendAsc struct { Sortable } type byDividendAsc struct { sortable }
type ByYieldAsc struct { Sortable } type byYieldAsc struct { sortable }
type ByMarketCapAsc struct { Sortable } type byMarketCapAsc struct { sortable }
type ByTickerDesc struct { Sortable } type byTickerDesc struct { sortable }
type ByLastTradeDesc struct { Sortable } type byLastTradeDesc struct { sortable }
type ByChangeDesc struct { Sortable } type byChangeDesc struct { sortable }
type ByChangePctDesc struct { Sortable } type byChangePctDesc struct { sortable }
type ByOpenDesc struct { Sortable } type byOpenDesc struct { sortable }
type ByLowDesc struct { Sortable } type byLowDesc struct { sortable }
type ByHighDesc struct { Sortable } type byHighDesc struct { sortable }
type ByLow52Desc struct { Sortable } type byLow52Desc struct { sortable }
type ByHigh52Desc struct { Sortable } type byHigh52Desc struct { sortable }
type ByVolumeDesc struct { Sortable } type byVolumeDesc struct { sortable }
type ByAvgVolumeDesc struct { Sortable } type byAvgVolumeDesc struct { sortable }
type ByPeRatioDesc struct { Sortable } type byPeRatioDesc struct { sortable }
type ByDividendDesc struct { Sortable } type byDividendDesc struct { sortable }
type ByYieldDesc struct { Sortable } type byYieldDesc struct { sortable }
type ByMarketCapDesc struct { Sortable } type byMarketCapDesc struct { sortable }
func (list ByTickerAsc) Less(i, j int) bool { return list.Sortable[i].Ticker < list.Sortable[j].Ticker } func (list byTickerAsc) Less(i, j int) bool { return list.sortable[i].Ticker < list.sortable[j].Ticker }
func (list ByLastTradeAsc) Less(i, j int) bool { return list.Sortable[i].LastTrade < list.Sortable[j].LastTrade } func (list byLastTradeAsc) Less(i, j int) bool { return list.sortable[i].LastTrade < list.sortable[j].LastTrade }
func (list ByChangeAsc) Less(i, j int) bool { return c(list.Sortable[i].Change) < c(list.Sortable[j].Change) } func (list byChangeAsc) Less(i, j int) bool { return c(list.sortable[i].Change) < c(list.sortable[j].Change) }
func (list ByChangePctAsc) Less(i, j int) bool { return c(list.Sortable[i].ChangePct) < c(list.Sortable[j].ChangePct) } func (list byChangePctAsc) Less(i, j int) bool { return c(list.sortable[i].ChangePct) < c(list.sortable[j].ChangePct) }
func (list ByOpenAsc) Less(i, j int) bool { return list.Sortable[i].Open < list.Sortable[j].Open } func (list byOpenAsc) Less(i, j int) bool { return list.sortable[i].Open < list.sortable[j].Open }
func (list ByLowAsc) Less(i, j int) bool { return list.Sortable[i].Low < list.Sortable[j].Low } func (list byLowAsc) Less(i, j int) bool { return list.sortable[i].Low < list.sortable[j].Low }
func (list ByHighAsc) Less(i, j int) bool { return list.Sortable[i].High < list.Sortable[j].High } func (list byHighAsc) Less(i, j int) bool { return list.sortable[i].High < list.sortable[j].High }
func (list ByLow52Asc) Less(i, j int) bool { return list.Sortable[i].Low52 < list.Sortable[j].Low52 } func (list byLow52Asc) Less(i, j int) bool { return list.sortable[i].Low52 < list.sortable[j].Low52 }
func (list ByHigh52Asc) Less(i, j int) bool { return list.Sortable[i].High52 < list.Sortable[j].High52 } func (list byHigh52Asc) Less(i, j int) bool { return list.sortable[i].High52 < list.sortable[j].High52 }
func (list ByVolumeAsc) Less(i, j int) bool { return list.Sortable[i].Volume < list.Sortable[j].Volume } func (list byVolumeAsc) Less(i, j int) bool { return list.sortable[i].Volume < list.sortable[j].Volume }
func (list ByAvgVolumeAsc) Less(i, j int) bool { return list.Sortable[i].AvgVolume < list.Sortable[j].AvgVolume } func (list byAvgVolumeAsc) Less(i, j int) bool { return list.sortable[i].AvgVolume < list.sortable[j].AvgVolume }
func (list ByPeRatioAsc) Less(i, j int) bool { return list.Sortable[i].PeRatio < list.Sortable[j].PeRatio } func (list byPeRatioAsc) Less(i, j int) bool { return list.sortable[i].PeRatio < list.sortable[j].PeRatio }
func (list ByDividendAsc) Less(i, j int) bool { return list.Sortable[i].Dividend < list.Sortable[j].Dividend } func (list byDividendAsc) Less(i, j int) bool { return list.sortable[i].Dividend < list.sortable[j].Dividend }
func (list ByYieldAsc) Less(i, j int) bool { return list.Sortable[i].Yield < list.Sortable[j].Yield } func (list byYieldAsc) Less(i, j int) bool { return list.sortable[i].Yield < list.sortable[j].Yield }
func (list ByMarketCapAsc) Less(i, j int) bool { return m(list.Sortable[i].MarketCap) < m(list.Sortable[j].MarketCap) } func (list byMarketCapAsc) Less(i, j int) bool { return m(list.sortable[i].MarketCap) < m(list.sortable[j].MarketCap) }
func (list ByTickerDesc) Less(i, j int) bool { return list.Sortable[j].Ticker < list.Sortable[i].Ticker } func (list byTickerDesc) Less(i, j int) bool { return list.sortable[j].Ticker < list.sortable[i].Ticker }
func (list ByLastTradeDesc) Less(i, j int) bool { return list.Sortable[j].LastTrade < list.Sortable[i].LastTrade } func (list byLastTradeDesc) Less(i, j int) bool { return list.sortable[j].LastTrade < list.sortable[i].LastTrade }
func (list ByChangeDesc) Less(i, j int) bool { return c(list.Sortable[j].ChangePct) < c(list.Sortable[i].ChangePct) } func (list byChangeDesc) Less(i, j int) bool { return c(list.sortable[j].ChangePct) < c(list.sortable[i].ChangePct) }
func (list ByChangePctDesc) Less(i, j int) bool { return c(list.Sortable[j].ChangePct) < c(list.Sortable[i].ChangePct) } func (list byChangePctDesc) Less(i, j int) bool { return c(list.sortable[j].ChangePct) < c(list.sortable[i].ChangePct) }
func (list ByOpenDesc) Less(i, j int) bool { return list.Sortable[j].Open < list.Sortable[i].Open } func (list byOpenDesc) Less(i, j int) bool { return list.sortable[j].Open < list.sortable[i].Open }
func (list ByLowDesc) Less(i, j int) bool { return list.Sortable[j].Low < list.Sortable[i].Low } func (list byLowDesc) Less(i, j int) bool { return list.sortable[j].Low < list.sortable[i].Low }
func (list ByHighDesc) Less(i, j int) bool { return list.Sortable[j].High < list.Sortable[i].High } func (list byHighDesc) Less(i, j int) bool { return list.sortable[j].High < list.sortable[i].High }
func (list ByLow52Desc) Less(i, j int) bool { return list.Sortable[j].Low52 < list.Sortable[i].Low52 } func (list byLow52Desc) Less(i, j int) bool { return list.sortable[j].Low52 < list.sortable[i].Low52 }
func (list ByHigh52Desc) Less(i, j int) bool { return list.Sortable[j].High52 < list.Sortable[i].High52 } func (list byHigh52Desc) Less(i, j int) bool { return list.sortable[j].High52 < list.sortable[i].High52 }
func (list ByVolumeDesc) Less(i, j int) bool { return list.Sortable[j].Volume < list.Sortable[i].Volume } func (list byVolumeDesc) Less(i, j int) bool { return list.sortable[j].Volume < list.sortable[i].Volume }
func (list ByAvgVolumeDesc) Less(i, j int) bool { return list.Sortable[j].AvgVolume < list.Sortable[i].AvgVolume } func (list byAvgVolumeDesc) Less(i, j int) bool { return list.sortable[j].AvgVolume < list.sortable[i].AvgVolume }
func (list ByPeRatioDesc) Less(i, j int) bool { return list.Sortable[j].PeRatio < list.Sortable[i].PeRatio } func (list byPeRatioDesc) Less(i, j int) bool { return list.sortable[j].PeRatio < list.sortable[i].PeRatio }
func (list ByDividendDesc) Less(i, j int) bool { return list.Sortable[j].Dividend < list.Sortable[i].Dividend } func (list byDividendDesc) Less(i, j int) bool { return list.sortable[j].Dividend < list.sortable[i].Dividend }
func (list ByYieldDesc) Less(i, j int) bool { return list.Sortable[j].Yield < list.Sortable[i].Yield } func (list byYieldDesc) Less(i, j int) bool { return list.sortable[j].Yield < list.sortable[i].Yield }
func (list ByMarketCapDesc) Less(i, j int) bool { return m(list.Sortable[j].MarketCap) < m(list.Sortable[i].MarketCap) } func (list byMarketCapDesc) Less(i, j int) bool { return m(list.sortable[j].MarketCap) < m(list.sortable[i].MarketCap) }
type Sorter struct { type Sorter struct {
profile *Profile profile *Profile
@ -93,39 +94,39 @@ func (self *Sorter) SortByCurrentColumn(stocks []Stock) *Sorter {
if self.profile.Ascending { if self.profile.Ascending {
interfaces = []sort.Interface{ interfaces = []sort.Interface{
ByTickerAsc { stocks }, byTickerAsc { stocks },
ByLastTradeAsc { stocks }, byLastTradeAsc { stocks },
ByChangeAsc { stocks }, byChangeAsc { stocks },
ByChangePctAsc { stocks }, byChangePctAsc { stocks },
ByOpenAsc { stocks }, byOpenAsc { stocks },
ByLowAsc { stocks }, byLowAsc { stocks },
ByHighAsc { stocks }, byHighAsc { stocks },
ByLow52Asc { stocks }, byLow52Asc { stocks },
ByHigh52Asc { stocks }, byHigh52Asc { stocks },
ByVolumeAsc { stocks }, byVolumeAsc { stocks },
ByAvgVolumeAsc { stocks }, byAvgVolumeAsc { stocks },
ByPeRatioAsc { stocks }, byPeRatioAsc { stocks },
ByDividendAsc { stocks }, byDividendAsc { stocks },
ByYieldAsc { stocks }, byYieldAsc { stocks },
ByMarketCapAsc { stocks }, byMarketCapAsc { stocks },
} }
} else { } else {
interfaces = []sort.Interface{ interfaces = []sort.Interface{
ByTickerDesc { stocks }, byTickerDesc { stocks },
ByLastTradeDesc { stocks }, byLastTradeDesc { stocks },
ByChangeDesc { stocks }, byChangeDesc { stocks },
ByChangePctDesc { stocks }, byChangePctDesc { stocks },
ByOpenDesc { stocks }, byOpenDesc { stocks },
ByLowDesc { stocks }, byLowDesc { stocks },
ByHighDesc { stocks }, byHighDesc { stocks },
ByLow52Desc { stocks }, byLow52Desc { stocks },
ByHigh52Desc { stocks }, byHigh52Desc { stocks },
ByVolumeDesc { stocks }, byVolumeDesc { stocks },
ByAvgVolumeDesc { stocks }, byAvgVolumeDesc { stocks },
ByPeRatioDesc { stocks }, byPeRatioDesc { stocks },
ByDividendDesc { stocks }, byDividendDesc { stocks },
ByYieldDesc { stocks }, byYieldDesc { stocks },
ByMarketCapDesc { stocks }, byMarketCapDesc { stocks },
} }
} }

Loading…
Cancel
Save