0

I am building a DAQ in a Java based Platform called KMax. This platform, has a design interface to use objects like histograms. Each histogram has a name, which is declared on the design interface.

To call the histogram in the code you have to use

hist = tlsh.getKmaxHist("DATA");

The string DATA is the name that the user gives in the design interface and hist is the variable that refers to the object. Every histogram object has certain classes it can use. For instance hist.getSum() gives the total sum of the histogram.

In my DAQ I have many histograms. My plan is to create a slider box that will pick the histogram, that the user wants to apply some functions(such as getSum()). The slider box has a class(string getProperty("VALUE")) that returns the value that the user has selected.

The plan is to use something like sliderBox.getProperty("VALUE").getSum(). Of course something like that is not valid, therefore I was wondering if there is a way to "convert" the string that the getProperty() returns, into a variable already defined in the code.

1
  • 1
    I do not understand what you're asking, you might use a Map; but that isn't really different from what you have shown here. Commented Mar 11, 2014 at 16:38

4 Answers 4

4

Sounds like a Map will do what you need. You can put the histograms in a Map keyed by whatever the property value is.

Map<String,Histogram> histograms = new HashMap<String,Histogram>();
histograms.put("PropertyValue1", histogram1);
histograms.put("PropertyValue2", histogram2);

String desiredHistogram = silderBox.getProperty("VALUE");
Histogram histogramToUse = histograms.get(desiredHistogram);
histogramToUse.getSum(); // do whatever you need to with this

You'll want to check for nulls and all that stuff too.

Sign up to request clarification or add additional context in comments.

3 Comments

Thank you very much for your answer! This is really enlightening! One small question:where am I supposed to put that code? Inside my method that will use the function that I'd like? Shall I import anything?
@Thanos It's up to you where to put it, wherever it makes sense in your application. The first block should go wherever you create your histograms, and the second block should go wherever you use them. You'll need to import java.util.Map and java.util.HashMap.
Thank you very much for your answer!!! It really worked!!! And again thank's for the Map!!!
0

It looks to me like you need a Map<String, Histogram>. Variable names are lost when java code gets compiled.

Comments

0

You can use the *BeanInfo class mechanism. For instance. Having a class Hist, one can write a HistBeanInfo with a "sum" property. Though these classes were intended for GUI builders with components on palettes listing heterogene properties, one can use them indepedantly.

The BeanInfo classes might be generated.

This still is a far way to actually instrument that information, maybe using reflection.

An alternative to BeanInfo would be using home-brew annotations, but with BeanInfo you have an API supported by some IDEs.

Comments

0

Store it in a map:

yourHistogramsMap.get(sliderBox.getProperty("VALUE")).getSum();

Of course, you have to store your histograms there first.

2 Comments

Thank you for your answer! I don't, however understand your thinking. sliderBox.getProperty("VALUE") gives a string. I don't understand the syntax yourHistogramsArray[string].
I misread where you said it was a string. Use that as the key for the map instead

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.