All Projects → yegor256 → Cactoos

yegor256 / Cactoos

Licence: mit
Object-Oriented Java primitives, as an alternative to Google Guava and Apache Commons

Programming Languages

java
68154 projects - #9 most used programming language

Labels

Projects that are alternatives of or similar to Cactoos

hangman
Hangman (the game)
Stars: ✭ 26 (-95.77%)
Mutual labels:  oop
Tensorflow Project Template
A best practice for tensorflow project template architecture.
Stars: ✭ 3,466 (+463.58%)
Mutual labels:  oop
Designpatternslibrary
A comprehensive design patterns library implemented in C#, which covers various design patterns from the most commonly used ones to the lesser-known ones. Get familiar with and learn design patterns through moderately realistic examples.
Stars: ✭ 485 (-21.14%)
Mutual labels:  oop
TicariOtomasyon
Mağazaya gelen elektronik eşyalara ait ürün , stok ve satış bilgisinin tutulduğu proje
Stars: ✭ 14 (-97.72%)
Mutual labels:  oop
Stampit
OOP is better with stamps: Composable object factories.
Stars: ✭ 3,021 (+391.22%)
Mutual labels:  oop
Design Patterns
Contains examples of design patterns that implemented in php
Stars: ✭ 375 (-39.02%)
Mutual labels:  oop
design-patterns-java
📗 Classic OOP Design Patterns from GoF, implemented in Java.
Stars: ✭ 25 (-95.93%)
Mutual labels:  oop
Java design patterns
Java 实现的面向对象设计模式示例, 创建者、抽象工厂、工厂方法、原型、单例、适配器、桥接、组合、装饰器、备忘录、观察者、状态、策略、模板方法、访问者
Stars: ✭ 547 (-11.06%)
Mutual labels:  oop
Laconia
🏺 ‎ A minimalist MVC framework.
Stars: ✭ 307 (-50.08%)
Mutual labels:  oop
Proxymanager
🎩✨🌈 OOP Proxy wrappers/utilities - generates and manages proxies of your objects
Stars: ✭ 4,556 (+640.81%)
Mutual labels:  oop
Pmanager
A project management system built using laravel. Watch full video here
Stars: ✭ 260 (-57.72%)
Mutual labels:  oop
Akita
🚀 State Management Tailored-Made for JS Applications
Stars: ✭ 3,338 (+442.76%)
Mutual labels:  oop
Designpatternsphp
sample code for several design patterns in PHP 8
Stars: ✭ 20,158 (+3177.72%)
Mutual labels:  oop
metroidvaniafangame
A platformer game designed for the iphone 8-XS, created with an object oriented approach and MVC pattern. Technical details/Credits in README
Stars: ✭ 30 (-95.12%)
Mutual labels:  oop
Dynamix
🍥 A new take on polymorphism in C++
Stars: ✭ 504 (-18.05%)
Mutual labels:  oop
ddd-example-ecommerce
Domain-driven design example in Java with Spring framework
Stars: ✭ 73 (-88.13%)
Mutual labels:  oop
Attrs
Python Classes Without Boilerplate
Stars: ✭ 3,786 (+515.61%)
Mutual labels:  oop
Bash Oo Framework
Bash Infinity is a modern standard library / framework / boilerplate for Bash
Stars: ✭ 5,247 (+753.17%)
Mutual labels:  oop
Python Programs
My collection of Python Programs
Stars: ✭ 518 (-15.77%)
Mutual labels:  oop
Eo
EOLANG, the Programming Language
Stars: ✭ 442 (-28.13%)
Mutual labels:  oop

Donate via Zerocracy

EO principles respected here Managed by Zerocracy DevOps By Rultor.com We recommend IntelliJ IDEA

Build Status Build status Javadoc PDD status Maven Central License

jpeek report Test Coverage SonarQube Hits-of-Code

Project architect: @victornoel

ATTENTION: We're still in a very early alpha version, the API may and will change frequently. Please, use it at your own risk, until we release version 1.0. You can view our progress towards this release here.

Cactoos is a collection of object-oriented Java primitives.

Motivation. We are not happy with JDK, Guava, and Apache Commons because they are procedural and not object-oriented. They do their job, but mostly through static methods. Cactoos is suggesting to do almost exactly the same, but through objects.

Principles. These are the design principles behind Cactoos.

How to use. The library has no dependencies. All you need is this (get the latest version here):

Maven:

<dependency>
  <groupId>org.cactoos</groupId>
  <artifactId>cactoos</artifactId>
</dependency>

Gradle:

dependencies {
    compile 'org.cactoos:cactoos:<version>'
}

Java version required: 1.8+.

StackOverflow tag is cactoos.

Input/Output

More about it here: Object-Oriented Declarative Input/Output in Cactoos.

To read a text file in UTF-8:

String text = new TextOf(
  new File("/code/a.txt")
).asString();

To write a text into a file:

new LengthOf(
  new TeeInput(
    "Hello, world!",
    new File("/code/a.txt")
  )
).intValue();

To read a binary file from classpath:

byte[] data = new BytesOf(
  new ResourceOf("foo/img.jpg")
).asBytes();

Text/Strings

To format a text:

String text = new FormattedText(
  "How are you, %s?",
  name
).asString();

To manipulate with a text:

// To lower case
new Lowered(
	new TextOf("Hello")
);
// To upper case
new Upper(
	new TextOf("Hello")
);

Iterables/Collections/Lists/Sets

More about it here: Lazy Loading and Caching via Sticky Cactoos Primitives.

To filter a collection:

Collection<String> filtered = new ListOf<>(
  new Filtered<>(
    s -> s.length() > 4,
    new IterableOf<>("hello", "world", "dude")
  )
);

To flatten one iterable:

new Joined<>(
  new Mapped<>(
    iter -> new IterableOf<>(
      new ListOf<>(iter).toArray(new Integer[]{})
    ),
    new IterableOf<>(1, 2, 3, 4, 5, 6))
  )
);    // Iterable<Integer>

To flatten and join several iterables:

new Joined<>(
  new Mapped<>(
    iter -> new IterableOf<>(
      new ListOf<>(iter).toArray(new Integer[]{})
    ),
    new Joined<>(
      new IterableOf<>(new IterableOf<>(1, 2, 3)),
      new IterableOf<>(new IterableOf<>(4, 5, 6))
    )
  )
);    // Iterable<Integer>

To iterate a collection:

new And(
  new Mapped<>(
    new FuncOf<>(
      input -> {
        System.out.printf("Item: %s\n", input);
      }
    ),
    new IterableOf<>("how", "are", "you", "?")
  )
).value();

Or even more compact:

new ForEach<String>(
    input -> System.out.printf(
        "Item: %s\n", input
    )
).exec("how", "are", "you", "?");

To sort a list of words in the file:

List<Text> sorted = new ListOf<>(
  new Sorted<>(
    new Split(
      new TextOf(
        new File("/tmp/names.txt")
      ),
      new TextOf("\\s+")
    )
  )
);

To count elements in an iterable:

int total = new LengthOf(
  new IterableOf<>("how", "are", "you")
).intValue();

To create a set of elements by providing variable arguments:

final Set<String> unique = new SetOf<String>(
    "one",
    "two",
    "one",
    "three"
);

To create a set of elements from existing iterable:

final Set<String> words = new SetOf<>(
    new IterableOf<>("abc", "bcd", "abc", "ccc")
);

To create a sorted iterable with unique elements from existing iterable:

final Iterable<String> sorted = new Sorted<>(
    new SetOf<>(
        new IterableOf<>("abc", "bcd", "abc", "ccc")
    )
);

To create a sorted set from existing vararg elements using comparator:

final Set<String> sorted = new org.cactoos.set.Sorted<>(
    (first, second) -> first.compareTo(second),
    "abc", "bcd", "abc", "ccc", "acd"
);

To create a sorted set from existing iterable using comparator:

final Set<String> sorted = new org.cactoos.set.Sorted<>(
    (first, second) -> first.compareTo(second),
    new IterableOf<>("abc", "bcd", "abc", "ccc", "acd")
);

Funcs and Procs

This is a traditional foreach loop:

for (String name : names) {
  System.out.printf("Hello, %s!\n", name);
}

This is its object-oriented alternative (no streams!):

new And(
  n -> {
    System.out.printf("Hello, %s!\n", n);
  },
  names
).value();

This is an endless while/do loop:

while (!ready) {
  System.out.prinln("Still waiting...");
}

Here is its object-oriented alternative:

new And(
  ready -> {
    System.out.println("Still waiting...");
    return !ready;
  },
  new Endless<>(booleanParameter)
).value();

Dates and Times

From our org.cactoos.time package.

Our classes are divided in two groups: those that parse strings into date/time objects, and those that format those objects into strings.

For example, this is the traditional way of parsing a string into an OffsetDateTime:

final OffsetDateTime date = OffsetDateTime.parse("2007-12-03T10:15:30+01:00");

Here is its object-oriented alternative (no static method calls!) using OffsetDateTimeOf, which is a Scalar:

final OffsetDateTime date = new OffsetDateTimeOf("2007-12-03T10:15:30+01:00").value();

To format an OffsetDateTime into a Text:

final OffsetDateTime date = ...;
final String text = new TextOf(date).asString();

Our objects vs. their static methods

Cactoos Guava Apache Commons JDK 8
And Iterables.all() - -
Filtered Iterables.filter() ? -
FormattedText - - String.format()
IsBlank - StringUtils.isBlank() -
Joined - - String.join()
LengthOf - - String#length()
Lowered - - String#toLowerCase()
Normalized - StringUtils.normalize() -
Or Iterables.any() - -
Repeated - StringUtils.repeat() -
Replaced - - String#replace()
Reversed - - StringBuilder#reverse()
Rotated - StringUtils.rotate() -
Split - - String#split()
StickyList Lists.newArrayList() ? Arrays.asList()
Sub - - String#substring()
SwappedCase - StringUtils.swapCase() -
TextOf ? IOUtils.toString() -
TrimmedLeft - StringUtils.stripStart() -
TrimmedRight - StringUtils.stripEnd() -
Trimmed - StringUtils.stripAll() String#trim()
Upper - - String#toUpperCase()

Questions

Ask your questions related to cactoos library on Stackoverflow with cactoos tag.

How to contribute?

Just fork the repo and send us a pull request.

Make sure your branch builds without any warnings/issues:

mvn clean verify -Pqulice

To run a build similar to the CI with Docker only, use:

docker run \
	--tty \
	--interactive \
	--workdir=/main \
	--volume=${PWD}:/main \
	--volume=cactoos-mvn-cache:/root/.m2 \
	--rm \
	maven:3-jdk-8 \
	bash -c "mvn clean install site -Pqulice -Psite --errors; chown -R $(id -u):$(id -g) target/"

To remove the cache used by Docker-based build:

docker volume rm cactoos-mvn-cache

Note: Checkstyle is used as a static code analyze tool with checks list in GitHub precommits.

Contributors

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].