Skip to content

Mtxity/MtxUtil

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1,196 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MtxUtil

A collection of data structures and other utilities

Contents

In order of package names

MtxAddress stores and parses US and CAN address data

DB ID Generator (com.edavalos.mtx.util.db.id)

MtxAutoIdBuilder generates IDs given a specified criteria

These are its implementations:

  • MtxChecksumIdGenerator - uses the Luhn algorithm to get a unique ID.
  • MtxChecksumIterativeIdGenerator - an ordered version of MtxChecksumIdGenerator.
  • MtxIdGenerator - base class for generating IDs.
  • MtxUuidGenerator - uses passed data for hashing

DB Query Generator (com.edavalos.mtx.util.db.query)

Fluent utilities to assemble SQL statements programmatically, avoiding manual string concatenation and encouraging parameterized queries.

Core capabilities include:

  • builders for SELECT, INSERT, UPDATE, and DELETE statements
  • WHERE clause construction with grouped conditions (AND/OR), comparisons, and IN/NOT IN
  • JOIN support (INNER/LEFT/RIGHT) with ON predicates and table/column aliasing
  • ORDER BY, GROUP BY, and HAVING
  • LIMIT/OFFSET pagination
  • parameter binding (positional or named) to help prevent injection
  • safe identifier handling (table/column quoting) and configurable placeholders
  • rendering to a final SQL string plus a ready-to-bind parameter list

DB Table Data Holder (com.edavalos.mtx.util.db.table)

Specialized Field Wrappers (com.edavalos.mtx.util.db.var)

MtxRandom generates a random value of most types of primitives.

These are its implementations:

  • MtxIpRandom - uses the IPv4 address of the machine this is running on as a seed.
  • MtxMemRandom - uses the number of free RAM bytes of the machine this is running on as a seed.
  • MtxTimeRandom - uses the current time (in nanoseconds) as a seed.

MtxHash will securely encrypt sensitive strings. All implementations hash the values a couple of thousand times and add a salt at every iteration.

These are its implementations:

  • MtxSha256Hash - hashes strings with the SHA-256 algorithm. Hashes value 5,000 times.
  • MtxSha3Hash - hashes strings with the SHA3-256 algorithm. Hashes value 2,000 times.
  • MtxMD5Hash - hashes strings with the MD5 algorithm. Hashes value 9,000 times.
  • MtxHashmapHash - hashes strings with the algorithm that Java hashmaps use. Hashes value 20,000 times.

MtxEncryptor and MtxInsecureEncryptor will convert strings to gibberish and then convert them back to their original values.

  • MtxEncryptor - uses Javax.Crypto to convert strings into hashes. Slower but virtually unresolvable.
  • MtxInsecureEncryptor - uses an encryption matrix to generate hashes. Fast, and secure for most use cases.

These will take care of boilerplate file scanning as well as content parsing.

Currently, these are supported:

  • MtxFileReader - basic scanning of txt files. Will take in a filepath and provide a string array of rows.
  • MtxCsvParser - Will take in a filepath to a csv file and provide a 2D string array representing the matrix in the file.
  • MtxJsonParser - Will take in a filepath to a json file and provide a LinkedHashMap<String, Object> representing the json in the file.

MtxList is a general purpose list. It has four implementations:

  • MtxLinkedList - O(n) lookup and O(1) insert
  • MtxArrayList - O(1) lookup and O(1) insert, but periodically expensive adds
  • MtxHashList - O(1) lookup and O(1) insert, but periodically expensive removes
  • MtxStringList - O(n) lookup and O(n) insert, but O(1) toString()s
  • MtxIntrusiveLinkedList - O(n) lookup and O(1) insert, but marginally faster than MtxLinkedList

All of these support equals() and iterator() as well as the basic functions. (size(), toArray(), sort(), etc.) See the interface for a complete list.

These are simplified versions of their equivalent Java standard library implementations.

  • MtxStack - supports push(), pop() and peek()
  • MtxQueue - supports enqueue() and dequeue()

Both of these support size() and toString()

This is a representation (and real-world use case) of a multi-priority and bidirectional stack:

  • MtxElevator - controlled with queueFloor() and moveToNextFloor()

MtxMap is a general purpose key–value container for fast lookups with optional ordered or sorted iteration.

It includes variants to fit different needs:

  • hash-backed maps — average O(1) get()/put()
  • linked maps — preserves insertion order with predictable iteration
  • tree-backed maps — sorted by key with O(log n) get()/put()
  • array-backed maps — compact footprint, best for small collections

All of these support equals() and iterator() as well as the basic functions. (get(), put(), remove(), containsKey(), containsValue(), keySet(), values(), entrySet(), size(), etc.) See the interface for a complete list.

MtxMath holds a collection of mathematical utility classes, constants, and methods:

  • MtxFactorial - procedurally generates an infinite number of factorial integers
  • MtxFibonacci - procedurally generates an infinite number of fibonacci integers
  • MtxCatalan - procedurally generates an infinite number of catalan integers
  • MtxStats - takes an array of numbers and calculates values with them such as mean, median, mode, standard deviation, variance, and total
  • PI, TAU, E, Y, and PHI - public constants holding semi-frequently used mathematical values
  • isPrime() - checks if an integer is a prime number
  • quadraticFormulaSolver() - gets the positive x value from a quadratic equation given a, b, and c
  • twoDimensionArrayCopy() - copies a two dimension integer array
  • min() and max() - gets the min or max of an array or list of doubles or integers

MtxRomanNumeral converts year integers into roman numerals and roman numeral strings into year integers.

Running Total Integer Analyzer (com.edavalos.mtx.util.math)

MtxRunningTotal takes in integers (as a stream or individually) then runs calculations on the last x values.

MtxStopwatch begins counting when told to and marks laps or pauses / resets counter when told to as well. Core methods are:

  • start() - begins counting (or continues where paused)
  • lap() - marks a lap but continues counting
  • stop() - marks a lap and pauses counting
  • reset() - clears all laps and resets counting to zero (but does not start counting again)
  • getLaps() - gets all marked laps since last reset or creation

HTTP Request Reader (com.edavalos.mtx.util.network)

MtxRequestReader takes a serialized HTTP request and parses it. Something like: GET /test/14/twelve?key1=value1&key2=value2 HTTP/1.1 would be consumed by an MtxRequestReader object to have the following properties accessible:

  • requestMethod: GET
  • httpVersion: HTTP/1.1
  • fixedParams: ["test", "14", "twelve"]
  • anchor: null
  • queryParams: key1=value1, key2=value2
  • hasQueryParams: true
  • hasAnchor: false

MtxSet is a general purpose set. It has six implementations:

  • MtxHashSet - unordered list of unique elements backed by a hash map key set
  • MtxLinkedSet - ordered list of unique elements backed by a linked list
  • MtxSortedLinkedSet - ordered and sorted list of unique elements backed by a linked list
  • MtxMapSet - unordered list of unique elements backed by a tree map
  • MtxArraySet - unordered list of unique elements backed by a dynamic array
  • MtxSortedArraySet - ordered and sorted list of unique elements backed by a dynamic array

All of these support equals() and iterator() as well as the basic functions. (contains(), toArray(), toString(), containsAll(), etc.) See the interface for a complete list.

String Handlers and Manipulators (com.edavalos.mtx.util.string)

String Utilities (com.edavalos.mtx.util.string)

A collection of helpers for inspecting, cleaning, and transforming text for everyday use.

Common tasks include:

  • null/blank checks and safe comparisons (case-sensitive or case-insensitive)
  • trimming and whitespace normalization (including collapsing runs of spaces/tabs)
  • prefix/suffix operations to add, remove, or ensure markers
  • padding and alignment for fixed-width output (left, right, center)
  • case and word-style conversions (lower/upper, Title Case, camelCase, PascalCase, snake_case, kebab-case)
  • splitting/joining delimited strings with sensible defaults
  • bounds-safe substring and search helpers (starts/ends-with, contains)
  • lightweight sanitization (strip non-printables, keep alphanumeric)

MtxTime is an object for keeping a record of a time vector, with operations to modify it accordingly. It can be instantiated with a string to parse into a time, or directly with integers for each component. It will also self balance (so that its hours are no greater than 23 and its seconds and minutes are no greater than 59).

It has support for these methods:

  • addTime() - adds a time to this time
  • subtractTime() - subtracts a time from this time
  • multiplyBy() - multiplies this time by an integer
  • isLongerTHan() - checks if this time vector is longer than another one

MtxClock records the time elapsed (in milliseconds) between when start() and getElapsed() is called

MtxTimeUtil provides several utilities for dealing with times:

  • isValidTime() - checks if a string fits the pattern used by MtxTime
  • extractTimeDigits() - converts a time string into an integer array of time components
  • getRelativeTimeToNow() - gets the difference between a specified time and now, in a human-readable format

MtxStopwatch begins counting when told to and marks laps or pauses / resets counter when told to as well. Core methods are:

  • start() - begins counting (or continues where paused)
  • lap() - marks a lap but continues counting
  • stop() - marks a lap and pauses counting
  • reset() - clears all laps and resets counting to zero (but does not start counting again)
  • getLaps() - gets all marked laps since last reset or creation

MtxTimerTask executes code asynchronously when specified for the number of times specified. Code, frequency, and delay are specified in constructor. Methods are:

  • start() - begins countdown to running code, and once code is ran, manages and begins countdown for next run

About

I got bored and decided to re-invent the wheel

Resources

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages