Right away i just try to explain my problem:
Using BlazeDS i got the following Javaclasses:
DatabaseService.java:
public class Database {
private Category helpCat = null;
private Category root = new Category(1, "root", null, null);
private List<Article> database;
public Database()
{
// ------------ tree -----------------------------------------------------------------------
List<Category> level_one = new ArrayList<Category>();
List<Category> level_two_computer = new ArrayList<Category>();
List<Category> level_tree_hardware = new ArrayList<Category>();
// Level 1
Category buecher = new Category(2, "buecher", root, null);
Category computer = new Category(3, "computer", root, level_two_computer);
level_one.add(buecher);
level_one.add(computer);
//Level 2
Category hardware = new Category(4, "hardware", computer, level_tree_hardware);
Category software = new Category(5, "software", computer, null);
level_two_computer.add(hardware);
level_two_computer.add(software);
//Level 3
Category graphic = new Category(6, "graphic", hardware, null);
Category sound = new Category(7, "sound", hardware, null);
level_tree_hardware.add(graphic);
level_tree_hardware.add(sound);
// Level 0
root.addChilds(level_one);
// ------ tree end ----------------------------------------------------------------------------
database = new ArrayList<Article>();
try {
add(new Book("Per Anhalter durch die Galaxis", "42", Articletype.BOOK, 795, "Per Anhalter durch die Galaxiss", "Douglas Adams", "Heyne Verlag", "Taschenbuch", "3453146972"), buecher);
add(new Book("Harry Potter und der Stein der Weisen", "descriptionShort", Articletype.BOOK, 1299, "Harry Potter und der Stein der Weisen", "Joanne K. Rowling", "Carlsen Verlag GmbH", "gebunden", "3551551677"), buecher);
add(new Book("Harry Potter und die Kammer des Schreckens", "descriptionShort", Articletype.BOOK, 1499, "Harry Potter und die Kammer des Schreckens", "Joanne K. Rowling", "Carlsen Verlag GmbH", "gebunden", "3551551677"), buecher);
add(new Hardware("nVidia GeForce 8400GS", "Graphikkarte", Articletype.HARDWARE, 2665, "512 GDDR5 Speicher, DVI, 1 GPU", "MSI", "neu"), graphic);
add(new AKW("Biblis C", "Druckwasserreaktor, Preis auf Anfrage, Nur Selbstabholer", Articletype.AKW, -1, "Biblis", 0, 2525, "Siemens", 1, 2012), software);
} catch (Exception e) {
e.printStackTrace();
}
}
public List<Category> getCategories(String node) {
if(node.equalsIgnoreCase("root"))
return root.getChildren();
Category baum = null;
baum = get_node_by_name(root, node);
return baum.getChildren();
}
private Category get_node_by_name(Category localroot, String lookfor)
{
helpCat = null;
if(localroot.getChildren() != null)
{
for (int i = 0; i < localroot.getChildren().size(); ++i)
{
if(!(localroot.getChild(i).getName().equals(lookfor)))
{
get_node_by_name(localroot.getChild(i), lookfor);
}
else
{
helpCat = localroot.getChild(i);
helpCat.setParent(null);
}
}
}
return helpCat;
}
public List<Article> search(int artID, String name, Category categorie){
List<Article> ergebnis = new ArrayList<Article>();
if (artID >= 0)
{
for(int i = 0; i< database.size(); ++i){
if(database.get(i).getID() == artID)
{
ergebnis.add(database.get(i));
return ergebnis;
}
}
}
if (name != null){
for(int i = 0; i<database.size(); ++i){
if (database.get(i).getName().equalsIgnoreCase(name))
ergebnis.add(database.get(i));
}
return ergebnis;
}
if (categorie != null){
{
ergebnis.addAll(categorie.getArticles());
}
return ergebnis;
}
return database;
}
public Article add(Article newArticle, Category cat) throws Exception
{
newArticle.addCategory(cat);
if(newArticle.getID() != 0)
{
throw new Exception("Die Artikel ID wird vom DBS festgelegt!");
}
if (database.isEmpty())
{
newArticle.setID(0);
}
else
{
newArticle.setID(database.get(database.size() - 1).getID()+1);
}
database.add(newArticle);
return newArticle;
}
}
And the Category Class:
public class Category {
private int idCat;
private String nameTEST;
private Category parent = null;
private List<Article> articles = new ArrayList<Article>();
private List<Category> children = new ArrayList<Category>();
public Category(int _id, String _name, Category _parent, List<Category> _children)
{
if(_id > 0)
idCat = _id;
if(_name != null)
nameTEST = _name;
if(_parent != null)
parent = _parent;
if(_children != null)
children = _children;
}
public String toString()
{
return nameTEST;
}
void addArticle(Article article){
articles.add(article);
}
public List<Article> getAllArticles(){
List<Article> ergebnis = this.getArticles();
for (int i = 0; i<children.size();++i){
ergebnis.addAll(children.get(i).getAllArticles());
}
return ergebnis;
}
public void setID(int iD) {
idCat = iD;
}
public int getID() {
return idCat;
}
public void setName(String name) {
this.nameTEST = name;
}
public String getName() {
return nameTEST;
}
/**
* #param parent the parent to set
*/
public void setParent(Category parent)
{
this.parent = parent;
}
/**
* #return the articles
*/
public List<Article> getArticles()
{
return articles;
}
public void addChilds(List<Category> _next)
{
for (int i = 0; i < _next.size(); ++i)
{
children.add(_next.get(i));
}
}
public void addChild(Category one_next)
{
children.add(one_next);
}
public Category getChild(int index)
{
return children.get(index);
}
public void removeChild(Article article){
articles.remove(article);
}
public List<Category> getChildren()
{
return this.children;
}
}
also there are of course classes for articles and so on, but thats not important at that point.
the counterpart in flex looks like this:
Category.as
[RemoteClass(alias="PACKAGE.Category")]
public class Category
{
private var idCat:int = -1;
private var nameTEST:String = null;
private var parent:Category = null;
private var articles:ArrayCollection = new ArrayCollection;
private var children:ArrayCollection = new ArrayCollection;
public function Category(id:int, name:String, parent:Category, childlist:ArrayCollection, articles:ArrayCollection = null)
{
this.idCat = id;
this.nameTEST = name;
this.parent = parent;
this.articles = articles;
this.children = childlist;
}
public function setChildren(childList:ArrayCollection):void
{
this.children = childList;
}
public function getChildren():ArrayCollection
{
return this.children;
}
public function getName():String
{
return this.nameTEST;
}
}
Then i got a Flex service class calling BlazeDS and executing the getCategories java method. Since Flash dosn't seem to understand typed arrays, the result from that method which i get back in flex is a simple array of untyped objects (the mapping dosn't seem to work here, even tought the class category exists in flex and has the same properties).
thats the first thing. but however, i'm converting the untyped objects manually into objects of the category.as class.
the second thing is that categories have child-categories within the java object, which are also ArrayLists of the type category.java. the problem about that: my result event object only contains the first level of categories, looking into them the children are allways null. i dunno why they are empty, since they ARE part of the java object category.
and the third thing (the strangest by fast), you maybe noticed i named the properties of the category.java class strange, like idCat and nameTest instead of simply id and name. why that? because the property names of my flex result objects dont seem to change when i change the java objects properties names (result object properties are named "id" and "name" but the java class object properties are named "idCAT" and "nameTEST"). that it REALLY strange, since if i set the properties, like you see at nameTEST = "TESTNAME" it IS recogniced by flex, only the proertyNAMES dont seem to be recognized at all.
is blaze DS saving / caching the mapping configuration somewhere? how do i get it to rebuild the hole mappings IF so?
that could also explain my problem about the untyped objects i get from java, since before i changed the lists into ArrayLists they where vectors ( which blazeDS dosn't support AFAIK), and maybe not only the propertynames, but also the propertytypes are hard-mapped at some wired place and blazeds just dosn't get them refreshed.
i really like checked everything 5 times by now, even redeployed blazeds on the server to make sure no mappings left, but it didnt help at all.
ANY ideas what i could do? (exept changing to another serializer then blazeds (thats what i'm going to do if everything else fails...))
i have the same issues, but if you can warm up the tree before call the method, it will be ok.
what i mean "warm up" is you iterator the arraylist without doing anything. it is flunky why this work!
I have had similar problems with a list returned from a service not including the child elements in the list. I have found that BlazeDS can return a typed list. The two things that fixed this for me were:
a) Ensure that the returned list is of type java.util.List (not java.util.ArrayList for example).
b) Ensure that the class for the elements in the list have both public setters and getters for all entities to be returned.
For example - the following code works for me:
public class OrganisationService {
...
public List<Organisation> getOrganisations() {
List<Organisation> list = new ArrayList<Organisation>();
...
return list;
}
...
}
As mentioned elsewhere, you need to initiailize your AS3 remote objects so that it is included in the SWF during compilation.
Somewhere in your code, add:
var cat:Category = new Category();
var art:Article = new Article();
That should fix your generic object issue. (I add mine all in one spot, in an application start up method).
It turns out that a simple missmatch of the classnames was the cause of all evil. still some problems to solve, but atleast i get sub-arrays returned now, only the objects are still simple AS 3 objects and not the specified "Category" and "Article" objects, but i think thats because i dont have all methods included and mapping is failing because of that.
but thanks for your offer, i appreciate that.
Related
I am currently working on an application connected to a MongoDB instance. I am having trouble where the 'id' field of my object is not being returned to me within the application but is being returned as null.
The schema has an 'entity' as defined below:
{
"entity_id": String,
"parent": String,
"relevance": boolean
}
I'm querying the collection using the Java Sync Driver (4.4.1) like so:
try {
Entity testDoc = collection.find(eq("entity_id", entity_id)).first();
if (testDoc != null) {
//add entity to a list
}
} catch (Exception e) {
LOGGER.log(Level.SEVERE, "Failed to get Entity", e);
}
For some reason this will give me every field in the object when I query EXCEPT the entity_id. I keep getting this returned as:
entity_id= null
Two things stick out to me. The first being that every other field is a String (originally the Id was a UUID object but I simplified while troubleshooting) and they still return if it's other fields. The second being that there is a whitespace before this null value as if it's being formatted. Other null values return as field=null instead of field= null
I was looking to see if there is some security setting preventing things from being labeled as *_id or *id from being returned but I have found no such instance.
Edit: Here is the Entity Pojo for clarity
public class Entity {
#BsonProperty(value = "entity_id")
private String entityID;
#BsonProperty(value = "parent")
private String parent;
#Deprecated
#BsonProperty(value = "relevance")
private boolean relevance;
public Entity() {}
public Entity(String entityID, String parent, Boolean relevance) {
this.entityID = entityID;
this.parent = parent;
this.relevance = relevance;
}
public String getEntityID() {
return entityID;
}
public void setEntityID(String entityID) {
this.entityID = entityID;
}
public String getParent() {
return parent;
}
public void setParent(String parent) {
this.parent = parent;
}
public boolean isRelevant() {
return relevance;
}
public void relevance(boolean relevance) {
this.relevance = relevance;
}
}
So update for anyone watching this, it appears to have been an issue with my Eclipse IDE.
I reimported the project into IntelliJ Community Edition and rebuilt the Maven project, etc... After doing so, the test cases passed and my entityID returns in the query. Hopefully if anyone else runs into this issue they can do something similar.
I am fairly new to java and working on a project to simulate a CPU scheduler in Java and i am using a linked list to store each process object that is read in from a external master list. When I test print the processes and the variables they contain, everything comes out as expected but whenever I try and do something with them it stops working.
public class process
String ID;
int Arrive;
int ExecSize;
int Execstore;
int Tstart;
int Tend;
int quant;
public process(String ID,int Arrive,int ExecSize) {
this.ID = ID;
this.Arrive = Arrive;
this.ExecSize = ExecSize;
this.Execstore=ExecSize;
this.Tend = 0;
this.Tstart = 0;
this.quant = 4;
}
public void setquant(int update) {
this.quant = update;
}
public int getquant() {
return quant;
}
public void setExecSize(int update) {
this.ExecSize = update;
}
public void setTend(int update) {
this.Tend = update;
}
public void setTstart(int update) {
this.Tstart = update;
}
String getID() {
return ID;
}
int getArrive() {
return Arrive;
}
int getExecSize() {
return ExecSize;
}
int getTstart() {
return Tstart;
}
int getTend() {
return Tend;
}
int getExecstore() {
return Execstore;
}
and this is the class used for the simulation
public class fcfs {
int disp;
int Ttotal = 0;
int Exec;
int Turn;
int Wait;
String output;
LinkedList<process> Que = new LinkedList<process>();
LinkedList<process> Quecleared = new LinkedList<process>();
public fcfs(LinkedList<process> B,int D) {
Que.addAll(B);
disp=D;
}
public void run()
{
while (Que != null)
{
Ttotal = Ttotal + disp;
System.out.println(Que.getFirst().getExecSize());
Exec=Que.getFirst().getExecSize();
output += String.format("T%d: %s\n",Ttotal,Que.getFirst().getID());
Que.getFirst().setTstart(Ttotal);
Ttotal = Ttotal+Exec;
Que.getFirst().setTend(Ttotal);
Quecleared.add(Que.poll());
}
}
So whenever i use System.out.println I get the expected result that I read into the list. But anything else I try to do in reference to elements of the process object will not work. Any help would be greatly appreciated
while (!Que.isEmpty())
{
Ttotal = Ttotal + disp;
System.out.println(Que.peekFirst().getExecSize());
Exec=Que.peekFirst().getExecSize();
output += String.format("T%d: %s\n",Ttotal,Que.peekFirst().getID());
Que.peekFirst().setTstart(Ttotal);
Ttotal = Ttotal+Exec;
Que.peekFirst().setTend(Ttotal);
Quecleared.add(Que.pollFirst());
}
This shouldn't throw an error on Exec = Que.peekFirst().getExecSize();
That error is thrown when your container is empty.
EDIT
In your code you specified the condition Que != null. In java once an object has been instantiated it is no longer considered null even if it IS empty. Most likely what was happening here is you continued iterating through your while(Que != null) loop until you had called Que.poll() on all elements of the list.
After clearing the list you did not exit the loop because Que still was not null. Then calling getFirst() on the empty instance of a LinkedList threw an exception.
A similar situation can be seen here with null vs empty strings:
Difference between null and empty ("") Java String
EDIT 2
It also appears that your class methods for getID(), getExecSize(), etc are passing values by reference as opposed to copying their value. Thus any change you make after passing the reference from queue will alter any copies you tried to make of it.
This can be best avoided by creating a new instance of an object and returning that from your function. Shown in an answer on the question linked below:
class Foo {
private Bar myBar;
public Foo deepCopy() {
Foo newFoo = new Foo();
newFoo.myBar = myBar.clone(); //or new Bar(myBar) or myBar.deepCopy or ...
return newFoo;
}
}
For more information on ways to pass values as opposed to reference values of your pre-existing instances, as well as what a shallow copy actually is, check this link: In Java, what is a shallow copy?
I'm trying to randomly generate a tree structure of objects that look something like the following:
Branch parent = new Branch("Start");
Branch branch1 = new Branch(parent, "Branch 1");
Branch branch2 = new Branch(parent, "Branch 2");
Branch branch21 = new Branch(branch2, "Branch 2.1");
Branch branch22 = new Branch(branch2, "Branch 2.2");
I know how to create objects manually, and how to generate random numbers, and I've seen some stuff on randomly generating nodes for creating fractals, but I'm pretty lost all the sudden, as I've never had to programmatically generate objects before.
Any ideas as to where to start, or what technique to use would be appreciated.
Typically, when building such items it's good to have a designed in and out. Otherwise, you will find yourself having to support many methods of application to support the intended result.
Hope this helps!
Try something along the following :)
Branch start = new Branch();
CreateChildren(start);
const int ChildrenLimitCheck = 0;
private void CreateChildren(Branch parent) {
//Use a limit variable so that you can decrease, and if it's equal to a sepcific number(usually 0) exit.
int Limit = (int) (Math.random() * 5);
//Call the function that's recursive, inside of a function that isn't recursive. This gives you a clean way to interface with the recursive function without excessive lines of code in other areas
generateChildren(parent,Limit);
}
private void generateChildren(Branch parent,int limit) {
//Check to see if we've hit our minimum. If so, exit out of the logic
if(limit == ChildrenLimitCheck)
return;
//Specify the random number of branches created in this instance
int numberOfBranches = (int) (Math.random() * 5);
for (int i = 0; i < numberOfBranches; i++) {
Branch child = new Branch(parent);
parent.Children.Add(child);
//Depending on what you want to do, either pass i or pass limit. If you don't use limit, you can remove it from this function :)
//If you pass i, try doing:
//for (int i = numberOfBranches; i > 0; i--)
//So that you can eventually get down to 0, to automatically stop your recursive calls with the above return statement.
//Seems you just want to run a loop for xxx number of times. This will still grant that, but you won't have to guess the upper limit
//of numberOfBranches to exit on, and you'll be able to exit cleanly
//This may be what caused your stackoverflow error. For all recursive functions, you need an exit condition or it will run indefinately
generateChildren(child,--limit);
//generateChildren(child,i);
}
}
I do this quite often and I can definately help in some areas of efficiency.
Try logic similar to the following. Place a breakpoint at Console.Write to see depth. This is a C++ object oriented approach, which I personally prefer over LINQ for performance. I didn't fine tune this, so LINQ may be faster. But if you know what you're doing, you can significantly increase performance via custom methods and inheritance.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication11
{
public class Branch
{
//Branch Name
public string BranchName { get; set; }
//Add depth
public List<Branch> Children = new List<Branch>();
//Add a parent
public Branch Parent = null;
public Branch()
{
}
public Branch(string BranchName)
{
this.BranchName = BranchName;
}
public Branch(Branch Parent, string BranchName)
{
this.Parent = Parent;
this.BranchName = BranchName;
}
//Internal Functions
public bool HasParent()
{
return this.Parent != null;
}
public Branch getParent()
{
return this.Parent;
}
}
//Wrap a list inside of a class so we can have leverage over the add, and create our own functions for our need
public class BranchList
{
public List<Branch> branchParentList = new List<Branch>();
public void AddBranchToParent(Branch parent, Branch child)
{
foreach (Branch node in branchParentList)
{
if (node == parent)
{
node.Children.Add(child);
}
}
}
public void AddBranchAsChild(string parent, Branch child)
{
foreach (Branch node in branchParentList)
{
if (node.BranchName == parent)
{
node.Children.Add(child);
return;//Exit out, don't do the other loop. We found it
}
//Depth
AddBranchAsChildInChildren(node, child,parent);
}
}
public void AddBranchAsChildInChildren(Branch branch,Branch Child,string parent)
{
foreach(Branch child in branch.Children)
{
if (child.BranchName == parent)
child.Children.Add(Child);
}
}
public void AddBranchAsChildInChildren(Branch branch, string Child, string parent)
{
foreach (Branch child in branch.Children)
{
if (child.BranchName == parent)
child.Children.Add(new Branch() { BranchName=Child });
}
}
public void AddBranchAsChild(string parent, string child)
{
foreach (Branch node in branchParentList)
{
if (node.BranchName == parent)
{
node.Children.Add(new Branch() { BranchName = child });
return;
}
//Depth
AddBranchAsChildInChildren(node, child, parent);
}
}
public void AddBranchAsParent(Branch Branch, Branch Child)
{
if (branchParentList.Contains(Branch) == false)
throw new Exception("Parent exists");
foreach (Branch b in branchParentList)
{
if (b == Child)
{
b.Parent = Branch;
}
}
}
public void AddParent(Branch Parent)
{
if (branchParentList.Contains(Parent))
throw new Exception("Parent exists");
this.branchParentList.Add(Parent);
}
}
//Wrap the list, use it as an interface
public class BranchManager
{
public BranchList branchList = new BranchList();
public BranchManager()
{
}
public void AddParent(Branch Branch)
{
branchList.AddParent(Branch);
}
public void AddBranchAsChild(Branch Parent, Branch Child)
{
branchList.AddBranchToParent(Parent, Child);
}
public void AddBranchAsChild(string ParentName, Branch Child)
{
branchList.AddBranchAsChild(ParentName, Child);
}
public void AddBranchAsChild(string ParentName, string ChildName)
{
branchList.AddBranchAsChild(ParentName, ChildName);
}
}
class Program
{
static void Main(string[] args)
{
/*
Branch parent = new Branch("Start");
Branch branch1 = new Branch(parent, "Branch 1");
Branch branch2 = new Branch(parent, "Branch 2");
Branch branch21 = new Branch(branch2, "Branch 2.1");
Branch branch22 = new Branch(branch2, "Branch 2.2");
*/
BranchManager branchManager = new BranchManager();
branchManager.AddParent(new Branch("Start"));
branchManager.AddBranchAsChild("Start", "Branch 1");
branchManager.AddBranchAsChild("Start", "Branch 2");
branchManager.AddBranchAsChild("Branch 2", "Branch 2.1");
branchManager.AddBranchAsChild("Branch 2", "Branch 2.2");
Console.WriteLine(branchManager.branchList.branchParentList.Count);
}
}
}
Best guess so far, using a recursive function to handle the randomly generating children & parents:
Branch start = new Branch();
generateChildren(start);
private void generateChildren(Branch parent) {
int numberOfBranches = (int) (Math.random() * 5);
for (int i = 0; i < numberOfBranches; i++) {
Branch child = new Branch(parent);
generateChildren(child);
}
}
It properly creates a list of Branch objects with linked parents. I ran into a StackOverflow error until I wrapped it in a counter that limits the total number of branches.
The real question is: Is there a non-recursive way to handle it?
I have a static data inside my arraylist in a controller package. These are my codes in the controller package.
for(int i=0;i<studentPic.length;i++){
//i want to update the value of zero
mStudentModels.add(new StudentModel(studentPic[i],status[i],studentName[i],courseAndYear[i],0));
}
public List<StudentModel> getStudentModels (){
return mStudentModels;
}
Now i want to update a certain data if it meets a certain condition:
private void stopCountdown() {
if (mTask != null) {
mTask.interrupt();
List<StudentModel> studentModels = studentData.getStudentModels();
studentData = new StudentData();
for(int i=0;i<studentModels.size();i++){
StudentModel studentModel = studentModels.get(i);
if(studentModels.get(i).getStatus()=="PRESENT"){
mFirebaseDatabase.child("attendance").child(formattedDate).child("present").push().setValue(studentModel);
}else if(studentModels.get(i).getStatus()=="LATE"){
mFirebaseDatabase.child("attendance").child(formattedDate).child("late").push().setValue(studentModel);
}else{
//i want to update the value of zero here
int absences = studentModel.getNumOfAbsences();
studentModel.setNumOfAbsences(absences+1);
mFirebaseDatabase.child("attendance").child(formattedDate).child("absent").push().setValue(studentModel);
}
}
}
}
The problem is if i call studentData.getStudentModels(); the value always remains zero. Whats the problem with that?
Here's my controller:
public class StudentData {
private List<StudentModel> mStudentModels;
public void setmStudentModels(List<StudentModel> mStudentModels) {
this.mStudentModels = mStudentModels;
}
public StudentData(){
mStudentModels = new ArrayList<>();
int[] studentPic = {R.drawable.boy1, R.drawable.boy2, R.drawable.girl1, R.drawable.girl2, R.drawable.girl3,
R.drawable.girl4, R.drawable.girl5, R.drawable.boy3, R.drawable.girl6, R.drawable.girl7,
R.drawable.boy4, R.drawable.girl8, R.drawable.girl9, R.drawable.girl10, R.drawable.boy5,
R.drawable.girl1, R.drawable.girl12, R.drawable.girl13, R.drawable.boy6, R.drawable.girl14};
String[] status = {"ABSENT","LATE","PRESENT","PRESENT","PRESENT","PRESENT","PRESENT","PRESENT","PRESENT","PRESENT","PRESENT","PRESENT",
"PRESENT","PRESENT","PRESENT","ABSENT","PRESENT","PRESENT","PRESENT","PRESENT"};
String[] studentName = {"Andy Lim", "Benjamin Adams", "Karen Healey", "Anne Pierre", "Corine Alvarez",
"Emily Hedrick", "Courtney Quick", "Oscar Renteria", "Ellen Joy", "Jesse Ramer",
"Jackson Beck", "Alicia Hofer", "Jenae Rupp", "Allison Beitler", "Martin Hofkamp",
"Emma Ruth", "Kathryn Berg", "Michelle Salgado", "Lewis Caskey", "Elizabeth Core"};
String[] courseAndYear = {"BSIT-3", "BSIT 2", "BSIT-3","BSCS-3" , "BSCS-2", "BSIT-3", "BSIT-2", "BSIT-3", "BSIT-2", "BSIT-3",
"BSCS-3", "BSCS-2", "BSCS-3", "BSCS-2", "BSCS-3", "BSIT-3", "BSCS-2", "BSIT-2", "BSCS-3", "BSCS-2"};
for(int i=0;i<studentPic.length;i++){
mStudentModels.add(new StudentModel(studentPic[i],status[i],studentName[i],courseAndYear[i],0));
}
}
public List<StudentModel> getStudentModels (){
return mStudentModels;
}
}
My model looks like this:
public StudentModel(int studentPic, String status, String studentName, String courseAndYear, int numOfAbsences) {
this.studentPic = studentPic;
this.status = status;
this.studentName = studentName;
this.courseAndYear = courseAndYear;
this.numOfAbsences = numOfAbsences;
}
Looks like below checks need to do:
Whether studentPic is not empty.
Whether mStudentModels is not empty (Mainly whether mStudentModels is getting added before the call of stopCountdown() method).
If it does not fix the issue, please provide more information on the code of Controller side.
In Lucene, I am using the TaxonomyReader to read an index of a taxonomy stored in my disk. For a given category, I need to find all categories that are its children. However, in the Lucene's API I could find a method to retrieve the parent but not with the children. There is a method called getChildrenArrays() that returns a ChildrenArrays object. As you can see, this class only has two methods:
getYoungestChildArray
getOlderSiblingArray
I want to implement Enumerator using these two methods. Does someone know how to do it?
I got the following:
private class EnumChildren implements Enumeration<Integer> {
int category, current;
int[] next, first;
public EnumChildren(int category) {
ChildrenArrays childrenArrays = tr.getChildrenArrays();
first = childrenArrays.getYoungestChildArray();
next = childrenArrays.getOlderSiblingArray();
current = first[category];
}
public boolean hasChildren() {
return (current != TaxonomyReader.INVALID_ORDINAL);
}
#Override
public boolean hasMoreElements() {
current = next[current];
return (current != TaxonomyReader.INVALID_ORDINAL);
}
#Override
public Integer nextElement() {
return current;
}
}
Ans is used as:
ordinal = tr.getOrdinal(new CategoryPath(nodeCategory.getPath(), '/'));
EnumChildren childrenEnumeration = new EnumChildren(ordinal);
if (childrenEnumeration.hasChildren()) {
do {
int current = childrenEnumeration.nextElement();
Category child = new Category(tr.getPath(current).toString());
addChildren(child);
nodeCategory.children.add(child);
} while (childrenEnumeration.hasMoreElements());
}