In Anylogic how do you extract the name of an object so i can use and assign it as a Text value? (Object >> Text) - tostring

The Problem: An agent has a parameter that refers to an object (lets say an INode). I want to get and use the name of that INode as plain text without writing a function that maps INodes to their names. If currentLocation (which has a value of Node12) is the parameter, in a snippet, it looks like:
agent.currentLocation
Is there a name property of Parameters or other Objects that i can reference and it returns a String (just the text "Node12" in this case)? I have tried all kinds of references with parameter.name, getValue, etc, to no avail.

For INodes you can use myNode.getName(), as you can for every object in Java.
However, you cannot get the name of parameters, variables, etc. And you shouldn't do that, it is considered bad practice :-)

Related

SNMP OID with non-unique node names

I am writing an extension to my companies existing SNMP MIB. I have a whole list of objects, with the same properties on each. I want to be able to get and set these through SNMP.
So for example, consider my object has name, desc, arg0, arg1. What I want is to be able to refer to these as:
fullpath.objects.ObjectA.name
fullpath.objects.ObjectA.desc
fullpath.objects.ObjectA.arg0
fullpath.objects.ObjectB.name
fullpath.objects.ObjectB.desc
fullpath.objects.ObjectB.arg0
However the leaf nodes appear to have to have unique names, so I am unable to define this.
I can use a SNMP table to produce:
fullpath.objects.table.name.1
fullpath.objects.table.desc.1
fullpath.objects.table.arg0.1
fullpath.objects.table.name.2
fullpath.objects.table.desc.2
fullpath.objects.table.arg0.2
But there is nowhere to look up that 2 means ObjectB. This leaves it open to user error looking up the wrong value and setting the wrong thing.
At the moment the best solution I can see is:
fullpath.objects.ObjectAName
fullpath.objects.ObjectADesc
fullpath.objects.ObjectAArg0
fullpath.objects.ObjectBName
fullpath.objects.ObjectBDesc
fullpath.objects.ObjectBArg0
which involves defining name for every object (there are 20 or so of them). The set of objects is fixed, so this is ok...just not very tidy.
Is there some way to define names for index in the table?
Is there some way of defining a container type?
Is there some way of allowing leaf nodes to be non-unique?
Any other ideas?
You should definitely use SNMP tables to accomplish what is required. This is the only way.
MIB Object names must be unique within entire MIB file.
You can easily use object of OCTET STRING type as Table index. So each byte/symbol/char of OCTET STRING value will be translated to corresponding numeric ASCII code in OID.
I ended up just using a naming convention and adding each of the settings directly into the MIB.
Not really the answer I wanted, but it means that all of the settings show up in the MIB, and that reduces the chance of users setting the wrong setting.

How to check whether a value exists in a Ruby structure?

I used to have a series of independent arrays (e.g. name(), id(), description() ). I used to be able to check whether a value existed in a specific array by doing name.include?("Mark")
Now that I moved to a MUCH MORE elegant way to manage different these independent arrays (here for background: How do I convert an Array with a JSON string into a JSON object (ruby)) I am trying to figure out how I do the same.
In short I put all the independent arrays in a single structure so that I can reference the content as object().name, object().id, object().description.
However I am missing now how I can check whether the object array has a value "Mark" in its name structure.
I have tried object.name.include?("Mark") but it doesn't quite like it.
I have also tried to use has_value?but that doesn't seem to be working either (likely because it used to be an hash before I imported it into the structure but right now is no longer a hash - see here: How do I convert an Array with a JSON string into a JSON object (ruby))
Thoughts? How can I check whether object.name contains a certain string?
Thanks.
If you want to find all customers called Mark you can write the following:
customers_named_mark = array_of_customers.select{|c| c.name == 'Mark' }
This will return a potentially empty array.
If you want to find the first customer named Mark, write
customer_named_mark = array_of_customers.detect{|c| c.name == 'Mark' }
This will return the first matching item or nil.

How can I retrieve object keys from a sequence in freemarker?

I have a list of objects that are returned as a sequence, I would like to retrieve the keys of each object so as to be able to display the object correctly. At the moment I try data?first?keys which seems to get something like the queries that return the objects (Not sure how to explain that last sentence either but img below shows what I'm trying to explain).
The objects amount of objects returned are correct (7) but displaying the keys for each object is my aim. The macro that attempts this is here (from the apache ofbiz development book chapter 8).
Seems like it my sequence is a list of hashes and as explained by Daniel Dekany this post:
The original problem is that, someHash[key] expects a
string as key. Because, the hash type of FTL, by definition, maps
string keys to arbitrary values. It's not the same as Java's Map.
(Note that to further complicate the matters, in FTL
someSequenceOrString[index] expects an integer index. So, the [] thing
is used for that too.) Now someBeanWrappedMap(key) has technically
nothing to do with all the []-s, it's just a method call, so it
accepts all kind of keys. If you have a Map with non-string keys, you
must use that.
Thanks D Dekany if you're on stack, this ended my half day frustration with the ftl template.

Reference Variable as a value - VB6

Is it possible to use a variable value as a name for a reference variable? For example:
Dim PersonName As String
PersonName = recordset("PersonName")
Instead of the value of PersonName being a person name e.g. JoeBloggs; the reference variable itself would be JoeBloggs i.e. joebloggs = whatever.
I have looked around for the answer as I thought it would be a common question; but I was unable to find one.
#w0051977 dont worry, your need (if i understand it correctly) does make sense, ive wanted to do this once as well. If you understand it, you want to be able to define your variables name using a string? Like, if you have a "JohnDoe" in your database then you want to set the name of your variable as a string named JohnDoe, am i right? if that is right, you can't directly do this in VB6, however, in vb.net we have reflection so there is some way you can read the name of the variable and have it returned as a string (though i understand you want to do the opposite). So, best way to do this in vb6 is the following...
Dim c As Collection ' where c is our collection to make it short-hand/less typing.
Set c = New Collection ' you could have done As New Collection instead but this is better, trust me.
c.Add "MyValue1", "JohnDoe" ' sets a variable named JohnDoe with value "MyValue1"
c.Add "MyValue2", "JessKay" ' remember, these are stored as Variants, but can use as string.
Now to call it...
MsgBox c("JohnDoe") ' this simple.
so c("JohnDoe") will return whatever is in the value you've set for this variable name.
same story for the chick, say you wanna set another variable with the girls value in it...
Dim abc As String
abc = c("JessKay") ' thats all :) abc will equal "MyValue2"
Also, remember anything stored in a VB6 collection will always be stored as a Variant, so takes more memory than a String. However, you can still use it as a string or a number or anything else you want.
Cool?
Let me know if your needs were actually different and i've misunderstood your question. thanks.

Why can't I retrieve "contents" of a note item in Yojimbo, but I can retrieve the "content"?

A note item in Yojimbo's Applescript dictionary is defined as:
note item n [inh. database item] : A note item.
elements
contained by application.
properties
encrypted (boolean, r/o) : Is the note is encrypted?
contents (text) : The contents of the note. syn content
If this note is encrypted, the contents property is only readable
if permitted by the current security policies.
responds to
append, prepend.
In an attempt to export my data, I've been poking around with AppleScript, learning the language, etc, and currently have this:
tell application "Yojimbo"
repeat with EachNote in (note items in library)
display dialog (content of EachNote) as string
end repeat
end tell
What's confusing me is that, though the class defines the property "contents", I have to use "content" to retrieve the contents. Using "contents" results in this error:
Can’t make «class YNot» id "A0C9E19E-3106-44F9-97A6-A1A74AD77948"
of application "Yojimbo" into type string.
I'm assuming the "syn content" means it's a synonym, thus I should be able to use "content" and "contents" interchangeably. But apparently the synonym works, but the original does not...?
Also, more simply, why do the contents have to be coerced into a string? If I look at the properties on the object (via: (properties of EachNote) as string ), "contents" is a double-quoted string, though I realize this isn't necessarily "proof" that it's a string.
I'm still starting with AppleScript, so if I'm making a n00bish mistake, feel free to slap.
For others who find a similar confusion, I found help here: http://groups.google.com/group/yojimbo-talk/browse_thread/thread/d04f42db335c77e7
So all props go to Jim for being awesome!
The basics:
contents of an object is different than contents of a variable containing an object.
contents of a variable containing an object returns the object, not the object's contents, unlike every other property. Other properties return the property of the object in the variable, as expected.
This means, to get the contents of an object inside a variable, you need to use contents of contents of variable.
As demonstrated here, on my blog, yes, this is extremely strange. While var == var and var == contents of var, var != contents of (contents of var), so Applescript does indeed violate the identity principle for "contents" in this specific case. It does not chain this effect, though, so you shouldn't need to use contents of three layers deep (it'll work the same as two)
contents of contents of var works on objects as well, so it's always safe to use.
Many dictionaries use content as a synonym of contents, which avoids this whole problem. If desired, use content of var, and it'll work like other properties, always returning the object's content instead of the object.

Resources