Is there a cleaner way of writing same method with different parameters?

I need to have multiple methods taking different parameters. Is there a cleaner way of writing those methods instead of declaring each one of them separately? I need 4 the same methods in total. Am I able to write one but let it decide what parameters are passed? Or do I have to end up copying and pasting first one 3 times and changing the parameters. Here are 2 of them

public String findLogNumber(XWPFWordExtractor we) {
    int logIndex;
    int logIndexEnd;
    String logNumber = "";
    if (we.getText().contains("Log ")) {
        logIndex = we.getText().indexOf("Log ") + 4;
        logIndexEnd = logIndex + 5;
        logNumber = we.getText().substring(logIndex, logIndexEnd);
    }
    return logNumber;
}

public String findLogNumber(WordExtractor we) {
    int logIndex;
    int logIndexEnd;
    String logNumber = "";
    if (we.getText().contains("Log ")) {
        logIndex = we.getText().indexOf("Log ") + 4;
        logIndexEnd = logIndex + 5;
        logNumber = we.getText().substring(logIndex, logIndexEnd);
    }
    return logNumber;
}

Java screensaver loading the wrong main class, any ideas?

I’m building a Windows screensaver using Java, JavaFX, the JavaFX Packager, the Gradle JavaFX Packager plugin, etc. I generate various executable files with this configuration:

jfx {
    mainClass = "tech.projectx.projectx.ConfiguratorApp"
    vendor = "ProjectX"
    appName = "ProjectX"
    nativeReleaseVersion = version
    secondaryLaunchers = [
            [
                    appName  : "ProjectX Renderer",
                    mainClass: "tech.projectx.projectx.RendererApp",
                    needMenu : true
            ],
            [
                    appName  : "ProjectX Displayer",
                    mainClass: "tech.projectx.projectx.DisplayerApp",
                    needMenu : true
            ],
            [
                    appName  : "ProjectX Screensaver",
                    mainClass: "tech.projectx.projectx.WinScreensaverApp",
                    needMenu : false
            ]
    ]
}

When configuring, previewing and testing the screensaver, everything works well, but when the screensaver actually runs, the main class seems to be DisplayerApp instead of WinScreensaverApp.

Any ideas why or how to gather more information about what’s going on?

Left and right parts of spannable overlaps each over

I want make TextView with text on left side and right side.
Most popular and nice solution – using spannable.
This is my code

private fun applyText(textView: TextView, leftText: String, rightText: String?) {
val right = rightText ?: ""

val merged = SpannableString(leftText + "n" + right)

merged.setSpan(AlignmentSpan.Standard(Layout.Alignment.ALIGN_NORMAL), 0, leftText.length, Spanned.SPAN_INCLUSIVE_EXCLUSIVE)
merged.setSpan(LineOverlapSpan(), leftText.length, leftText.length + 1, Spanned.SPAN_INCLUSIVE_EXCLUSIVE)
merged.setSpan(AlignmentSpan.Standard(Layout.Alignment.ALIGN_OPPOSITE), leftText.length + 1, leftText.length + 1 + right.length,
               Spanned.SPAN_INCLUSIVE_EXCLUSIVE)

textView.text = merged
}

This is LineOverlapSpan()

private class LineOverlapSpan : LineHeightSpan {
override fun chooseHeight(text: CharSequence?, start: Int, end: Int, spanstartv: Int, v: Int, fm: Paint.FontMetricsInt) {
    fm.bottom += fm.top
    fm.descent += fm.top
}
 }

I found this solution here

When length of text small, it’s works nice, but when right text has big length i have a troubles and cant find solution.
Screenshots:
nice works
bad works

Remove enumeration style of paragraph with docx4j

In my word template file I have some tables and sometimes the second column of them is formatted as an enumeration.
Using docx4j I’m filling it with dynamic content and if there’s only one entry I need to get rid of the enumeration style.
I found a place deep down in the structure that has a value for enumeration but when setting it to null, I don’t see any changes in my template.

//This value is "Listenabsatz" (German) and I want to get rid of it
//Setting this value to "" or setting pStyle to null didn't help
((PStyle)((PPr)((P)((java.util.ArrayList)((Tc)((JAXBElement)templateRow.content.get(1)).value).content).get(0)).pPr).pStyle).val

In my actual code this is the place where I’m trying to change it:

Tr templateRow = (Tr) rows.get(0);
Tc cell = (Tc) ((javax.xml.bind.JAXBElement) templateRow.getContent().get(1)).getValue();
P par = (P) (cell.getContent().get(0));
PPr parStyle = par.getPPr();
if (parStyle.getPStyle() != null && parStyle.getPStyle().getVal() != null) {
    parStyle.setPStyle(null);
    parStyle.getPStyle().setVal();
    //parStyle.getPStyle().setVal("");
}

How can I remove that enumeration style succesfully?

Emulation tool for USB Crypto Token or Certificate

For testing purpose, we are looking for a tool or driver emulating a hardware cryptographic support based on a software private key and certificate (*.p12 for example)

The idea is to install that driver under Windows (or Linux), configure it with a provider (*.p12) and then it should act as if we have a crypto smart card or usb token pluggued in the computer.

The idea is to try some API in Java that should interact with a hardware token.

Regards

Java/Spring/Hibernate – Many-To-Many relation does not work

I have a problem with Many-To-Many mapping. I have properly working mapping One-To-Many, so using this knowledge I tried to modify Many-To-Many and make two One-To-Many relations with one additional table (as it’s common solution).
I decided to create a table between User and TaskResource named UserTaskResource (many users can solve many task resources / many task resources can be done by many users). There is a relation User (1–N) UserTaskResource and UserTaskResource (N–1) TaskResource.

The issue I get is:

Caused by: org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: com.wjaroszuk.model.UserLinkResource.link_resource in com.wjaroszuk.model.LinkResource.userLinkResources

Is there a mistake somewhere in my thinking process?

User Table:

@Entity
public class User implements Serializable {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    @Email(message = "Email address is not valid.")
    @NotNull
    private String email;
    @NotNull
    @Size(min = 3, max = 100, message = "Username must at least 3 characters.")
    private String userName;
    @NotNull
    @Size(min = 5, max = 100, message = "Password must at least 5 characters.")
    private String password;
    @Transient
    private String confirmPassword;
    private String firstName;
    private String lastName;
    private String token;
    private String role = "ROLE_USER";
    private String lastLogin;
    @OneToMany(mappedBy = "user", cascade = CascadeType.ALL, orphanRemoval = true)
    private Set<UserTextResource> textResources;
    @OneToMany(mappedBy = "user", cascade = CascadeType.ALL, orphanRemoval = true)
    private Set<UserLinkResource> linkResources;
    @OneToMany(mappedBy = "user", cascade = CascadeType.ALL, orphanRemoval = true)
    private Set<UserTaskResource> taskResources;

TaskResource table:

@Entity
public class TaskResource implements Serializable {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    private String name;
    @Temporal(TemporalType.TIMESTAMP)
    private Date creationDate;
    @ManyToOne
    @JoinColumn(name = "chapter_id")
    private Chapter chapter;
    @OneToMany(mappedBy = "task_resource", cascade = CascadeType.ALL)
    private Set<UserTaskResource> userTaskResources;

UserTaskResource table (connecting two tables from above):

@Entity
@Table(name = "user_task_resource")
public class UserTaskResource implements Serializable {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    @Temporal(TemporalType.TIMESTAMP)
    private Date creationDate;
    private String taskText;
    @ManyToOne
    @JoinColumn(name = "user_id")
    private User user;
    @ManyToOne
    @JoinColumn(name = "taskresource_id")
    private TaskResource taskResource;

Binding java Library Xamarin.Android

it’s been two days that I seek on every forum, Docs, tuto, Blog etc..for an anwser.

I began an Android app for my internship I develop it in xamarin C# because i don’t know Java. Until recently everything was fine but now I need to integrate an SDK to use a POS (point of sale) with the app but this library is written in java and I can’t bind it with xamarin even if follow the docs or the tutos (I can’t even debug).

There’s somoene here who already succesfully bind a library which can help me ?

I reached the point where I’m trying to learn quickly java to rewrite all the app.

here is the link to the sdk i need to integrate : https://github.com/sumup/sumup-android-sdk

how to remove the red line under the pom.xml?

I use IDEA, there is red-bold-font label in my pom.xml, I can solve the red line error, but I have no ideas about the red-bold-font error, how to disable the inspection?

My project runs very well.I can’t remove the dependency.

above is all my information and the picture is in below.

enter image description here

How to refactor a lambda expression to a method reference?

My code looks like this:

class A {
    public void m() {
        Arrays.stream("a", "b")
            .map(x -> x + "!") // <-- lambda expression
            .forEachOrdered(System.out::println);
    }
}

I want to refactor it into:

class A {
    public void m() {
        Arrays.stream("a", "b")
            .map(this::t) // <-- method reference
            .forEachOrdered(System.out::println);
    }

    public String t(String x) {
        return x + "!";
    }
}

How can I do this refactoring with IntelliJ?

Java Spark API basic auth. returns 401 when called from Angular app

I have java spark api configured for basic api. When i call URL(with basic auth) from Postman, it returns JSON. But when i call same URL from Angular 4 application it returns: Response for preflight has invalid HTTP status code 401.
Headers in angular are properly set and i already read this answer:
Angular 2 – Response for preflight has invalid HTTP status code 401

And i know problem is in API, but i don’t know how to configure it to allow OPTIONS from browser before auth. Code of route creation is in code below

    private static void create_routes() {

    staticFileLocation("/static");

    Spark.options("/*", (request, response) -> {

        String accessControlRequestHeaders = request.headers("Access-Control-Request-Headers");
        if (accessControlRequestHeaders != null) {
            response.header("Access-Control-Allow-Headers", accessControlRequestHeaders);
        }
        String accessControlRequestMethod = request.headers("Access-Control-Request-Method");
        if (accessControlRequestMethod != null) {
            response.header("Access-Control-Allow-Methods", accessControlRequestMethod);
        }
        return "OK";
    });

    Spark.before((request, response) -> {
        response.header("Access-Control-Allow-Origin", "*");
    });

    RouteOverview.enableRouteOverview("/debug"); 
    path("/api", () -> {
        before("/*", new SecurityFilter(authConfig, "DirectBasicAuthClient"));
    });
    after("/api/*", (request, response) -> response.type("application/json"));

    new ApiController();
}