C
Curious
I have two ArrayLists:
ArrayList mBuyLimits = new ArrayList();
ArrayList mSellLimits = new ArrayList();
Each item on mBuyLimits and mSellLimits is an instance of
"LongTermLimit" that is defined as below:
public class LongTermLimit
{
protected double mPrice;
protected int mShares;
public LongTermLimit(double price, int shares)
{
mPrice = price;
mShares = shares;
}
public double Price
{
get { return mPrice; }
}
public int Shares
{
set { mShares = value; }
get { return mShares; }
}
}
For mBuyLimits, I want to sort it by "Price" in descending order. For
instance, if mBuyLimits contains the following:
Shares Price
---------------
300 25.04
230 26.04
470 26.6
I want to sort it to:
Shares Price
---------------
470 26.6
230 26.04
300 25.04
For mSellLimits, I want to sort it by "Price" in ascending order. For
instance, if mSellLimits contains the following:
Shares Price
---------------
300 49.58
230 46.2
100 36.04
130 39.42
170 42.81
I want to sort it to:
Shares Price
---------------
100 36.04
130 39.42
170 42.81
230 46.2
300 49.58
Is there a way to define two separate "Sort" methods in the class,
"LongTermLimit". One is for sorting by "Price" in descending order
(for sorting mBuyLimits), and the other one is for sorting by "Price"
in ascending order (for sorting mSellLimits)?
ArrayList mBuyLimits = new ArrayList();
ArrayList mSellLimits = new ArrayList();
Each item on mBuyLimits and mSellLimits is an instance of
"LongTermLimit" that is defined as below:
public class LongTermLimit
{
protected double mPrice;
protected int mShares;
public LongTermLimit(double price, int shares)
{
mPrice = price;
mShares = shares;
}
public double Price
{
get { return mPrice; }
}
public int Shares
{
set { mShares = value; }
get { return mShares; }
}
}
For mBuyLimits, I want to sort it by "Price" in descending order. For
instance, if mBuyLimits contains the following:
Shares Price
---------------
300 25.04
230 26.04
470 26.6
I want to sort it to:
Shares Price
---------------
470 26.6
230 26.04
300 25.04
For mSellLimits, I want to sort it by "Price" in ascending order. For
instance, if mSellLimits contains the following:
Shares Price
---------------
300 49.58
230 46.2
100 36.04
130 39.42
170 42.81
I want to sort it to:
Shares Price
---------------
100 36.04
130 39.42
170 42.81
230 46.2
300 49.58
Is there a way to define two separate "Sort" methods in the class,
"LongTermLimit". One is for sorting by "Price" in descending order
(for sorting mBuyLimits), and the other one is for sorting by "Price"
in ascending order (for sorting mSellLimits)?