How to name a Class for container of resulted items of a clicked item? - class

I have an item X that when clicked will be splitted into 1 or more items.
So I have an ArrayList that will be returning the items but I am not sure of how to name the class of that ArrayList.
the class will hold itemName and Count.
public class WhatNameShouldItBe
{
public int itemId ...;
public int itemCount ...;
}
ArrayList<WhatNameShouldItBe> resultItems;
PS: Sorry about the question title ... if you need more information let me know was not sure if anything else was needed to such a question.
Some names I was thinking about:
ExtractedItems but since it is not extracted yet doesnt sound right to me...
ResultedItems or ResultItems
ClickableItemsResult
It is a list of items that can be given to the user when they use a clickable item

English isn't my native language, but I'll give it a shot anyway : SpawnedItem ?

You have a class describing something that has properties. Say it's a Widget. Each widget has an ID and a Count.
You then want a list of these Widgets. No problem, you make an ArrayList and name it something appropriate to what purpose the list serves:
public class Widget
{
public int itemId ...;
public int itemCount ...;
}
ArrayList<Widget> ClickedWidgets;
If the main purpose of the list is to differentiate those Widgets that were clicked on, then call it ClickedWidgets or something similar.
Remember, the most important thing about naming variables in programming is that it makes sense to you. (It also helps if others can figure it out later!)

A little bit vague on the question, but perhaps "Fragments" would work.

Related

How to make a class-wide ID number

Perhaps I am simply reading old material, but I can't see a way to do something seemingly very simple.
I have a class called Robot, each instance of which needs a unique id. The id is simply an Int that should be 1,2,3... The normal solution would be to have a class var MaxId that you increment in the init() and then assign that to the instance's id.
Swift (4?) does not have class vars, but does have computed properties at the class level. However, I am a bit mystified about how one might use this to do a MaxId. Am I missing something blindingly obvious here?
a unique id. The id is simply an Int that should be 1,2,3.
You can certainly use a static property and increment it, but note that
those are two different requirements. If all you really want is a unique id, there is no need for the “least available integer” approach. Just use the built-in UUID struct and move on.
Static variables are essentially class variables. Try this in a playground:
class Numbered {
static var serial: Int = 1
let myID: Int
init() {
myID = Numbered.serial
Numbered.serial = Numbered.serial + 1
}
}
print(Numbered().myID)
print(Numbered().myID)

Adding elements to TableViewer from a collection?

So I'm trying to make a simple program that takes in some basic information about a loan, and turns it into an amortization table.
I am using WindowBuilder for this, and thus I have a Tableviewer that is supposed to have a column for Month, interest, payment, ect.
Unfortunately, I can't figure out how to get the table to actually display information. I have a Loan object that generates an ArrayList of month objects (each month being one row of the table), but from what I've read online, it's not as simple as telling the Tableviewer to populate each column with a variable from that arraylist.
I have set my Content Provider to be a Loan object, which contains an Arraylist of Month Objects, and each Month object has a getter for each column.
How do I go about displaying the text in each column?
Thanks.
EDIT:
So, here is the snippet of code from the example given to me below:
colFirstName.setLabelProvider(new ColumnLabelProvider() {
#Override
public String getText(Object element) {
Person p = (Person) element;
return p.getFirstName();
}});
I don't quite understand what is going on here. It's overriding the getText method, and casting the element to the type of element that has their data?
balanceCol.setLabelProvider(new ColumnLabelProvider(){
#Override
public String getText(Object element) {
Loan m = (Loan) element;
return m.getMonthObj().get(0).getMonth();
}
});
When I run this, it almost sorta works. It fills in about half the months, and then I get this error:
java.lang.ClassCastException: model.Month cannot be cast to model.Loan

In JavaFX 8 how can I bind to a computed expression?

I apologize if this is a repeat (couldn't find one) or pretty simple. I just can't find anything on it.
I would like to have a dynamic title on my primary stage based on values in a table. However I can't seem to find a way to handle this without have to code it on an event listener. I'd rather create a binding if possible.
Something like this:
primaryStage.titleProperty().bind("Open Items" + tableView.getItems().size());
primaryStage.titleProperty().bind(Bindings.size(tableView.getItems()).asString("Open Items %d"));
or
primaryStage.titleProperty().bind(Bindings.createStringBinding(() ->
"Open Items "+tableView.getItems().size(),
tableView.getItems());
or
primaryStage.titleProperty().bind(new StringBinding() {
{ bind(tableView.getItems()); }
#Override
public String computeValue() {
return "Open Items "+tableView.getItems().size();
}
});
and probably many other ways...

How should the enum type look like in the bottom part of a UML diagram?

I know what the enum type should look like in the middle section of a UML diagram but how should it look in the bottom section where it contains the actions/methods of the class? Isn't there accessors and mutators for enum types?
+GetTypeOfAttack:TypeOfAttack
Is probably the answer but you need to ask yourself a question about whether this is a 'classic' accessor mutator
A classic accessor/mutator (getter/setter) is usually like the following
private bool hiddenField = true;
//Accessor
public bool GetHiddenField()
{
return hiddenField;
}
//mutator
public void SetHiddenField(bool input)
{
hiddenField = input;
}
BUT you may (more often than not) have situations where you need to do some logic evaluation before either getting or setting the field... This is not a pure accessor/mutator but essentially it is.
In answer to your question:
+SetHiddenField(bool): void
+GetHiddenField:bool
See how they map to the previous code. +/- = public/private, (denoteParameters) and : denotes return type

Why create an instance of a class within its own definition?

I've been looking into the topic of creating instances of a class within its own definition. Something like this:
public class myClass
{
public static myClass aObject = new myClass();
public static myClass bObject = new myClass();
}
I kind-of understand how this is possible, but I'm confused as to why it would be useful.
Also, my logic says that it should be possible to do something like this:
aObject.bObject.someMethod();
aObject is an instance of myClass, so it should contain bObject, right? I feel like I'm missing some fundamental understanding of how classes work, so I would really like to know what's going on here, and why someone would want to do this.
aObject.bObject.someMethod() would definitely work if someMethod() was defined as a part of myClass. As to why something like that would be done, I'll give an example that is used in java.
Say you have a class called Color that represents colors. You can make a new color of of its RGB value with the constructor Color(byte r, byte g, byte b). There are also constants in the Color class that represent commonly used colors, like red or green or pink. You can quickly access the pink color just by saying Color.PINK, since PINK is a Color variable that is inside the Color class. That way you don't have to construct a new color object each time you want to use pink in a method.
aObject.bObject.someMethod();
This is like saying "of object a's object b... do something." So its like a ball (called A) has a ball inside it (called B) which has a ball inside it (called C).. ect.
A linked list is a list does something like this, in that:
class Link {
public long data; // data item
public Link next; // next link in list
// =============================================================
public Link(long value){ // constructor
data = value; // assign parameter to data's data field
}
}
Link has inside of it a pointer to another link which does the same until you make a null object.
I think this is what you were asking...