How to create ArrayLIst<Object of my class> - arraylist

Hello so I am doing my first Java game. I have done some Scala Before. I am trying to do an ArrayList with instances of the class Questions I have done.
So I Have made a file with public class **Question** {stuff}
And in Another file (but same package) I have made some instances of this class:
Question question1 = new Question("Vad är 2+2","4","fyra","3");
this I did for question2/question3/question4 aswell
And now I want to create an ArrayList with them as elements probably would work with an normal Array But I want to get to know the java ArrayList
I tried this:
ArrayList<Question> QAL = new ArrayList
ArrayList(question1,question2);
and this:
ArrayList<Question> QAL = new ArrayList<Question>();
QAL.add(question1);
But neither works and the second one I found on an guide but for some reason it does not work. I would love any help I can get probably something really simple but I have struggled for a few hours now with this.
THanks- Le

You have to use the name of the ArrayList to add a object to list:
ArrayList QAL = new ArrayList(); ArrayList.add(question1);
change to:
ArrayList QAL = new ArrayList(); QAL.add(question1);

Related

Microsoft Graph API not returning custom column from list

Working in VB.Net, using the Microsoft.Graph api communicate with sharepoint.
I have a list on a sharepoint site.
Lets say:
List name : ListTestName
Columns: ListColumnTest1, ListColumnTest2, ListColumnTest3
Dim queryFields As List(Of QueryOption) = New List(Of QueryOption) From {New QueryOption("$expand", "fields")}
Dim items As IListItemsCollectionPage = Await GraphClient.Sites(sharepointSessionId).Lists("ListTestName").Items.Request(queryFields).GetAsync()
This is the code I have to grab the list and trying to get all of the fields (columns) but when I look into the Fields in the "Items" variable I do not see any of the fields that I have added to the list. I only see the sharepoint fields such as "title" or "Id"
I really dont understand why this is not working.
Even when I look via the the graph-explorer site (https://developer.microsoft.com/en-us/graph/graph-explorer) using:
GET https://graph.microsoft.com/v1.0/sites/<SiteId's>/lists/ListTestName/items?expand=fields
I do not see my custom columns However if I try and filter directly to one of the columns like this :
GET https://graph.microsoft.com/v1.0/sites/<SiteId's>/lists/ListTestName/items?expand=fields(select=ListColumnTest1)
This does seem to have returned back my custom field.
Thus I tried adding to the query field {New QueryOption("$expand", "fields(select=ListColumnTest1")} this just crashed when I called the request.
Edit: I asked this question slightly wrong and will be posting a second question that is more to what I need. However, below the question is marked correct because their solution is the correct solution for what I asked. :)
Have you try this endpoint?
GET https://graph.microsoft.com/v1.0/sites/{site-id}/lists/{list-id}?expand=columns,items(expand=fields)
I could get the custom columns with this endpoint.
Updated:
IListColumnsCollectionPage columns = graphClient.Sites["b57886ef-vvvv-4d56-ad29-27266638ac3b,b62d1450-vvvv-vvvv-84a3-f6600fd6cc14"].Lists["538191ae-7802-43b5-90ec-c566b4c954b3"].Columns.Request().GetAsync().Result;
I would avoid to create QueryOption. Try to use Expand and Select method.
Example (C#...apologise I'm not familiar with VB but I hope it will easy for you to rewrite it):
await GraphClient.client.Sites[sharepointSessionId].Lists["ListTestName"].Items.Request()
.Expand(x => new
{
ListColumnTest1 = x.Fields.AdditionalData["ListColumnTest1"],
ListColumnTest2 = x.Fields.AdditionalData["ListColumnTest2"]
})
.Select(x => new
{
ListColumnTest1 = x.Fields.AdditionalData["ListColumnTest1"],
ListColumnTest2 = x.Fields.AdditionalData["ListColumnTest2"]
})
.GetAsync();

Define a predecessor when using Rally WSAPI to add user story

I'm working on a .NET application to add user stories to our Rally workspace, and I'd like to set one of the user stories as a predecessor to the next one. I can add the stories just fine, but the predecessor/successor relationship isn't being created. I'm not getting any errors, it's just not creating the predecessor. (I'm using the Rally.RestApi .NET library).
I have the _ref value for the first story, and I've tried setting the "Predecessors" property on the DynamicJsonObject to that.
followUpStory["Predecessors"] = firstStoryRef;
I also tried creating a string array, no luck.
followUpStory["Predecessors"] = new string[] { firstStoryRef };
I kept the code examples to a minimum since the stories are being created fine and this is the only issue, but let me know if sharing more would be helpful.
The easiest way is to use the AddToCollection method. Check out the docs:
http://rallytools.github.io/RallyRestToolkitFor.NET/html/efed9f73-559a-3ef8-5cd7-e3039040c87d.htm
So, something like this:
DynamicJsonObject firstStory = new DynamicJsonObject();
firstStory["_ref"] = firstStoryRef;
List<DynamicJsonObject> predecessors = new List<DynamicJsonObject>() { firstStory};
OperationResult updateResult = restApi.AddToCollection(followUpStoryRef, "Predecessors", predecessors);

Yii dependency injection basic

Can anyone explain me DI basics please? I understand what it is, but I don't really know now, how to use DI container in practice. For example, I have 2 functions in the same controller:
public function actionIndex()
{
$productsModel = new Products();
$productsFormModel = new ProductsForm();
$informationFormModel = new InformationForm();
....
}
public function actionInformation()
{
$productsModel = new Products();
$productsFormModel = new ProductsForm();
$informationFormModel = new InformationForm();
....
}
So my two questions is:
As you see above, I use same models in these functions. It is good idea to initialized them into "public function init() {}" and then use them in all class globally or this is bad idea?
I think it should be better if these models would be injected into this controller, right? How to do it correctly?
I was created file DI.php, which I included into entry script. File content was:
<?php
\Yii::$container->set('products_model', 'app\models\Products');
\Yii::$container->set('products_form', 'app\models\ProductsForm');
\Yii::$container->set('information_form', 'app\models\InformationForm');
?>
So then I was able to get class app\models\Products instance globally (in every controller, view or model):
$instance_products = \Yii::$container->get('products_model');
$instance_products_form = \Yii::$container->get('products_form');
$instance_information_form = \Yii::$container->get('information_form');
But this is bad idea, right?
Please, answer someone my two questions. :)
Thanks!
Keeping things DRY is always a good idea. The classes seem very related, so I suggest making this relationship explicit by creating a new model (e.g. ProductsInfo). One could name the controller accordingly (ProductsInfoController), thereby clarifying the application structure.
Use dependency injection sparingly. If there is a different way way, use that instead. DI isn't a good fit for the described use-case.

Auto generated linq class is empty?

This is a continuation of my previous question: Could not find an implementation of the query pattern
I'm trying to insert a new 'Inschrijving' into my database. I try this with the following code:
[OperationContract]
public void insertInschrijving(Inschrijvingen inschrijving)
{
var context = new DataClassesDataContext();
context.Inschrijvingens.InsertOnSubmit(inschrijving);
dc.SubmitChanges();
}
But the context.Inschrijvingens.InsertOnSubmit(inschrijving); gives me the following error:
cannot convert from 'OndernemersAward.Web.Service.Inschrijvingen' to 'OndernemersAward.Web.Inschrijvingen'
I call the method in my main page:
Inschrijvingen1Client client = new Inschrijvingen1Client();
Inschrijvingen i = new Inschrijvingen();
client.insertInschrijvingCompleted += new EventHandler<System.ComponentModel.AsyncCompletedEventArgs>(client_insertInschrijvingCompleted);
client.insertInschrijvingAsync(i);
But as you can see there appears to be something wrong with my Inschrijvingen class, which is auto generated by LINQ. (Auto generated class can be found here: http://pastebin.com/QKuAAKgV)
I'm not entirely sure what is causing this, but I assume it has something to do with the auto generated class not being correct?
Thank you for your time,
Thomas
The problem is that you've got two Inschrijvingen classes - one in the OndernemersAward.Web.Service namespace, and one in the OndernemersAward.Web namespace.
You either need to change the codebase so that you've only got one class, or you need to convert from one type to the other.

How can I access a HashMap using Expression Language

I'm having some problems on manipulating data in EL / JSP.
I have two variables in my Action (I'm using Struts2 btw) they are:
private List<Appointment> appointment;
private Map<Integer, String> doctors;
Appointment has the attribute docID and the doctors list uses this to identify the Doctor full name; I want in my JSP to get the doctor full name. That is, I want this:
${doctors[${appointment.docID}]}
However this dont work. Any idean on how to get this working?
You don't need to open another EL-expression. Just remove the inner-one:
${doctors[appointment.docID]}