Nishtha Thakur has Published 564 Articles

How to allow only a single tree node to be selected in a JTree with Java?

Nishtha Thakur

Nishtha Thakur

Updated on 30-Jul-2019 22:30:26

361 Views

Set the selection mode to SINGLE_TREE_SELECTION, if you want only a single tree node to be selected −tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);The following is an example to allow only a single tree node to be selected in a JTree −Examplepackage my; import javax.swing.JFrame; import javax.swing.JTree; import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.TreeSelectionModel; public class SwingDemo {   ... Read More

MongoDB find() to operate on recursive search?

Nishtha Thakur

Nishtha Thakur

Updated on 30-Jul-2019 22:30:26

656 Views

Use find() with dot notation to perform recursive search. Let us first create a collection with documents −> db.findOperationDemo.insertOne({"ClientDetails":[{"ClientId":101, "ClientName":"Chris"}, {"ClientId":102, "ClientName":"Robert"}]}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd9a118b50a6c6dd317ad99") } > db.findOperationDemo.insertOne({"ClientDetails":[{"ClientId":110, "ClientName":"David"}, {"ClientId":112, "ClientName":"Mike"}]}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd9a12fb50a6c6dd317ad9a") }Following is the query ... Read More

MongoDB query to count the size of an array distinctly?

Nishtha Thakur

Nishtha Thakur

Updated on 30-Jul-2019 22:30:26

198 Views

Use DISTINCT for distinct elements and then length to get the size of array −db.yourCollectionName.distinct('yourFieldName').length;Let us first create a collection with documents −> db.countOrSizeDemo.insertOne({"StudentFirstName":"John"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd304f5b64f4b851c3a13dc") } > db.countOrSizeDemo.insertOne({"StudentFirstName":"David"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd304fab64f4b851c3a13dd") } > db.countOrSizeDemo.insertOne({"StudentFirstName":"David"}); {   ... Read More

Hygienic Macros in C

Nishtha Thakur

Nishtha Thakur

Updated on 30-Jul-2019 22:30:26

439 Views

Here we will see the Hygienic Macros in C. We know the usage of macros in C. But sometimes, it does not return the desired results because of accidental capture of identifiers.If we see the following code, we can see that it is not working properly.Example#include #define INCREMENT(i) do { ... Read More

Is there a way to limit the number of records in a certain MongoDB collection?

Nishtha Thakur

Nishtha Thakur

Updated on 30-Jul-2019 22:30:26

80 Views

Yes, you can use capped parameter along with max size. Following is the syntax −db.createCollection("yourCollectionName", {capped:true, size:yourSizeInBytes, max:howManyRecordsYouWant})Let us first create a collection with capped:true −> db.createCollection("limitTheNumberOfRecordsDemo", {capped:true, size:200024, max:3}) { "ok" : 1 }We will now create a collection with documents −> db.limitTheNumberOfRecordsDemo.insertOne({"ClientName":"James Brown"}); {    "acknowledged" : true, ... Read More

Print numbers in sequence using thread synchronization

Nishtha Thakur

Nishtha Thakur

Updated on 30-Jul-2019 22:30:26

546 Views

Here we will see how to print numbers in a correct sequence using different threads. Here we will create n number of threads, then synchronize them. The idea is, the first thread will print 1, then second thread will print 2 and so on. When one thread is trying to ... Read More

strtol() function in C++

Nishtha Thakur

Nishtha Thakur

Updated on 30-Jul-2019 22:30:26

243 Views

The strol() function is used to convert the string to long integers. It sets the pointer to point to the first character after the last one. The syntax is like below. This function is present into the cstdlib library.long int strtol(const char* str, char ** end, int base)This function takes ... Read More

How to keep two “columns” in MongoDB unique?

Nishtha Thakur

Nishtha Thakur

Updated on 30-Jul-2019 22:30:26

744 Views

Use unique and set it to TRUE. Let us implement the same by creating index and setting two columns to unique −>db.keepTwoColumnsUniqueDemo.createIndex({"StudentFirstName":1, "StudentLastName":1}, {unique:true}); {    "createdCollectionAutomatically" : true,    "numIndexesBefore" : 1,    "numIndexesAfter" : 2,    "ok" : 1 }Now you can insert documents in the above collection ... Read More

Find a strict document that contains only a specific field with a fixed length?

Nishtha Thakur

Nishtha Thakur

Updated on 30-Jul-2019 22:30:26

50 Views

You can use $where operator for this. Let us first create a collection with documents −>db.veryStrictDocumentDemo.insertOne({"StudentFirstName":"John", "StudentLastName":"Doe", "StudentAge":23}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cda4bcdb50a6c6dd317adb8") } > db.veryStrictDocumentDemo.insertOne({"StudentFirstName":"Larry"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cda4bdbb50a6c6dd317adb9") } >db.veryStrictDocumentDemo.insertOne({"StudentFirstName":"David", "StudentLastName":"Miller"}); {    "acknowledged" : true,    "insertedId" : ... Read More

Program for Christmas Tree in C

Nishtha Thakur

Nishtha Thakur

Updated on 30-Jul-2019 22:30:26

867 Views

Here we will see one interesting problem. In this problem, we will see how to print Christmas tree randomly. So the tree will be flickering like Christmas tree lights.To print a Christmas tree, we will print pyramids of various sizes just one beneath another. For the decorative leaves a random ... Read More

Advertisements