Skip to content

Commit

Permalink
#2863 fix namings and qulice violations
Browse files Browse the repository at this point in the history
  • Loading branch information
c71n93 committed May 2, 2024
1 parent bc09cd0 commit 3258acd
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 145 deletions.
10 changes: 0 additions & 10 deletions eo-maven-plugin/src/main/java/org/eolang/maven/util/BiIoProc.java

This file was deleted.

36 changes: 5 additions & 31 deletions eo-maven-plugin/src/main/java/org/eolang/maven/util/HmBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import org.cactoos.Input;
import org.cactoos.Text;
import org.cactoos.bytes.BytesOf;
import org.cactoos.io.InputOf;
import org.cactoos.io.OutputTo;
import org.cactoos.io.TeeInput;
import org.cactoos.scalar.IoChecked;
Expand All @@ -51,6 +50,9 @@ public final class HmBase implements Home {
*/
private final Path cwd;

/**
* Home with "save" functionality.
*/
private final Home origin;

/**
Expand All @@ -69,7 +71,7 @@ public HmBase(final File file) {
*/
public HmBase(final Path pth) {
this.cwd = pth;
this.origin = new HmNew(
this.origin = new HmSave(
(input, path) -> {
final Path target = this.absolute(this.onlyRelative(path));
if (target.toFile().getParentFile().mkdirs()) {
Expand Down Expand Up @@ -104,54 +106,26 @@ public HmBase(final Path pth) {
);
}

/**
* Saving string.
*
* @param str String
* @param path Cwd-relative path to file
* @throws IOException If fails
*/
@Override
public void save(final String str, final Path path) throws IOException {
this.origin.save(str, path);
}

/**
* Saving text.
*
* @param txt Text
* @param path Cwd-relative path to file
* @throws IOException If fails
*/
@Override
public void save(final Text txt, final Path path) throws IOException {
this.origin.save(txt, path);
}

/**
* Saving stream.
*
* @param stream Input stream
* @param path Cwd-relative path to file
* @throws IOException If fails
*/
@Override
public void save(final InputStream stream, final Path path) throws IOException {
this.origin.save(stream, path);
}

/**
* Saving bytes.
*
* @param bytes Byte array
* @param path Cwd-relative path to file
* @throws IOException If fails
*/
@Override
public void save(final byte[] bytes, final Path path) throws IOException {
this.origin.save(bytes, path);
}

@Override
public void save(final Input input, final Path path) throws IOException {
this.origin.save(input, path);
Expand Down
63 changes: 0 additions & 63 deletions eo-maven-plugin/src/main/java/org/eolang/maven/util/HmNew.java

This file was deleted.

47 changes: 10 additions & 37 deletions eo-maven-plugin/src/main/java/org/eolang/maven/util/HmOptional.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import org.cactoos.Bytes;
import org.cactoos.Input;
import org.cactoos.Text;
import org.cactoos.io.InputOf;

/**
* Location for files that saves optionally.
Expand All @@ -43,7 +42,10 @@ public final class HmOptional implements Home {
*/
private final Home origin;

private final Home call;
/**
* Home with "save" functionality.
*/
private final Home sve;

/**
* Rewrite files or not.
Expand All @@ -59,7 +61,7 @@ public final class HmOptional implements Home {
public HmOptional(final Home home, final boolean rwte) {
this.origin = home;
this.rewrite = rwte;
this.call = new HmNew(
this.sve = new HmSave(
(input, path) -> {
final Path target = this.absolute(this.onlyRelative(path));
if (!target.toFile().exists() || this.rewrite) {
Expand All @@ -71,58 +73,29 @@ public HmOptional(final Home home, final boolean rwte) {
);
}


/**
* Saving string.
*
* @param str String
* @param path Cwd-relative path to file
* @throws IOException If fails
*/
@Override
public void save(final String str, final Path path) throws IOException {
this.call.save(str, path);
this.sve.save(str, path);
}

/**
* Saving text.
*
* @param txt Text
* @param path Cwd-relative path to file
* @throws IOException If fails
*/
@Override
public void save(final Text txt, final Path path) throws IOException {
this.call.save(txt, path);
this.sve.save(txt, path);
}

/**
* Saving stream.
*
* @param stream Input stream
* @param path Cwd-relative path to file
* @throws IOException If fails
*/
@Override
public void save(final InputStream stream, final Path path) throws IOException {
this.call.save(stream, path);
this.sve.save(stream, path);
}

/**
* Saving bytes.
*
* @param bytes Byte array
* @param path Cwd-relative path to file
* @throws IOException If fails
*/
@Override
public void save(final byte[] bytes, final Path path) throws IOException {
this.call.save(bytes, path);
this.sve.save(bytes, path);
}

@Override
public void save(final Input input, final Path path) throws IOException {
this.call.save(input, path);
this.sve.save(input, path);
}

@Override
Expand Down
100 changes: 100 additions & 0 deletions eo-maven-plugin/src/main/java/org/eolang/maven/util/HmSave.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2016-2024 Objectionary.com
*
* 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 NON-INFRINGEMENT. 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.
*/
package org.eolang.maven.util;

import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Path;
import org.cactoos.BiProc;
import org.cactoos.Bytes;
import org.cactoos.Input;
import org.cactoos.Text;
import org.cactoos.io.InputOf;
import org.cactoos.proc.IoCheckedBiProc;

/**
* Home that defines the logic of saving different types of data to files.
*
* @since 0.37.0
*/
public final class HmSave implements Home {
/**
* BiProc with two arguments for saving {@link Input} from first argument to file from second.
*/
private final IoCheckedBiProc<Input, Path> sve;

/**
* Ctor.
*
* @param save BiProc for saving {@link Input} to file.
*/
public HmSave(final BiProc<Input, Path> save) {
this.sve = new IoCheckedBiProc<>(save);
}

@Override
public void save(final String str, final Path path) throws IOException {
this.save(new InputOf(str), path);
}

@Override
public void save(final Text txt, final Path path) throws IOException {
this.save(new InputOf(txt), path);
}

@Override
public void save(final InputStream stream, final Path path) throws IOException {
this.save(new InputOf(stream), path);
}

@Override
public void save(final byte[] bytes, final Path path) throws IOException {
this.save(new InputOf(bytes), path);
}

@Override
public void save(final Input input, final Path path) throws IOException {
this.sve.exec(input, path);
}

@Override
public boolean exists(final Path path) {
throw new IllegalStateException("Should never happen");
}

@Override
public Bytes load(final Path path) throws IOException {
throw new IllegalStateException("Should never happen");
}

@Override
public Path absolute(final Path path) {
throw new IllegalStateException("Should never happen");
}

@Override
public Path onlyRelative(final Path path) {
throw new IllegalStateException("Should never happen");
}
}
8 changes: 4 additions & 4 deletions eo-maven-plugin/src/main/java/org/eolang/maven/util/Home.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public interface Home {
* @param path Cwd-relative path to file
* @throws IOException If fails
*/
void save(final String str, final Path path) throws IOException;
void save(String str, Path path) throws IOException;

/**
* Saving text.
Expand All @@ -51,7 +51,7 @@ public interface Home {
* @param path Cwd-relative path to file
* @throws IOException If fails
*/
void save(final Text txt, final Path path) throws IOException;
void save(Text txt, Path path) throws IOException;

/**
* Saving stream.
Expand All @@ -60,7 +60,7 @@ public interface Home {
* @param path Cwd-relative path to file
* @throws IOException If fails
*/
void save(final InputStream stream, final Path path) throws IOException;
void save(InputStream stream, Path path) throws IOException;

/**
* Saving bytes.
Expand All @@ -69,7 +69,7 @@ public interface Home {
* @param path Cwd-relative path to file
* @throws IOException If fails
*/
void save(final byte[] bytes, final Path path) throws IOException;
void save(byte[] bytes, Path path) throws IOException;

/**
* Saving input.
Expand Down

0 comments on commit 3258acd

Please sign in to comment.