Adding constraints on Neo4J nodes

I populate a Neo4J data from a Json file. I wanted to add a constraint so that the data is only populated if it is not already done. The data consists of a root node and sub nodes under it. All nodes implement an interface called Location.
I have (r:RootLocation) then, multiple BaseLocation nodes under it, then PrimaryLocation nodes under the BaseLocation Nodes. Please see the image.
[Example of the node hierarchy[1]

@NodeEnity
public interface Location {
    public String getName();
}

@NodeEntity(label="Country")
public class Country implements Location {

}

I tried to add a constraint like CREATE CONSTRAINT ON (l:RootLocation) ASSERT l.name IS UNIQUE but it does not work. I end up new trees added after every restart. How can I prevent this. The structure is constructed from the JSON file and added to the database using:

locationRepository.save(locationTree)

Using animation on android resulting on strange click behaviour

I need to make this kind of layout
enter image description here

NB: sorry for the use of old ms paint

When I click button 2, page 1(the one with listview) will scale to 0 height (kind of an accordion), and page 2 will come up with translation. And now the problem is, after it looks like the image on the right, I cant click anything on it. After some check, all the click event goes through to page 1

Here is my code for the call:

public void openButtonTop(View v){
    if(!TopOpen){
        scaleViewY(ll, 0f, 1f,0f,false,how_long);
        translateView(
                buttonTanggal,0,0,
                -1*howfar,0,
                how_long);
        translateView(
                ll2,0,0,
                -1*howfar,0,
                how_long);
        TopOpen=true;
    }
}
public void openButtonBelow(View v){
    if(TopOpen){
        scaleViewY(ll, 1f, 0f,0f,true,how_long);
        translateView(
                buttonTanggal,0,0,
                0,-1*howfar,
                how_long);
        translateView(
                ll2,0,0,
                0,-1*howfar,
                how_long
        );
        TopOpen=false;
    }
}

And here is the animation function

public static void scaleViewY(final View v, float startScale, float endScale,float pivotY,final boolean gone,int how_long) {
    Animation anim = new ScaleAnimation(
            1f, 1f, // Start and end values for the X axis scaling
            startScale, endScale, // Start and end values for the Y axis scaling
            Animation.RELATIVE_TO_SELF, 0f, // Pivot point of X scaling
            Animation.RELATIVE_TO_SELF, pivotY); // Pivot point of Y scaling
    anim.setFillAfter(true); // Needed to keep the result of the animation
    anim.setDuration(how_long);
    anim.setAnimationListener(new Animation.AnimationListener() {
        @Override public void onAnimationStart(Animation animation) {
            //if(!gone)v.setVisibility(View.VISIBLE);
            //if(!gone)translateView(v,0,0,-410,0,0);
        }
        @Override public void onAnimationEnd(Animation animation) {
            //if(gone)v.setVisibility(View.GONE);
            //if(gone)translateView(v,0,0,0,-410,0);
        }
        @Override public void onAnimationRepeat(Animation animation) {}
    });
    v.startAnimation(anim);
}
public static void translateView(View v,float fromX,float toX,float fromY, float toY,int how_long){
    TranslateAnimation animation=new TranslateAnimation(fromX,toX,fromY,toY);
    animation.setFillAfter(true);
    animation.setDuration(how_long);
    v.startAnimation(animation);
}

One solution I found the best success with is set the visibilty to GONE for the page 1, but it makes a bit of blinking after page 2 slide up.

Does anyone know how to solve this?

Checking a position’s bounds before accessing it

I am trying to print a out 2D array and determine the element North, South, East, and West of the starting element. I have filled the array with random ints but need help with printing a “-1” for that direction if the direction is out of bounds instead of making the entire program crash

import java.util.Scanner;

public class GetNeighbors
{

    public static void printRow(int[]row) 
        {
            for (int i : row) {
            System.out.print(i);
            System.out.print("t");
        }
        System.out.println();
    }

    public static void main(String[]args)
    {
        Scanner kb=new Scanner(System.in);

        System.out.println("Please enter a number of rows");
        int r=kb.nextInt();
        System.out.println("Please enter a number of columns");
        int c=kb.nextInt();

        int[][]spot=new int[r][c];

        arrayWork(spot);
        directionWork(spot);

    }

    public static void arrayWork(int[][]spot)
    {   
        for(int i=0;i<spot.length;i++)
        {
            for(int j=0;j<spot[i].length;j++)
            {
                spot[i][j]=(int)(Math.random()*1001);
            }
        }
        for(int[]row:spot) 
            {
            printRow(row);
            }
    }

    public static void directionWork(int[][]spot)
    {
        Scanner kb=new Scanner(System.in);

        System.out.println("Please choose a row for an element");
        int row=kb.nextInt();
        System.out.println("Please choose a column for an element");
        int col=kb.nextInt();

        System.out.println("Requested neighbors for element at row "+row+", col "+col+" "+"("+spot[row][col]+")");

        System.out.print("North: "+spot[row-1][col]);
        System.out.print(" South: "+spot[row+1][col]);
        System.out.print(" East: "+spot[row][col+1]);
        System.out.print(" West: "+spot[row][col-1]);
    }
}

Split the String involve two special character

I have a string value which look like the following :

TE;R20;T11;19

which i would like to split it into TE,R20,T11 and 19. I try to apply the split method on it but unfortunately it’s still can’t split the string properly

Here is my source code

String description1 = CSVdata2[7];
System.out.println("The description1 is :"+description1);
String email1 = CSVdata2[2];
String [] data1 = description1.split(";");
String ID1 = data1[0];
String [] data2 = SysID1.split("/");
String ID2 = data2[0];
System.out.println("The ID2 is :"+ID2);

Here is my sample output

The description1 is :TE;R20;T11;19
The ID2 is :TE

I tried search some approach online but i still can’t make it split into the string that i want

Trying to test input validity

I’ve been working on a small project today, and after searching around for answers on StackOverflow and elsewhere, I’ve come to a roadblock.

I’ve been attempting to create a choose-your-own-adventure style game in Java and I’m beginning with creating a character using three characteristics (name, race, gender). I plan on using these to allow for branches in the story.

The problem is that I’m not getting the results I’m looking for. Currently, I’ve gotten my code to work, with a print statement showing the selections made by the player.

//list out character description

    System.out.println("You are " + Name + ", a " + characterGender + " " + 
    characterRace + ".");

However the output returns null values. I had it working properly until I attempted to implement a test on the input given to root out invalid entries.

//create test to verify validity of race selection

    boolean raceBoolean;

    if (raceInt < 0 || raceInt > 4) {

        raceBoolean = true;

    try {

        do {

    //selection list that defines options

                if (raceInt == 1)
                    characterRace = "human";

                else if (raceInt == 2)
                    characterRace = "elf";

                else if (raceInt == 3)
                    characterRace = "orc";

                else if (raceInt == 4)
                    characterRace = "undead";

        }

        while (raceBoolean = false);

            System.out.println("Nice try. Enter a valid number for one of the four races!");

        }

            finally {

        }

I’m honestly at a loss. I know that this is simple stuff, but I’m trying to teach myself. I appreciate any help that may be provided. Other topics aren’t very helpful given that they don’t provide much context for why there was an issue in the first place.

Thank you in advance. I’m honestly seeking to learn how to do this properly.

Full code below:

import java.util.Scanner;

public class Adventure {

public static void main(String[] args) {
    // TODO Auto-generated method stub

    //insert input tool
    Scanner input = new Scanner(System.in);

    //create inventory object for gold and items
    int gold = 10;

    //create health points object 

    //address player with greeting
    System.out.println("Welcome to your adventure!");

    //ask for character name, race, and gender

    System.out.println("What will your adventurer's name be?");

    String Name = input.nextLine();

    System.out.println("What will your adventurer's race be?");
    System.out.println("1. Human");
    System.out.println("2. Elf");
    System.out.println("3. Orc");
    System.out.println("4. Undead");

    int raceInt = input.nextInt();

    String characterRace = "";

    //create test to verify validity of race selection

    boolean raceBoolean;

    if (raceInt < 0 || raceInt > 4) {

        raceBoolean = true;

    try {

        do {

    //selection list that defines options

                if (raceInt == 1)
                    characterRace = "human";

                else if (raceInt == 2)
                    characterRace = "elf";

                else if (raceInt == 3)
                    characterRace = "orc";

                else if (raceInt == 4)
                    characterRace = "undead";

        }

        while (raceBoolean = false);

            System.out.println("Nice try. Enter a valid number for one of the four races!");

        }

            finally {

        }

    }

    //ask for character gender

    System.out.println("What will your adventurer's gender be?");
    System.out.println("1. Male");
    System.out.println("2. Female");

    int genderInt = input.nextInt();

    String characterGender = "";

    if (genderInt == 1)
        characterGender = "male";

    else if (genderInt == 2)
        characterGender = "female";

    //list out character description

    System.out.println("You are " + Name + ", a " + characterGender + " " + characterRace + ".");

    //introduce player to adventure with different introductions for different races

    System.out.print("You came to Glassolin with only ten gold pieces to your name. ");

    if (characterRace == "human")
        System.out.print("Glassolin is home to many humans; some from the far reaches of the realm. You feel right at home, more or less,"
                + " as long as you ignore the occasional odd look from the cityfolk staring at someone dressed in farmer's clothes.");
    else if (characterRace == "elf")
        System.out.print("While an elf isn't the most common sight around town, the locals seem like they don't care one way or another "
                + "about you wandering the streets. ");


}

}

how to store array list index into a variable

how to store array list index into a variable?

Name:

            //1st loop index    //2nd loop index

info.add(scan.next()); index 0, index 2

Last name:

            //1st loop index   //2nd loop index

info.add(scan.next()); index 1, index 3

Add another information: (different person) Y/N

String name 1 = (String) info.get(0);
String last name 1 = (String) info.get(1);

String name 2 = (String) info.get(2);
String last name 2 = (String) info.get(3);

spring boot not seeing request parameters

My angular app is calling a REST API web service run by Spring boot. Here is the parameter dump from the firefox web console:

enter image description here

My spring boot webapp is throwing this exception:

org.springframework.web.bind.MissingServletRequestParameterException: Required String parameter 'payload' is not present
    at org.springframework.web.method.annotation.RequestParamMethodArgumentResolver.handleMissingValue(RequestParamMethodArgumentResolver.java:198) ~[spring-web-4.3.13.RELEASE.jar:4.3.13.RELEASE]
    at org.springframework.web.method.annotation.AbstractNamedValueMethodArgumentResolver.resolveArgument(AbstractNamedValueMethodArgumentResolver.java:109) ~[spring-web-4.3.13.RELEASE.jar:4.3.13.RELEASE]
    at org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:121) ~[spring-web-4.3.13.RELEASE.jar:4.3.13.RELEASE]
    at org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:158) [spring-web-4.3.13.RELEASE.jar:4.3.13.RELEASE]
    at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:128) [spring-web-4.3.13.RELEASE.jar:4.3.13.RELEASE]
    at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:97) [spring-webmvc-4.3.13.RELEASE.jar:4.3.13.RELEASE]
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827) [spring-webmvc-4.3.13.RELEASE.jar:4.3.13.RELEASE]
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738) [spring-webmvc-4.3.13.RELEASE.jar:4.3.13.RELEASE]
    at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85) [spring-webmvc-4.3.13.RELEASE.jar:4.3.13.RELEASE]
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:967) [spring-webmvc-4.3.13.RELEASE.jar:4.3.13.RELEASE]
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:901) [spring-webmvc-4.3.13.RELEASE.jar:4.3.13.RELEASE]
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970) [spring-webmvc-4.3.13.RELEASE.jar:4.3.13.RELEASE]
    at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:872) [spring-webmvc-4.3.13.RELEASE.jar:4.3.13.RELEASE]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:707) [javax.servlet-api-3.1.0.jar:3.1.0]
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846) [spring-webmvc-4.3.13.RELEASE.jar:4.3.13.RELEASE]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:790) [javax.servlet-api-3.1.0.jar:3.1.0]
    at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:841) [jetty-servlet-9.4.7.v20170914.jar:9.4.7.v20170914]
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1650) [jetty-servlet-9.4.7.v20170914.jar:9.4.7.v20170914]
    at org.eclipse.jetty.websocket.server.WebSocketUpgradeFilter.doFilter(WebSocketUpgradeFilter.java:206) [websocket-server-9.4.7.v20170914.jar:9.4.7.v20170914]

And here is my method…

@RequestMapping(value = "/login", method = RequestMethod.POST)
@ResponseBody
public String login(@RequestParam(NetworkKeyNames.KEY_PAYLOAD) String payload) throws IOException {
    log.error("Payload=" + payload);
    TypeReference<Map<String, String>> typeRef = new TypeReference<Map<String, String>>() {
    };
    Map<String, String> payloadMap = objectMapper.readValue(payload, typeRef);
    String username = payloadMap.get(NetworkKeyNames.KEY_USERNAME);
    String password = payloadMap.get(NetworkKeyNames.KEY_PASSWORD);

    String result = securityService.login(username, password);
    return result;
}

It’s obvious that it’s hitting my spring boot app, but what’s happening to the parameters? Is there any way I can get more information?

Asteria Warp Flow Designer Newbie Questions

First, I don’t know what version this is.

Just want to ask simple things

Coding inside the java cup element, they have a method named “dateValue()”
I want to know how to use it properly, I tried entering different date formats (yyyymmdd, yyyy-mm-dd, mmddyyy.. and many other more) it accepts the input without any pop up errors, but it does not recognize the correct value for the input.
no matter what date I tried, it always outputs a complete timestamp with the date part as 1970-01-01, which is the very first date value for java.util.Date class. So I assume that my input is invalid.

Anyone knows how to use .dateValue()?

(additional but not important question to those who uses this software)
-How to save an object to a variable or maybe with a stream? within the flow.

how to map a file on server to url so user can use url to display / download file(png/pdf)

I have created a utility to upload a file on server for example and image file or a pdf file using java spring rest services.

But now I want to provide a url of uploaded image or pdf through a web service so I can display that file on html or in new tab using url
example http://localhost:8080/myimage.png http://localhost:8080/myfile.pdf

Please let me know what is the solution for this