Scala how to get object property value given name of property in string? - scala

I wondering how to get object property value given name of property in string in Scala? I saw examples when you get all fields of object using Reflection and iterate over it. But is it possible to call it without iteration? Or may be there is a way to pass object.field to another function without evaluation and evaluate it there and return result?

Kolmar comment give me right direction to call by name function.

Related

Specification builder doesn't recognize transient properties

I'm trying to implement specification in one of my use cases.
As u can see in the function dateValueBetween, I'm trying to get from the root the transient property valueDate. But when calling this service with real data it give the error downside.
My original problem was how to call the builder.between method but the value I have is a String value and need to be parsed.
but it seems that the first argument need to be a property of the table and not a function.
How can I achieve my goal?

Passing complex object as parameter to sub-stack

I want to pass the output of a custom resource, which is an array of objects, as parameter to a sub-stack. An example of what I want to pass as parameter to the child stack is :
[
{"Role":"Role1","IdentifierType":"Prefix","Identifiers":"Bucket1"}
{"Role":"Role2","IdentifierType":"Prefix","Identifiers":"Bucket2"}
]
How do I pass this to the sub-stack? I tried declaring the parameter in the child stack as String, and later as CommaDelimitedList. Both the times, the stack gave an error: "Value of property Parameters must be an object with String (or simple type) properties"
As I know until now, there is not way to pass complex objects as a result of of stack execution. Like the message say, the outputs need to be string or single types (integer and boolean in case of cloudformation).
Without more information is hard to help you with alternatives, but let's assume that your Custom Resource is based on lambda. And let's assume that you have control about the code of your Custom Resource. If this is the case you can:
Send the resource identification of your custom resource as a parameter for your nested stack;
Inside nested stack, invoke the lambda function again with the resourceId as a parameter;
Change the lambda code to check for a new parameter for the resourceId (inside the ResourceParameters, not inside the Common Resource Id sent by CloudFormation).
If the parameter is not empty (or not a defined value passed on the first invocation) respond with the old values (you must have a way to keep this values in some place or check then in runtime.);
Change the lambda code to do not take action in the update/deletion is case of invocation by the nested stack (with the resourceId parameter).
Again, is hard to think in alternatives without more info about your specific problem. But use this response as a food for thought.

How can I get a VLAX-OBJECT from an ads_name type

I am using entget function in order to get all the properties of a certain object. So I have the table of dotted pairs that describe the properties of the object but now I want to use the VLAX-OBJECT functions, such as VLAX-COPY or VLAX-MOVE. So I need to convert it from the ads_name type to VLAX-OBJECT type but I can not handle to do it. Can you suggest any Idea to do it please?.
You can use the vlax-ename->vla-object function to get the VLAX object from the entity name

Eclipse JDT AST: how to find a calling method returns value of an instance variable?

I'm using Eclipse JDT AST to parse a given java source code. While parsing the code, when it hits a method invocation, I want to find out whether that particular method returns or sets a value of an instance variable (basically to find out whether the callee method is a getter/setter of the same class of caller method).
E.g.:
public void test(){
//when parsing the following line I want to check whether "getName"
//returns a value of an instance variable.
String x = getName();
//when parsing the following line I want to check whether "setName"
//sets the value of an instance variable.
setName("some-name");
}
I've used the AST plugin also find out a possible path which would help me to refer it from the API, but couldn't.
Please let me know whether this is possible and if so, which approach that would help me to get the required information.
Don't think that there is an api which tells you whether a method is a getter or a setter.
You will have to write code to do this. For a getter, you can probably simply check if the last statement in the method is a return statement which returns an instance variable.

After raising IEnumerable.OrderBy(), the source list was not sorted,why?

1.First I defined an extension method for the IEnumerable.Add() like the code below
public static IEnumerable<T> Add<T, TKey>(this IEnumerable<T> enumerable, T value, Func<T, TKey> orderBy)
{
if (enumerable == null)
return null;
if (enumerable is IList<T>)
{
var list = enumerable as IList<T>;
if (!enumerable.Contains(value))
{
list.Add(value);
enumerable = enumerable.OrderBy(orderBy);
}
}
}
2.Then,I raised the extension method like this to sort the itemlist according to the "Date" property when a new item was added to the list:
itemList.Add(item, o => o.Date);
3.After all,it appears that the "itemList" was not sorted.
4.I followed the extension method and found that "enumerable" was a new instance after "enumerable = enumerable.OrderBy(orderBy)" and it was sorted,but the "list" was not.
5.Then I tried to cast the sorted enumerable to list like "list=enumerable.ToList()",both of them("enumerable" and "list") were sorted.
6.After that ,when the call stack went back to the "itemList.Add(item, o => o.Date);",the "itemList" was not sorted at all!!!
Anyone can give me some advices?Thanks a looooooooooooooooooooooooooooooooot!!
I believe your problem is that the reference to enumerable is being passed by value rather than by reference. See Jon Skeet's article about passing parameters by value or reference for more information about what that means. In short, C# passes a copy of the parameter's reference so assigning a new value to parameter does not change the reference of the object that was passed in. To pass a parameter by reference you specify the ref keyword, but I don't think that will work with an extension method. If you're dead set on making this work I would suggest inserting the items into your List in sorted order, probably requiring that T implement IComparable.
Update:
First off, see the Skeet's article it's really quite informative and I will probably only be half as clear as he is. Second, when you pass an object as a parameter to a method you are passing a copy of the reference. This means you can still access members of the object but, the same way that a value type is passed by copy, if you modify the reference (ie assign it a new value) you wont modify the original reference. Specifying ref means that you are passing a reference to the reference and changing the reference (assigning a value to it) will affect the original object.
Neither OrderBy or ToList will affect the source list. When you did this: list=enumerable.ToList() you changed your variable to point to a whole new list instance.
It appears to me that this method does too much. I would keep adding and sorting as separate operations. The fact that this extends IEnumerable but silently does nothing if the target is not an IList is a code smell.