├── .gitignore ├── .travis.yml ├── .rultor.yml ├── LICENSE.txt ├── src ├── test │ └── java │ │ └── com │ │ └── vssekorin │ │ └── cactoosmath │ │ ├── package-info.java │ │ ├── MatrixOfTest.java │ │ └── ElementTest.java └── main │ └── java │ └── com │ └── vssekorin │ └── cactoosmath │ ├── matrix │ ├── package-info.java │ ├── Element.java │ ├── MatrixEnvelope.java │ └── MatrixOf.java │ ├── Matrix.java │ └── package-info.java ├── README.md └── pom.xml /.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | .idea 3 | .DS_Store 4 | *.iml 5 | .project 6 | .settings 7 | .classpath 8 | .recommenders 9 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | sudo: false 3 | cache: 4 | directories: 5 | - $HOME/.m2 6 | script: 7 | - set -e 8 | - pdd --file=/dev/null 9 | - mvn javadoc:javadoc 10 | - mvn clean site -Psite --errors --batch-mode 11 | - mvn clean install -Pqulice --errors --batch-mode 12 | install: 13 | - gem install pdd 14 | - gem install xcop 15 | env: 16 | global: 17 | - MAVEN_OPTS="-Xmx256m" 18 | - JAVA_OPTS="-Xmx256m" 19 | jdk: 20 | - openjdk8 21 | after_success: 22 | - "bash <(curl -s https://codecov.io/bash)" 23 | -------------------------------------------------------------------------------- /.rultor.yml: -------------------------------------------------------------------------------- 1 | docker: 2 | image: g4s8/rultor:alpine3.10 3 | architect: 4 | - vssekorin 5 | assets: 6 | settings.xml: vssekorin/secret#assets/cactoos-math/settings.xml 7 | pubring.gpg: vssekorin/secret#assets/pubring.kbx 8 | secring.gpg: vssekorin/secret#assets/pubring.kbx 9 | merge: 10 | script: | 11 | pdd -f /dev/null 12 | mvn clean install -Pqulice --errors --settings ../settings.xml 13 | mvn clean site -Psite --errors --settings ../settings.xml 14 | deploy: 15 | script: | 16 | pdd -f /dev/null 17 | mvn clean deploy -Pqulice --errors --settings ../settings.xml 18 | release: 19 | sensitive: 20 | - settings.xml 21 | script: |- 22 | [[ "${tag}" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] || exit -1 23 | mvn versions:set "-DnewVersion=${tag}" --settings ../settings.xml 24 | git commit -am "${tag}" 25 | # note: -Pcactoos is needed to have the gpg and sonar secrets injected 26 | # Sonar is disabled (was -Psonar) because sonarcloud.io only support Java 11+ 27 | mvn clean deploy -Pcactoos -Pqulice -Psonatype --errors --settings ../settings.xml 28 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2017-2022 Vseslav Sekorin 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included 13 | in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /src/test/java/com/vssekorin/cactoosmath/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2017-2022 Vseslav Sekorin 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included 14 | * in all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | /** 26 | * Tests. 27 | * 28 | * @since 0.1 29 | */ 30 | package com.vssekorin.cactoosmath; 31 | -------------------------------------------------------------------------------- /src/main/java/com/vssekorin/cactoosmath/matrix/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2017-2022 Vseslav Sekorin 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included 14 | * in all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | /** 26 | * Matrixes. 27 | * 28 | * @since 0.1 29 | */ 30 | package com.vssekorin.cactoosmath.matrix; 31 | -------------------------------------------------------------------------------- /src/main/java/com/vssekorin/cactoosmath/Matrix.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2017-2022 Vseslav Sekorin 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included 14 | * in all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package com.vssekorin.cactoosmath; 25 | 26 | /** 27 | * Matrix. 28 | * 29 | * @param Matrix type 30 | * @since 0.1 31 | */ 32 | public interface Matrix { 33 | 34 | /** 35 | * Convert it to array. 36 | * 37 | * @return Array 38 | * @throws Exception If fails 39 | */ 40 | T[][] asArray() throws Exception; 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/com/vssekorin/cactoosmath/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2017-2022 Vseslav Sekorin 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included 14 | * in all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | /** 26 | * Cactoos math. 27 | * 28 | * @since 0.1 29 | * @see Project site www.cactoos.org 30 | * @see Cactoos GitHub repository 31 | * @see CactoosMath GitHub repository 32 | */ 33 | package com.vssekorin.cactoosmath; 34 | -------------------------------------------------------------------------------- /src/main/java/com/vssekorin/cactoosmath/matrix/Element.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2017-2022 Vseslav Sekorin 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included 14 | * in all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package com.vssekorin.cactoosmath.matrix; 25 | 26 | import com.vssekorin.cactoosmath.Matrix; 27 | import org.cactoos.scalar.ScalarEnvelope; 28 | 29 | /** 30 | * The element of a matrix. 31 | * 32 | * @param Type of element. 33 | * @since 0.2 34 | */ 35 | public final class Element extends ScalarEnvelope { 36 | 37 | /** 38 | * Ctor. 39 | * @param matrix Matrix 40 | * @param row Row 41 | * @param column Column 42 | */ 43 | public Element(final Matrix matrix, final int row, final int column) { 44 | super(() -> matrix.asArray()[row][column]); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/test/java/com/vssekorin/cactoosmath/MatrixOfTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2017-2022 Vseslav Sekorin 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included 14 | * in all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package com.vssekorin.cactoosmath; 25 | 26 | import com.vssekorin.cactoosmath.matrix.MatrixOf; 27 | import org.hamcrest.core.IsEqual; 28 | import org.junit.jupiter.api.Test; 29 | import org.llorllale.cactoos.matchers.Assertion; 30 | 31 | /** 32 | * Test case for {@link MatrixOf}. 33 | * 34 | * @since 0.5 35 | * @checkstyle MagicNumber (500 lines) 36 | */ 37 | final class MatrixOfTest { 38 | 39 | @Test 40 | void getFirstElement() throws Exception { 41 | new Assertion<>( 42 | "Must get first element", 43 | new MatrixOf<>(new Integer[][]{{1, 2}, {3, 4}}).asArray()[0][0], 44 | new IsEqual<>(1) 45 | ).affirm(); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/com/vssekorin/cactoosmath/matrix/MatrixEnvelope.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2017-2022 Vseslav Sekorin 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included 14 | * in all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package com.vssekorin.cactoosmath.matrix; 25 | 26 | import com.vssekorin.cactoosmath.Matrix; 27 | 28 | /** 29 | * Envelope for Matrix. 30 | * 31 | *

There is no thread-safety guarantee. 32 | * 33 | * @param Type of result 34 | * @since 0.1 35 | */ 36 | public abstract class MatrixEnvelope implements Matrix { 37 | 38 | /** 39 | * The delegate matrix. 40 | */ 41 | private final Matrix matrix; 42 | 43 | /** 44 | * Ctor. 45 | * @param matrix The scalar 46 | */ 47 | public MatrixEnvelope(final Matrix matrix) { 48 | this.matrix = matrix; 49 | } 50 | 51 | @Override 52 | public final T[][] asArray() throws Exception { 53 | return this.matrix.asArray(); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/test/java/com/vssekorin/cactoosmath/ElementTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2017-2022 Vseslav Sekorin 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included 14 | * in all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package com.vssekorin.cactoosmath; 25 | 26 | import com.vssekorin.cactoosmath.matrix.Element; 27 | import com.vssekorin.cactoosmath.matrix.MatrixOf; 28 | import org.hamcrest.MatcherAssert; 29 | import org.hamcrest.Matchers; 30 | import org.junit.Test; 31 | 32 | /** 33 | * Test case for {@link Element}. 34 | * 35 | * @since 0.2 36 | * @checkstyle JavadocMethodCheck (500 lines) 37 | * @checkstyle MagicNumberCheck (500 lines) 38 | */ 39 | public final class ElementTest { 40 | 41 | @Test 42 | public void value() throws Exception { 43 | MatcherAssert.assertThat( 44 | "Must return element by index [1, 1]", 45 | new Element<>( 46 | new MatrixOf<>( 47 | new Integer[][]{ 48 | {5, 7, 4}, 49 | {-4, 6, 0}, 50 | {2, 0, 3}, 51 | } 52 | ), 53 | 1, 1 54 | ).value(), 55 | Matchers.equalTo(6) 56 | ); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![EO principles respected here](http://www.elegantobjects.org/badge.svg)](http://www.elegantobjects.org) 2 | [![DevOps By Rultor.com](http://www.rultor.com/b/VsSekorin/cactoos-math)](http://www.rultor.com/p/VsSekorin/cactoos-math) 3 | 4 | [![Build Status](https://travis-ci.org/VsSekorin/cactoos-math.svg?branch=master)](https://travis-ci.org/VsSekorin/cactoos-math) 5 | [![License](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/VsSekorin/cactoos-math/blob/master/LICENSE.txt) 6 | 7 | Cactoos-Math is math extension of [Cactoos](https://github.com/yegor256/cactoos) ([my blog post about this](http://vssekorin.com/post/cactoos/)). 8 | 9 | **Motivation**: 10 | 11 | - Math classes is overkill for Cactoos, but it can be useful and interesting. 12 | - It is generally accepted that FP, rather than OOP, is more suitable for math. 13 | - Practice in OOP. 14 | 15 | **Principles**. 16 | These are the [design principles](http://www.elegantobjects.org#principles) behind Cactoos. 17 | 18 | Java version required: 1.8+. 19 | 20 | ## Matrix 21 | 22 | Identity matrix 6x6: 23 | 24 | ```java 25 | new MatrixOf<>( 26 | row -> col -> row.equals(col) ? 1 : 0, 27 | 6, 6 28 | ) 29 | ``` 30 | 31 | ## How to contribute? 32 | 33 | Just fork the repo and send us a pull request. 34 | 35 | Make sure your branch builds without any warnings/issues: 36 | 37 | ``` 38 | mvn clean install -Pqulice 39 | ``` 40 | 41 | ## Contributors 42 | 43 | - [@VsSekorin](https://github.com/VsSekorin) as Vseslav Sekorin ([Blog](http://vssekorin.com)) 44 | - [@floreasorin](https://github.com/floreasorin) 45 | - [@alexandrustoica](https://github.com/alexandrustoica) as Alexandru Stoica 46 | 47 | ## MIT License 48 | 49 | Copyright (c) 2017-2019 Vseslav Sekorin 50 | 51 | Permission is hereby granted, free of charge, to any person obtaining a copy 52 | of this software and associated documentation files (the "Software"), to deal 53 | in the Software without restriction, including without limitation the rights 54 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 55 | copies of the Software, and to permit persons to whom the Software is 56 | furnished to do so, subject to the following conditions: 57 | 58 | The above copyright notice and this permission notice shall be included in all 59 | copies or substantial portions of the Software. 60 | 61 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 62 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 63 | FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 64 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 65 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 66 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 67 | SOFTWARE. 68 | 69 | -------------------------------------------------------------------------------- /src/main/java/com/vssekorin/cactoosmath/matrix/MatrixOf.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2017-2022 Vseslav Sekorin 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included 14 | * in all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package com.vssekorin.cactoosmath.matrix; 25 | 26 | import com.vssekorin.cactoosmath.Matrix; 27 | import java.util.Iterator; 28 | import org.cactoos.Func; 29 | import org.cactoos.iterable.IterableOf; 30 | 31 | /** 32 | * Matrix of. 33 | * 34 | * @param Type of matrix 35 | * @since 0.1 36 | */ 37 | @SuppressWarnings( 38 | { 39 | "PMD.CallSuperInConstructor", 40 | "PMD.ConstructorOnlyInitializesOrCallOtherConstructors", 41 | "PMD.OnlyOneConstructorShouldDoInitialization", 42 | "unchecked" 43 | } 44 | ) 45 | public final class MatrixOf extends MatrixEnvelope { 46 | 47 | /** 48 | * Ctor. 49 | * @param rows Number of rows 50 | * @param cols Number of columns 51 | * @param src An array of some elements 52 | */ 53 | public MatrixOf(final Number rows, final Number cols, final T... src) { 54 | this(rows, cols, new IterableOf<>(src)); 55 | } 56 | 57 | /** 58 | * Ctor. 59 | * @param rows Number of rows 60 | * @param cols Number of columns 61 | * @param src An {@link Iterator} 62 | */ 63 | public MatrixOf(final Number rows, final Number cols, 64 | final Iterator src) { 65 | this(rows, cols, new IterableOf<>(src)); 66 | } 67 | 68 | /** 69 | * Ctor. 70 | * @param rows Number of rows 71 | * @param cols Number of columns 72 | * @param src An {@link Iterable} 73 | */ 74 | public MatrixOf(final Number rows, final Number cols, 75 | final Iterable src) { 76 | this(() -> { 77 | final T[][] result = 78 | (T[][]) new Object[rows.intValue()][cols.intValue()]; 79 | final Iterator iterator = src.iterator(); 80 | for (int row = 0; row < rows.intValue(); ++row) { 81 | for (int col = 0; col < cols.intValue(); ++col) { 82 | result[row][col] = iterator.next(); 83 | } 84 | } 85 | return result; 86 | }); 87 | } 88 | 89 | /** 90 | * Ctor. 91 | * @param func Filling function 92 | * @param rows Number of rows 93 | * @param cols Number of columns 94 | */ 95 | public MatrixOf(final Func> func, 96 | final Number rows, final Number cols) { 97 | this(() -> { 98 | final T[][] result = 99 | (T[][]) new Object[rows.intValue()][cols.intValue()]; 100 | for (int row = 0; row < rows.intValue(); ++row) { 101 | for (int col = 0; col < cols.intValue(); ++col) { 102 | result[row][col] = func.apply(row).apply(col); 103 | } 104 | } 105 | return result; 106 | }); 107 | } 108 | 109 | /** 110 | * Ctor. 111 | * @param src Array 112 | */ 113 | @SuppressWarnings("PMD.UseVarargs") 114 | public MatrixOf(final T[][] src) { 115 | this(() -> src); 116 | } 117 | 118 | /** 119 | * Ctor. 120 | * @param src Matrix 121 | */ 122 | public MatrixOf(final Matrix src) { 123 | super(src); 124 | } 125 | } 126 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 25 | 26 | 4.0.0 27 | 28 | com.jcabi 29 | parent 30 | 0.58.0 31 | 32 | com.github.vssekorin 33 | cactoos-math 34 | 0.4.0 35 | jar 36 | cactoos-math 37 | Math extension of Cactoos. 38 | https://github.com/vssekorin/cactoos-math 39 | 2017 40 | 41 | cactoos-math 42 | https://github.com/vssekorin/cactoos-math 43 | 44 | 45 | 46 | MIT 47 | https://github.com/vssekorin/cactoos-math/LICENSE.txt 48 | site 49 | 50 | 51 | 52 | 53 | vssekorin 54 | Vseslav Sekorin 55 | vssekorin@gmail.com 56 | vssekorin 57 | https://github.com/vssekorin 58 | 59 | Architect 60 | Developer 61 | 62 | 63 | 64 | 65 | GitHub 66 | https://github.com/vssekorin/cactoos-math/issues 67 | 68 | 69 | scm:git:git@github.com:vssekorin/cactoos-math.git 70 | 71 | scm:git:git@github.com:vssekorin/cactoos-math.git 72 | 73 | https://github.com/vssekorin/cactoos-math 74 | 75 | 76 | rultor 77 | http://www.rultor.com/s/cactoos-math 78 | 79 | 80 | 81 | github-pages 82 | https://github.com/vssekorin/cactoos-math 83 | 84 | 85 | 86 | 87 | 88 | 89 | maven-compiler-plugin 90 | 3.10.1 91 | 92 | 1.8 93 | 1.8 94 | false 95 | 96 | 97 | 98 | org.apache.maven.plugins 99 | maven-surefire-plugin 100 | 101 | true 102 | 103 | 104 | src/test/resources/logging.properties 105 | 106 | 107 | 108 | 109 | 110 | org.apache.maven.plugins 111 | maven-resources-plugin 112 | 3.2.0 113 | 114 | UTF-8 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | org.cactoos 123 | cactoos 124 | 0.52.0 125 | 126 | 127 | org.llorllale 128 | cactoos-matchers 129 | 0.25 130 | test 131 | 132 | 133 | com.jcabi 134 | jcabi-xml 135 | 0.23.2 136 | test 137 | 138 | 139 | com.jcabi 140 | jcabi-matchers 141 | 1.5.3 142 | test 143 | 144 | 145 | org.hamcrest 146 | * 147 | 148 | 149 | 150 | 151 | org.testcontainers 152 | testcontainers 153 | test 154 | 155 | 156 | org.hamcrest 157 | * 158 | 159 | 160 | 161 | 162 | org.slf4j 163 | slf4j-simple 164 | 2.0.0-alpha7 165 | provided 166 | 167 | 168 | junit 169 | junit 170 | 4.13.2 171 | test 172 | 173 | 174 | org.hamcrest 175 | * 176 | 177 | 178 | 179 | 180 | org.junit.vintage 181 | junit-vintage-engine 182 | 5.9.0-RC1 183 | test 184 | 185 | 186 | org.hamcrest 187 | * 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | org.testcontainers 196 | testcontainers-bom 197 | 1.17.3 198 | pom 199 | import 200 | 201 | 202 | 203 | 204 | 205 | qulice 206 | 207 | 208 | 209 | com.qulice 210 | qulice-maven-plugin 211 | 0.21.0 212 | 213 | 214 | org.jacoco 215 | jacoco-maven-plugin 216 | 0.8.0 217 | 218 | file 219 | 220 | 221 | 222 | jacoco-initialize 223 | 224 | prepare-agent 225 | 226 | 227 | 228 | jacoco-check 229 | test 230 | 231 | check 232 | 233 | 234 | 235 | 236 | BUNDLE 237 | 238 | 239 | INSTRUCTION 240 | COVEREDRATIO 241 | 0.0 242 | 243 | 244 | LINE 245 | COVEREDRATIO 246 | 0.0 247 | 248 | 249 | BRANCH 250 | COVEREDRATIO 251 | 0.0 252 | 253 | 254 | COMPLEXITY 255 | COVEREDRATIO 256 | 0.0 257 | 258 | 259 | METHOD 260 | COVEREDRATIO 261 | 0.0 262 | 263 | 264 | CLASS 265 | MISSEDCOUNT 266 | 15 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | jacoco-site 275 | install 276 | 277 | report 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | sonar 287 | 288 | 289 | 290 | org.codehaus.mojo 291 | sonar-maven-plugin 292 | 3.4.0.905 293 | 294 | 295 | package 296 | 297 | sonar 298 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | --------------------------------------------------------------------------------