So I had list of tuples like this:
val rooms = List(("Hi", "mom"),("hi", "dad"))
val foo = rooms.map(arg =>{
var fields = List
( new JField("greeting",arg._1),
new JField("recipient",arg._2))
new JObject(fields)})
And there was much happiness in the land, but when I changed list of room like so:
case class Room(greeting:String, recipient:String)
val rooms = List(Room("Hi", "mom"),Room("hi", "dad"))
val foo = rooms.map(arg =>{
var fields = List
( new JField("greeting",arg.greeting),
new JField("recipient",arg.recipient))
new JObject(fields)})
I get:
[error] <file>: type mismatch;
[error] found : scala.collection.immutable.List.type (with underlying type object List)
[error] required: List[blueeyes.json.JsonAST.JValue]
[error] new JArray(fields)
So it appears that the list is now of Object instead of JField as it was before, why is that?
It works if you don't detach the List from its (:
var fields = List(
new JField("greeting", arg.greeting),
new JField("recipient", arg.recipient))
Basically, it's parsing like this:
var fields = List // assign the List companion object
(new JField("greeting", arg.greeting), // construct a tuple with two items
new JField("recipient", arg.recipient)) // ...but don't use or assign it
new JObject(fields) // Make JObject containing the type
The error comes because the JObject constructor expects a JValue but you are passing it fields which has type List.type.
Related
I want to create a list in flutter that contains variable. Now when I am trying to edit the contents of the list, it actually gets stored in the list itself. For eg.,
static var _ratingSelected = "";
static var _disconnectSelected = "";
static var _uTypeSelected = "";
List finalSelectedList = [_uTypeSelected,_disconnectSelected,_ratingSelected];
This is my list, when I will edit the list, like,
finalSelectedList[0] = "Main";
The output list will be like
finalSelectedList = ["Main",_disconnectSelected,_ratingSelected];
It will edit the finalSelectedList[0] position of the list but not the variable _uTypeSelected. Is there any way so that the value gets stored in the variable _uTypeSelected and not at the position finalSelectedList[0]?
There is no way to do that. If you use finalSelectedList[0].someProp = "Main"; where the variables are instances of some classes that have a someProp property, then it would work, because there is an additional abstraction. Strings are primitive values and copied by value when added to a list and therefore there is no connection left between list entry and variable.
class Foo {
Foo(this.someProp);
String someProp;
}
static var _ratingSelected = Foo("");
static var _disconnectSelected = Foo("");
static var _uTypeSelected = Foo("");
List finalSelectedList = [_uTypeSelected,_disconnectSelected,_ratingSelected];
finalSelectedList[0].someProp = "Main";
Am trying to read some values from database and display it in a List.
list = new List();
list.setSize(30, 280);
try {
Class.forName("com.mysql.jdbc.Driver");
connect = DriverManager
.getConnection("jdbc:mysql://localhost:3306/project?"
+ "user=root&password=virus");
statement = connect.createStatement();
preparedStatement = connect
.prepareStatement("select subname from subject");
rs=preparedStatement.executeQuery();
while (rs.next()) {
subject = rs.getString("subname");
list.add(subject);
}
}
The import statement for List is-
import java.awt.List;
So I think List control is not available in JavaFX.
I tried to place the List in HBox -
hb.getChildren().addAll(addSubName, list, b2);
Then I got an error -
method addAll in interface ObservableList<E> cannot be applied to given types;
required: Node[]
found: TextField,List,Button
reason: varargs mismatch; List cannot be converted to Node
where E is a type-variable:
E extends Object declared in interface ObservableList
Is this error correctable ? If not, tell me about a control that can be used as a substitute for List in JavaFX.
Simple dart code:
class User {
String name;
User(this.name);
}
main() {
List<User> users = [new User('Freewind')];
var list = new List.from(users);
print(list.first.name); // ***
}
Notice the line ends with '// *'.
My IDEA editor doesn't recognize list.first as a User, since it can't do the autocompletion when I typed '.name'.
So I have to declare the type:
List<User> list = new List.from(users);
It works but I want to know if there is any other way to let compiler know list has type List<User>?
I tried:
var list = new List<User>.from(users);
Which has wrong syntax.
This one works for me in DartEditor (no error/warning/hint) and of course executes successfully
var list = new List<User>.from(users);
Given the following snippet from my test:
var mockProvider = MockRepository.GenerateMock<IItemProvider>();
var target = new ItemService(mockProvider);
target.SaveItem(item);
Internally target.SaveItem makes a call like this:
provider.SaveItem(new SaveContract(item.Id, user, contents)); where provider is the local name for the mockProvider passed in.
How do I:
Verify provider.SaveItem is called whilst also
Asserting that the values of item.Id, user and contents are as they should be.
I think I might be able to use mockProvider.AssertWasCalled but can't figure out the syntax to set the condition of the parameters passed to the constructor of SaveContract.
TIA
Ok so based on this I did something like the following:
var mockProvider = MockRepository.GenerateMock<IItemProvider>();
var target = new ItemService(mockProvider);
Item testItem = null;
mockProvider.Expect(c => c.SaveItem(Arg<Item>.Is.Anything))
.WhenCalled(call =>
{
testItem = (Item)call.Arguments[0];
});
target.SaveItem(item);//item initialised elsewhere
Assert.AreEqual(item.Id, testItem.Id);
I'm using Qjson to parse a json object that is returned from a web service. I'm stuck on handling an array of complex ojects.
At the first level the web service returns a map consisting of "error", "id", and "return". If there are no errors I can get the first level value by using
nestedMap = m_jsonObject["result"].toMap();
group = new Group();
group->Caption = nestedMap["Caption"].toString();
group->CollectionCount = nestedMap["CollectionCount"].toInt();
I can even get a date item value that is at the second level using
group->ModifiedOn = nestedMap["ModifiedOn"].toMap()["Value"].toDateTime();
I have an object called "Elements" that consists of 29 key-value pairs. The web service is returning an array of these "Elements" and I am unable to find the right way to parse it. In the header file the container for the elements is defined as
QList<GroupElement> Elements;
The line
group->Elements = nestedMap["Elements"].toList();
causes the compiler to throw an error 'error: no match for 'operator=' in '((MyClass*)this)->MyClass::group->Group::Elements = QVariant::toMap() const()'
I would like to learn the correct syntax to put this element into the class.
Update: I wrote another function to convert the QVariantMap object to a
first:
The group-> Elements object was changed to a
class ParentClass{
QList<SharedDataPointer<Address> > Elements;
other class memmbers...
};
Second:
A method to convert the QMap object to an Address object was created
QSharedDataPointer<Address>
API_1_6::mapToAddress(QVariantMap o)
{
QSharedDataPointer<Address> address (new Address());
address-> FirstName = o["FirstName"].toString();
address->LastName = o["LastName"].toString();
address->CompanyName = o["CompanyName"].toString();
address->Street = o["Street"].toString();
address->Street2 = o["Street2"].toString();
address->City = o["City"].toString();
address->Zip = o["Zip"].toString();
address-> State = o["State"].toString();
address->Country = o["Country"].toString();
address->Phone = o["Phone"].toString();
address->Phone2 = o["Phone2"].toString();
address-> Fax = o["Fax"].toString();
address-> Url = o["Url"].toString();
address->Email = o["Email"].toString();
address->Other = o["Other"].toString();
return address;
}
third: In the code, foreach is used to walk through the list and create and store the new objects
// get the list of the elements
elementsList = nestedMap["Elements"].toList();
// Add the element, converted to the new type, to the Elements object of the'parent' class
foreach(QVariant qElement, elementsList){
group-> Elements.append(mapToAddress(qElement))
}