Graph Abstract Data Type: Search method. - search

I am implementing a Graph for a school assignment with an adjacency list. I am having troubles with the search method. I would like to ask you the following question:
If you're searching a vertex that is not in the Graph, should it be an error?
Which is the best criteria to determine if a possible result is an error or not?
Thanks,
Gonzalo from Argentina (Hope you understand my english.)

A solution is to throw a NoSuchElementException if the element is not there.
An alternative solution could be to use something similar to Scala's Option or Haskell's Maybe.
Another possible solution is to introduce a pair of methods boolean contains(VertexID id) and Vertex get(VertexID id).
The class should use the query method contains to search for the presence for the element and the getter only if he knows that the element is there.
Of course get should throw a NoSuchElementException if it is invoked for a missing element.

Related

Can i get all components of an xsp document in xpages?

I have a simple document with 3 fields and 1 rich text field. I also have an xpage with 3 simple edit box controls and 1 rich text. The name of my NotesXSPDocument is document1.
Question 1:
Can i get a vector with all the controls of the xsp document? for example, instead of using getComponent("fld1"), getComponent("fld2") ... etc, can i use something like getAllComponents() or document1.getControls()? These methods do not exist of course so i am asking if there is a way to do it. I know i can get all items of a document (not XSP) by calling document1.getDocument().getItems(). IS there anything similar for xsp?
Question2:
Lets say we can get a vector as i described above. Then if i iterate through this vector to get each control's value, is there a method to check if it is rich text or simple text field?
Technically, yes, but not readily and this is one of those situations where there's likely a better way to approach whatever underlying problem it is you want to solve.
Nonetheless, if you're looking to get a list of inputs on the page, XspQuery is your friend: http://avatar.red-pill.mobi/tim/blog.nsf/d6plinks/TTRY-96R5ZT . With that, you could use "locateInputs" to get a List of all the inputs on the page, and then check their value method bindings to see if the string version is referencing your variable name. Error-prone and not pretty, but it'd work. Since they're property bindings, I don't think the startsWith filter in there would do what you want.
Alternatively, you could bind the components to something in a Java class from the start. I've been doing just such a thing recently (for a different end) and initially described it here: https://frostillic.us/f.nsf/posts/my-black-magic-for-the-day . The upshot is that, with the right cleverness for how you do your binding="" property, you could get a list of all the components that reference a property of a given object.
As for the second part of the question, if you DO get a handle on the components one way or another, you can check to see if it's a rich text control by doing "component instanceof com.ibm.xsp.UIInputRichText".
A bit complex but yes. facesContext.getViewRoot() is an UIViewRoot object so it has List<UIComponent> getChildren() method which returns its children.
However, since it's a tree-structure, some of its children will have additional children components. You have to traverse the entire tree to build a list of components you want to see.
For types, you can decide what type a component is by its class. For instance, UIInput is a text box, etc.

How to access certain EStructuralFeatures of an EMF Model?

I know that there are ways to access an EAttribute of an Eclipse EMF model by its featureID or by its name via different indirect approaches. For that I found the following: Eclipse EMF: How to get access EAttribute by name?
But what if I don't know the name of the attribute I want to get? Let's say, based on the design, the model has some fixed attributes by the developer, along with the features that can be set dynamically by the user.
So, for the time being I use the getEAllStructuralFeatures() and use indexes via get() to reach to the by-the-user-created attributes, since I know that the list I get will have the fixed attributes of the model as its first elements beginning with the index 0. But I find this solution unclear and inefficient. Also in some cases, that I want to work, not suitable.
E.g: IEMFEditProperty prop = EMFEditProperties.list(editingDomain, EMFMODELPackage.Literals.EMFMODEL.getEAllStructuralFeatures().get(X));
Do you know a solution or a workaround for this problem? As far as I can see, there are no direct methods to get such dynamically created features of the model.
Every help will be appreciated.
I have been working on a similar case recently where I first tried to define an EStructuralFeature to access exactly the setting/attribute of the object that I needed.
But if you look at how things work internally in ECore, you will find out, that there is no way this will ever work, since the indices are bound to the object identity of the EStructuralFeature objects created at runtime for the specific context (i.e. EClass instance).
My approach was then to either inspect the features proposed by EClass.getEAllStructuralFeatures or to iterate over the features and inspect the object returned by EObject.eGet for this very feature (where EClass eClass = eObject.eClass()).
Example: In a UML profile I have defined a UML Stereotype called "Bean" with a property called FactoryEntity. The property shall reference a UML Class with the Stereotype "Entity" that is closest to this very bean and for which a static factory method will be generated.
In the model I would then have one UML Class typed as Bean and one as Entity.
And for the Class typed as "Bean" I would then set a value for the attribute/property factoryEntity defined in the profile.
The question was then how the property value would be accessible in ECore. I ended up iterating the List of available EStructuralFeature of the EClass of the EObject and checking the type of the object returned by eGet.
final EObject eObject = (EObject) holdingClass.getValue(stereotype, stereoTypePropertyName);
final EList<EStructuralFeature> allEStructFeats = eObject.eClass().getEAllStructuralFeatures();
for(EStructuralFeature esf : allEStructFeats)
{
final Object o = eobject.eGet(esf);
if(o instanceof org.eclipse.uml2.uml.Class)
{
return (org.eclipse.uml2.uml.Class) o;
}
}
Maybe that is not the most elegant way to access structural features but it is the only one I thought was robust enough to last.
Please let me know if you have any suggestions on how to improve this.

System.ComponentModel.BindingList: Add(object) vs. AddNew()

What is the difference between the System.ComponentModel.BindingList methods Add(object) and AddNew()? The MSDN documentation says this:
Add: Adds an object to the end of the Collection<T>.
AddNew: Adds a new item to the collection.
It seems like both methods add an item to the collection, but Add(object) does it in one shot whereas AddNew() is slightly more complicated. My tests with Add(object) seem to be working, but I want to know if I am using the correct method.
So what is the difference between these methods?
AddNew() creates the object for you (that's why it doesn't have a parameter).
It's designed to be used by grids, which don't know how to create a new object to pass to Add().
AddNew() is very handy (it’s the well-known Factory design pattern) when you implement a class derived of BindingList().
It allows your code to initialize new items with values that depend on the list itself - e.g. a foreign key to the parent object if the binding list contains a list of children.

couchdb: is there an identity list function?

I'm learning about list functions in couchdb, and I'm wondering what the identity function looks like, if one exists. (i.e. a list that emits the same output as a raw view)
If you understand list functions, could you help me write one?
I expect it would look something like
function(head, req) {
while (var row = getRow()) {
send(row)
}
}
but I'm not sure, and that doesn't sound right because I don't use head and req anywhere.
I have an example list function. It's purpose is to do an intersection of tags, you pass in a key (as the view key), and extra_keys which are the additional tags to include in the intersection. I am just telling this as the purpose of this view does not relate to your question, but it will help you understand what you are looking at.
The list mimics view output, mostly. My app only really looks at rows, so that is the only property I add. YMMV. You can cut the cruft in the middle, if you like. The example is here:
https://github.com/ryanramage/eckoit/blob/master/app.js#L209
I found this blog post which seems to be close to what you want. The only difference would be that in the real view results there is a total_rows and offset field (as long as there isn't a reduce function).

SPFieldMultiChoice - can there be an underlying value?

With Sharepoint's SPFieldMultiChoice, there is a [stringcollection] "Choices" property and a [string] "Mappings" property. These can come from a schema.xml file. I have not seen where the out of the box functionality provides for usage of the values stored in . In other words, rendering a ListControl with Display text and underlying values. Easy enough to create, but just checking to see what i'm missing.
What you are looking for is the SPFieldMultiChoiceValue class. http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spfieldmultichoicevalue(v=office.12).aspx
Here is a simple tutorial explaining how to use this for example with a checkbox list.
http://blog.qumsieh.ca/2008/12/27/working-with-spfieldmultichoicevalue-saving-and-loading/
***edit After rereading your question I realized the context was wrong. No a multichoice field is not a key/value pair it is simply a valued index.

Resources