Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
204 views
in Technique[技术] by (71.8m points)

Advanced sorting in Java

I'm working on one idea for existing Java project which can add new logic of operations depends on modules initialized and also downloaded (optional modules) by user.

Question is, that some operation depends on order of commands, which can be hardly coded with knowledge of all modules, or it can be modular and loaded by some hooks.

Example - scoring element (in game).

  • Basic scoring
  • Feature1 scoring - double basic score
  • Feature2 scoring - add some extra points to Basic score, when Feature1 is - activated, double those score - different login if Feature1 is activated or not
  • Feature3 scoring - add extra score Depends on Feature1 and also Feature3 if one or both activated

It is not problem to hard code it.

But how to sort those scoring when will be created plugin with Feature 4 which can have different requirements for scoring, for example Has to be run after Basic scoring but before Feature1 scoring if activated because it change basic scoring which affect Fature1 scoring.

So my idea is define order requirements with defined which "known" scoring is required to be run after known scorings, but also requirement which tells to run before known scorings if defined

  • basic: run_after: NULL, run_before: NULL
  • feature1: run_after: basic, run_before: NULL
  • feature2: run_after: basic, feature1, run_before: NULL
  • feature3: run_after: basic, feature1, run_before: NULL
  • feature4: run_after: basic, run_before: feature1

so result will be when all modules are activated

  1. basic
  2. feature4
  3. feature1
  4. feature3 -> feature 3 and feature2 have same definition doesn't mather of order 2->3 or 3->2
  5. feature2

when for example onle basic and feature2 and feature4 then result will be same order by skipping not activated or not found modules

  1. basic
  2. feature4
  3. feature2

I was looking for some plugins in Java like PF4J, which can uses dependencies to order execution extensions.

But there can be feature5 and feature6 as plugins, which for example feature6 can use different scoring when feature5 is loaded.

If using PF4J dependencies, and feature5 will not be available, also feature6 will not be loaded. This is reason to looking for some advanced sorting.

question from:https://stackoverflow.com/questions/65844927/advanced-sorting-in-java

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...