Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
I have this code in Java.
MyObject a = MyObject.newMyObject();
a.setParameter(Parameters.BASIC);
CompositeObject co = CompositeObject.newCompositeObject();
co.add(BasicFactory.newInputStream(new FileInputStream(file), ResourceType.BASIC, a);
Is it possible to do it better using Groovy?
Here's a start.
def a = MyObject.newMyObject()
a.parameter = Parameters.BASIC
def co = CompositeObject.newCompositeObject()
co.add(BasicFactory.newInputStream(new FileInputStream(file), ResourceType.BASIC, a))
If all you really need is the co then you can do something like this to limit the scope of temporary variables.
def co = CompositeObject.newCompositeObject().with {
def a = MyObject.newMyObject()
a.parameter = Parameters.BASIC
def factory = BasicFactory.newInputStream(new FileInputStream(file), ResourceType.BASIC, a)
co.add factory
return it
}
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 10 days ago.
Improve this question
My probleme is how to change a global class variable in a void function. I need to conserve the changes of my classe. How can I do that ?
//for example
Class Animal{
B b = null;
void Treatement(B b)
{
try{
b = new Class B()
b.name = "toto";
}
catch(Exception e)
{
throw new Exception(e.getMessage());
}
}
}
}
The probleme is I can not find a solution for this example because my variable has to be as parametre and need to save it for other fonctions when an exception is raised.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
Why does java.lang.Exception not provide a setter for the message and allow setting it only via the constructor (e.g. super(_msg))?
For example:
public BadParameterException(QueryParameter _param, String _valStr) {
this.param = _param;
this.valAsStr = _valStr;
}
public BadParameterException(QueryParameter _param, String _valStr, String _msg) {
this(_param, _valStr);
/* This is not possible */ super.setMessage(_msg);
}
instead, I have to do this:
public BadParameterException(QueryParameter _param, String _valStr, String _msg) {
super(_msg);
this.param = _param;
this.valAsStr = _valStr;
}
Because an Exception is a snapshot of a situation. It's not supposed to change it's state.
Since the message can only be set through the constructor, it's basically final and cannot be changed afterwards. That's how it was designed.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I need to create a binding that allows me to do the equivalent of String.replaceAll(...) but with bindings. I have a string, "${driver} driving ${name}", and I want the keys, "${driver}", etc. to be replaced with the specific property. I also want the returned property to be able to add listeners so when driverProperty or another changes, the returned property value will change without having to re-call getString().
public String getString(Derby derby) {
String ret;
if (driverProperty.get().equals("") && nameProperty.get().equals("") && numberProperty.get().equals("") && groupProperty.get().equals("")) {
ret = "[blank]";
} else {
ret = (String) derby.getSettings().get("general.cardisplay").getValue();
ret = ret.replace("${driver}", driverProperty.get());
ret = ret.replace("${name}", nameProperty.get());
ret = ret.replace("${number}", numberProperty.get());
ret = ret.replace("${group}", groupProperty.get());
}
return ret;
}
Use Bindings.createStringBinding(). This takes a function supplying the String and a list of values to observe; if any of those values change the binding is marked as invalid.
Your question isn't too clear to me, but I think you can do something like
StringBinding formattedString = Bindings.createStringBinding(
() -> getString(derby),
derby.settingsProperty(),
nameProperty, numberProperty,
driverProperty, groupProperty);
Now you can do things like
formattedString.addListener((obs, oldFormattedString, newFormattedString) -> {
// invoked any time the formatted string changes...
});
or
Label label = new Label();
label.textProperty().bind(formattedString);
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
How can i parse this json with GSON to my model?
Thanks for help.
{
"Kod":"XU100",
"Son Değer":"83.947",
"En Düşük":"83.947",
"En Yüksek":"86.355"
},
Would be like:
#SerializedName("Kod")
private String kod;
#SerializedName("Son Değer")
private String sonDeger;
#SerializedName("En Düşük")
private String enDusuk;
#SerializedName("En Yüksek")
private String enYuksek;
//Getters and Setters
And then:
YourClass yourClass = gson.fromJson(json, YourClass.class);
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
What would the same code in c++ look like, or the closest thing to it?
public class Skill{
public Skill(String name){
}
public static Map<String, Skill> getSkills(){
Map<String, Skill> skills = new Map<String, Skill>();
skills.add("Endurance", new Skill());
return skills;
}
}
std::map<std::string,Skill*> skills;
skills["Endurance"] = new Skill();