-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add capability to sort market data
- Loading branch information
Showing
11 changed files
with
167 additions
and
39 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
src/main/java/com/blank038/servermarket/api/handler/sort/AbstractSortHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.blank038.servermarket.api.handler.sort; | ||
|
||
import com.blank038.servermarket.api.handler.sort.impl.DefaultSortHandlerImpl; | ||
import com.blank038.servermarket.api.handler.sort.impl.PriceHighSortHandlerImpl; | ||
import com.blank038.servermarket.api.handler.sort.impl.PriceLowSortHandlerImpl; | ||
import com.blank038.servermarket.internal.data.DataContainer; | ||
|
||
/** | ||
* @author Blank038 | ||
*/ | ||
public abstract class AbstractSortHandler implements SortHandler { | ||
protected final String sortKey; | ||
|
||
public AbstractSortHandler(String key) { | ||
this.sortKey = key; | ||
} | ||
|
||
public void register() { | ||
DataContainer.SORT_HANDLER_MAP.putIfAbsent(this.sortKey, this); | ||
} | ||
|
||
public static void registerDefaults() { | ||
new DefaultSortHandlerImpl().register(); | ||
new PriceHighSortHandlerImpl().register(); | ||
new PriceLowSortHandlerImpl().register(); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/com/blank038/servermarket/api/handler/sort/SortHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.blank038.servermarket.api.handler.sort; | ||
|
||
import com.blank038.servermarket.internal.cache.sale.SaleCache; | ||
|
||
import java.util.Comparator; | ||
import java.util.Map; | ||
|
||
/** | ||
* @author Blank038 | ||
*/ | ||
public interface SortHandler extends Comparator<SaleCache> { | ||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/com/blank038/servermarket/api/handler/sort/impl/DefaultSortHandlerImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.blank038.servermarket.api.handler.sort.impl; | ||
|
||
import com.blank038.servermarket.api.handler.sort.AbstractSortHandler; | ||
import com.blank038.servermarket.internal.cache.sale.SaleCache; | ||
|
||
/** | ||
* @author Blank038 | ||
*/ | ||
public class DefaultSortHandlerImpl extends AbstractSortHandler { | ||
|
||
public DefaultSortHandlerImpl() { | ||
super("default"); | ||
} | ||
|
||
@Override | ||
public int compare(SaleCache o1, SaleCache o2) { | ||
return 0; | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/com/blank038/servermarket/api/handler/sort/impl/PriceHighSortHandlerImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.blank038.servermarket.api.handler.sort.impl; | ||
|
||
import com.blank038.servermarket.api.handler.sort.AbstractSortHandler; | ||
import com.blank038.servermarket.internal.cache.sale.SaleCache; | ||
|
||
/** | ||
* @author Blank038 | ||
*/ | ||
public class PriceHighSortHandlerImpl extends AbstractSortHandler { | ||
|
||
public PriceHighSortHandlerImpl() { | ||
super("price_high"); | ||
} | ||
|
||
@Override | ||
public int compare(SaleCache o1, SaleCache o2) { | ||
if (o1.getPrice() == o2.getPrice()) { | ||
return 0; | ||
} | ||
return o1.getPrice() > o2.getPrice() ? -1 : 1; | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/com/blank038/servermarket/api/handler/sort/impl/PriceLowSortHandlerImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.blank038.servermarket.api.handler.sort.impl; | ||
|
||
import com.blank038.servermarket.api.handler.sort.AbstractSortHandler; | ||
import com.blank038.servermarket.internal.cache.sale.SaleCache; | ||
|
||
/** | ||
* @author Blank038 | ||
*/ | ||
public class PriceLowSortHandlerImpl extends AbstractSortHandler { | ||
|
||
public PriceLowSortHandlerImpl() { | ||
super("price_low"); | ||
} | ||
|
||
@Override | ||
public int compare(SaleCache o1, SaleCache o2) { | ||
if (o1.getPrice() == o2.getPrice()) { | ||
return 0; | ||
} | ||
return o1.getPrice() < o2.getPrice() ? -1 : 1; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
default: "默认" | ||
price_high: "价格高到低" | ||
price_low: "价格低到高" |