简体   繁体   中英

Java — Associate data input with data output?

I am looking for advice on basic designs for a system with this functionality.

Let's say I have a data class like this:

Class nodeData
boolean aValue;
boolean bValue;
boolean cValue;

Using some set of business logic, I define mutually exclusive sets of titles to the node that this data represents.

For example, I define this title:

Singular.YES means Only one of aValue, bValue, cValue is true
Singular.NO means 0 or more than 1 of aValue, bValue, cValue is true

or this one:

aDefined.YES means aValue is true.
aDefined.NO means aValue is false.

or this one:

totalTrue:.0 means 0 of the values are true
totalTrue.1 means 1 of the values are true
etc.

In each of these cases, the titles are mutually exclusive among each other in that same set, and which title within a set applies to that data is based on some hard-coded business logic.

Then, each specific title is associated with some specific piece of functionality. For example, I might say that "If aDefined.YES, call methodX" or "If totalTrue.0, call methodX and then methodY".

If N is the number of title sets, then there are N! combinations of titles, and N! combinations of associated functionality. How do I accomplish: For each node data, find the set of titles associated with that data. Run the functionality associated with each of those titles.

EDIT: This isn't a boolean logic question, this is a design question. My point is that I want a robust method of associating data sets with some name or subclass given arbitrary business logic.

skipping the Value parts
I think this should help you but your question is a bit vague.

//checking if one of the 3 bools are true
if((a&&!b&&!c)||(!a&&b&&!c)||(!a&&!b&&c))
    Singular = Singular.YES
else
    Singular = Singular.NO

//checking if one bool is true
if(a)
    aDefined = aDefined.YES
else
    aDefined = aDefined.NO

//checking how many bools are true
int i = 0;
if(a)
    i++;
if(b)
    i++;
if(c)
    i++;
TotalTrue = i;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM