Java utils source code

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

some Java utility classes that I created for some of my Closed Source projects

nandan-desai-extras/Java-Utils

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Sign In Required

Please sign in to use Codespaces.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

README.md

In this repository, I will keep uploading some Java utility classes that I’ve developed and used in my Closed Source projects.

An ArrayList class is not feasible when you have to store a lot of heavy Object s in a list. LongList class can easily store more than 100,000 elements in the form of an array in a memory-efficient way without compromising too much on read/write speed. The way this works is, it stores all the elements on the disk (secondary storage) and only stores a fixed number of elements (called a «block») into the memory. Every time you are accessing an element in LongList , you’ll be reading it from the block (which is stored in the memory) and not from the disk. Hence the speed is not compromised. For example, if you have 500,000 elements stored in LongList and the block size that you’ve defined is 1000, then you’ll be consuming the memory only for those 1000 elements and the rest of the elements will be on the disk.

/* * providing a unique ID to each LongList is required. * Block size is optional. default block size is 500. * */ //'Car' is a sample user-defined class LongListCar> carLongList = new LongList<>("car-list", 1000);
carLongList.initialize(carArrayList);
for(int i=0; icarLongList.size(); i++)< System.out.println(carLongList.get(i)); >

This can also be done like this:

  • You can choose where you want LongList to store the data on disk. You can provide the path like this:
// getCacheDir() gives you the cache directory in Android LongList.storageRootDir = getCacheDir().toString();

Current working directory is the default path where the LongList will store the data.

This class stores Java Objects on the disk. Uses LRUMap internally. I created this utility class to display ‘Recently viewed TV shows’ list shown below.

This class can be used to create Graphs (Network graphs) for Android. I didn’t find any suitable library for creating a network graph for Android and so I decided to create my own. This file has no other dependency. Just copy the file in your project and include the following in your layout (xml file) where required:

io.github.nandandesai.datamonitr.graphics.SimpleGraphView android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/networkGraph" />

(The name of the tag changes based on the package name where you place the SimpleGraphView.java file).

And then, you can build the graph as shown below:

ListSimpleGraphView.Node> nodeList = new ArrayList<>(); ListSimpleGraphView.Edge> edgeList = new ArrayList<>(); //Source-1 SimpleGraphView.Node sourceNode1 = new SimpleGraphView.Node(getResources().getDrawable(R.drawable.laptop_sample, null), "Source-1"); nodeList.add(sourceNode1); //Destination-1 SimpleGraphView.Node destNode1 = new SimpleGraphView.Node(getResources().getDrawable(R.drawable.server_icon, null), "Destination-1"); nodeList.add(destNode1); //Destination-2 SimpleGraphView.Node destNode2 = new SimpleGraphView.Node(getResources().getDrawable(R.drawable.server_icon, null), "Destination-2"); nodeList.add(destNode2); //Destination-3 SimpleGraphView.Node destNode3 = new SimpleGraphView.Node(getResources().getDrawable(R.drawable.server_icon, null), "Destination-3"); nodeList.add(destNode3); //Edge connecting Source-1 and Destination-1 SimpleGraphView.Edge edge1 = new SimpleGraphView.Edge(sourceNode1, destNode1); edge1.setUpperText("Source-1 to Destination-1"); edge1.setLowerText("More info"); edgeList.add(edge1); //Edge connecting Source-1 and Destination-2 SimpleGraphView.Edge edge2 = new SimpleGraphView.Edge(sourceNode1, destNode2); edge2.setUpperText("Source-1 to Destination-2"); edge2.setLowerText("More info 2"); edgeList.add(edge2); //Edge connecting Source-1 and Destination-3 SimpleGraphView.Edge edge3 = new SimpleGraphView.Edge(sourceNode1, destNode3); edge3.setUpperText("Source-1 to Destination-3"); edge3.setLowerText("More info 3"); edgeList.add(edge3); //create a Graph object SimpleGraphView.Graph graph = new SimpleGraphView.Graph(); //add all edges to the graph object graph.addAllEdges(edgeList); //add all nodes to the graph object graph.addAllNodes(nodeList); //find the SimpleGraphView SimpleGraphView simpleGraphView = findViewById(R.id.networkGraph); //submit graph object and let the SimpleGraphView draw it simpleGraphView.draw(graph);

The above code will create the graph as shown below: (you need to replace the code with your own drawables. The screenshot is just a demo).

I wanted to generate the Terraform configuration code in HCL and not in JSON. I wrote this simple Java class to do that. TerraformBlockGenerator.java file doesn’t have any dependency. Just include the file in your project and you’re good to go.

MapString,Object> tfAttributes = new HashMap<>(); tfAttributes.put("ami", "#expdata.aws_ami.ubuntu.id"); tfAttributes.put("instance_type", "t3.micro"); MapString, String> tags = new HashMap<>(); tags.put("Name", "Hello World"); tfAttributes.put("tags", tags); String tfResourceBlock = new TerraformBlockGenerator().generate("resource", "aws_instance", "web", tfAttributes); System.out.println(tfResourceBlock);
resource "aws_instance" "web" < ami = data.aws_ami.ubuntu.id instance_type = "t3.micro" tags < Name = "Hello World" > >

Copyright 2021 Nandan Desai

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the «Software»), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED «AS IS», WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

some Java utility classes that I created for some of my Closed Source projects

Источник

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

Collection of java utility classes — Ensemble de classes utilitaires java

License

nrc-cnrc/java-utils

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Sign In Required

Please sign in to use Codespaces.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

README.md

java-utils is a collection of java utility classes used in various project at the National Research Council of Canada.

Many of these classes provide functionality similar to functionality found in frameworks like Spring. In such cases, the reason why we implemented our own version of the functionality may be that our version:

  • is more lightweight and easier to use
  • provides some additional features
  • was implemented at a time when there was no existing alternative
  • or it could just be that we just did not know that there already was a usable implementation available

Java-utils is a Maven project with several sub-modules:

Оцените статью