java.lang.NoClassDefFoundError: javax/websocket/ClientEndpointConfig$Configurator from StandardWebsocketClient

I need to write websocket client.
I started following this tutorial: https://github.com/eugenp/tutorials/blob/master/spring-boot/src/main/java/org/baeldung/websocket

and after run StomClient I received:

    java.lang.NoClassDefFoundError: javax/websocket/ClientEndpointConfig$Configurator

at WebSocketTester.testConnection(WebSocketTester.java:16)

Caused by: java.lang.ClassNotFoundException:
javax.websocket.ClientEndpointConfig$Configurator at
java.net.URLClassLoader.findClass(URLClassLoader.java:381) at
java.lang.ClassLoader.loadClass(ClassLoader.java:424) at
sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335) at
java.lang.ClassLoader.loadClass(ClassLoader.java:357) … 23 more

My pom only have this dependencies:

    <dependencies>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-websocket</artifactId>
        <version>5.0.2.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-messaging</artifactId>
        <version>5.0.2.RELEASE</version>
    </dependency>

Client and session handler are copied from github under attached link.
Exception is thrown from this line WebSocketClient client = new StandardWebSocketClient(); in client class

How to get the timestamp of file from the git using jgit?

Is there any way to get timestamp of newly added files from jgit? I have below code which walks the tree and get me the newly added files but I am not able to figure out how can I get the timestamp of that newly added files.

  private Map<String, Object> getFiles(String repoName) {
    File gitWorkDir = new File(repoName);
    Git git = Git.open(gitWorkDir);
    Repository repo = git.getRepository();

    ObjectId lastCommitId = repo.resolve(Constants.HEAD);

    RevWalk revWalk = new RevWalk(repo);
    RevCommit commit = revWalk.parseCommit(lastCommitId);

    RevTree tree = commit.getTree();

    TreeWalk treeWalk = new TreeWalk(repo);
    treeWalk.addTree(tree);
    treeWalk.setRecursive(true);
    Set<String> newlyAdded = new HashSet<String>();
    while (treeWalk.next()) {
      newlyAdded.add(treeWalk.getPathString());
      // newlyAdded.add(treeWalk.getPathString()+":"+"file_timestamp");
    }
    Map<String, Object> m = new HashMap<String, Object>();
    Set<String> changedFiles = new HashSet<String>();
    Set<String> deletedFiles = new HashSet<String>();
    m.put(Constants.CHANGED_FILE_STR, changedFiles);
    m.put(Constants.NEWLY_ADDED_FILE_STR, newlyAdded);
    m.put(Constants.DELETED_FILE_STR, deletedFiles);
    return m;
  }

Can I use commit.getCommitTime() here?

AtomicInteger conditional check thread safe

I ran across a doubt if below is thread safe,

// is this thread safe, final int MAX_COUNT = 3 ?
if(retryCount.get() < MAX_COUNT){
// some other code
retryCount.getAndIncrement();
}else{
 // reset count & some other code
 retryCount.set(0);
}

Is the above conditional check thread safe ?

Can anyone help me with this java error ???

So I have this lab due where I have to make a basic class with some constructors for getting the points in a space… I seem to have struggled to write most of my code , but my test case is giving me an error that states the following….
“java.lang.NoSuchMethodException: Point.getRadius()”

Can anyone help me understand where i went wrong in my code ?

MY Code

 public class Point {

//X and Y cordinates
    private double x;
    private double y;

    //Constructor
    public Point(double x, double y) {
            super();
            this.x = x;
            this.y = y;
    }
    //getters
    public double getX() {
            return x;
    }
    public double getY() {
            return y;
    }

    //Method to find radius of point from the Origin point, which is 
    //passed as argument
    public double getRadius(Point origin){
            double a = this.getX() - origin.getX();
            double b = this.getY() - origin.getY();
            return Math.sqrt(a*a + b*b);
    }

    //Method to find angle of point with respect to x-axis
    public double getAngle(){
            //atan function of Math class is used to find the angle
            //in the range -pi/2 through pi/2, multiply by 180 and 
            //divide by PI to convert into radian
            return Math.atan(this.y/this.x) * 180 / Math.PI;
    }

    //Method to find a point which is rotated 90 of current point from origin
    public Point rotate90(Point origin){
            //these formulas are used to calculate X and Y coordinates of new point
            double newX = origin.getX() + (this.getX()-origin.getX())*Math.cos(90) - (this.getY()-origin.getY())*Math.sin(90);

            double newY = origin.getY() + (this.getX()-origin.getX())*Math.sin(90) + (this.getY()-origin.getY())*Math.cos(90);

            return new Point(newX, newY);

    }

}

Now Here are my test cases

 import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
 import java.util.function.Predicate;
 import java.util.stream.Collectors;
 import java.util.Arrays;
 import java.util.List;
 import java.util.Map;
 import java.lang.reflect.Field;

    import static org.junit.Assert.assertArrayEquals;
    import static org.junit.Assert.assertEquals;
    import static org.junit.Assert.assertTrue;
    import static org.junit.Assert.fail;
    import org.junit.Test;

public class TestCases
{
   public static final double DELTA = 0.00001;

   /*
    * This test is just to get you started.
    */
   @Test
   public void testGetX()
   {
      assertEquals(1.0, new Point(1.0, 2.0).getX(), DELTA);
   }

   /*
    * The tests below here are to verify the basic requirements regarding
    * the "design" of your class.  These are to remain unchanged.
    */

   @Test
   public void testImplSpecifics()
      throws NoSuchMethodException
   {
      final List<String> expectedMethodNames = Arrays.asList(
         "getX",
         "getY",
         "getRadius",
         "getAngle",
         "rotate90"
         );

      final List<Class> expectedMethodReturns = Arrays.asList(
         double.class,
         double.class,
         double.class,
         double.class,
         Point.class
         );

      final List<Class[]> expectedMethodParameters = Arrays.asList(
         new Class[0],
         new Class[0],
         new Class[0],
         new Class[0],
         new Class[0]
         );

      verifyImplSpecifics(Point.class, expectedMethodNames,
         expectedMethodReturns, expectedMethodParameters);
   }

   private static void verifyImplSpecifics(
      final Class<?> clazz,
      final List<String> expectedMethodNames,
      final List<Class> expectedMethodReturns,
      final List<Class[]> expectedMethodParameters)
      throws NoSuchMethodException
   {
      assertEquals("Unexpected number of public fields",
         0, Point.class.getFields().length);

      final List<Method> publicMethods = Arrays.stream(
         clazz.getDeclaredMethods())
            .filter(m -> Modifier.isPublic(m.getModifiers()))
            .collect(Collectors.toList());

      assertEquals("Unexpected number of public methods",
         expectedMethodNames.size(), publicMethods.size());

      assertTrue("Invalid test configuration",
         expectedMethodNames.size() == expectedMethodReturns.size());
      assertTrue("Invalid test configuration",
         expectedMethodNames.size() == expectedMethodParameters.size());

      for (int i = 0; i < expectedMethodNames.size(); i++)
      {
         Method method = clazz.getDeclaredMethod(expectedMethodNames.get(i),
            expectedMethodParameters.get(i));
         assertEquals(expectedMethodReturns.get(i), method.getReturnType());
      }

      // verify that fields are final
      final List<Field> nonFinalFields = Arrays.stream(
         clazz.getDeclaredFields())
            .filter(f -> !Modifier.isFinal(f.getModifiers()))
            .collect(Collectors.toList());

      assertEquals("Unexpected non-final fields", 0, nonFinalFields.size());
   }
}

hashCode and equals for JPA Entity

I need some thoughts on this implementation of hashCode and equals for Hibernate entities.

The main goal is to identify two same objects representing row in db and distinguish them from unsaved objects and remove or add items to relations represented with Set<> collection.

@Data
@MappedSuperclass
public class BaseEntity {

    @Id
    @Column(name = "id")
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private long id;

    private static AtomicLong idGenerator = new AtomicLong(Long.MIN_VALUE);

    @Transient
    private long instanceId = idGenerator.incrementAndGet();

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || !(o instanceof BaseEntity)) return false;
        BaseEntity c = (BaseEntity) o;
        return (this.id != 0 && c.id != 0) && this.id == c.id;
    }

    @Override
    public int hashCode() {
        if (id != 0) { return (int) (id % Integer.MAX_VALUE); }
        int i = (int) (instanceId % Integer.MAX_VALUE);
        return i < 0 ? i : -i;
    }
}

Memory leak 3rd party library java

I am using an irreplaceable 3rd party library in a java project that is holding on to references of a specific object I create and creating an object for each one with a reference to my object creating a large memory leak. I have tools that let me see the leaking objects. My question is how can I free up that memory? The library tools are heavily weaved throughout the project so it would be difficult to make that into its own separate process. Thoughts?

Debug embedded tomcat on heroku

I’m working on a Java web application. I already deploy it to heroku. Now I’m trying to remote debug my application using IntelliJ with no results. To deploy it I use git, then heroku starts it reading and executing the Procfile. And here is the problem. Everywhere I see that to debug I must use this line in my Procfile: web: java -agentlib:jdwp=transport=dt_socket,server=y,address=9090,suspend=n -jar target/myapp.jar. But I can’t put this line on my Procfile because I execute my app using web: sh target/bin/webapp and not java. There’s some workaround to simply debug my application.

3D projectile calculation

I’m currently working on a 3D vector engine that can carry out simple tasks such as trajectory. However, i’m having a bit of trouble understanding how to code the maths behind it.

This is a question that i’m currently having some trouble with:

A trajectory in 3D for a projectile that has an impulse applied to it for t seconds. Time
step = 0.02 seconds. Gravity vector is (0.0, -9.81, 0.0). Assume a 3D Cartesian
coordinate system with the initial position of the projectile at (0,0,0).
Inputs to the problem are the force vector (a 3D vector such as (1.0,1.0,0.0) and the
time that the force is applied t.
Output of the position vectors and velocity vectors on a console until the projectile
hits the ground

public class Vector3DMaths {

    public static Vector3D addition3D(Vector3D vec10, Vector3D vec11){

        Vector3D vecAddResult3D = new Vector3D();

        vecAddResult3D.x = vec10.x + vec11.x;
        vecAddResult3D.y = vec10.y + vec11.y;
        vecAddResult3D.z = vec10.z + vec11.z;

        return vecAddResult3D;
    }

    public static Vector3D subtraction3D(Vector3D vec12, Vector3D vec13){

        Vector3D vecSubtractResult3D = new Vector3D();

        vecSubtractResult3D.x = vec12.x - vec13.x;
        vecSubtractResult3D.y = vec12.y - vec13.y;
        vecSubtractResult3D.z = vec12.z - vec13.z;

        return vecSubtractResult3D;
    }

    public static double findMagnitude3D(Vector3D vec14){

        double d3D;
        double magnitude3D;

        d3D = (Math.pow((vec14.x), 2) + Math.pow((vec14.y), 2) + Math.pow((vec14.z), 2));

        magnitude3D = Math.sqrt(d3D);

        return magnitude3D;
    }

    public static double dotProduct3D(Vector3D a3D, Vector3D b3D){

        double aDOTb3D;
        double aMag3D;
        double bMag3D;
        double angle3D;

        aDOTb3D = (a3D.x * b3D.x) + (a3D.y + b3D.y) + (a3D.z + b3D.z);

        aMag3D = findMagnitude3D(a3D);
        bMag3D = findMagnitude3D(b3D);

        angle3D = Math.acos((aDOTb3D)/(aMag3D * bMag3D));
        angle3D = angle3D * (180/Math.PI);

        return angle3D;
    }

    public static Vector3D unitNormal3D(Vector3D vec15){

        double vec15Mag;
        Vector3D unitN3D = new Vector3D();

        vec15Mag = findMagnitude3D(vec15);

        unitN3D.x = vec15.x / vec15Mag;
        unitN3D.y = vec15.y / vec15Mag;
        unitN3D.z = vec15.z / vec15Mag;

        return unitN3D;
    }

    public static Vector3D scalerMultiple3D(Vector3D vec16, double scalerQuantity){

        Vector3D newVec1 = new Vector3D();

        newVec1.x = vec16.x * scalerQuantity;
        newVec1.y = vec16.y * scalerQuantity;
        newVec1.z = vec16.z * scalerQuantity;

        return newVec1;
    }

}

This is my Vector maths library

    case "16":

                    System.out.println("Force vector: (1.0,1.0,0.0)");
                    System.out.println("Mass of object: 0.1 kg");
                    System.out.println("Time step: 0.02 seconds");
                    System.out.println(" ");

                    Vector3D forceVector = new Vector3D(1.0,1.0,0.0);

                    double scalerMulitple = 0.2;

                    Vector3D vVec1 = Vector3DMaths.scalerMultiple3D(forceVector, scalerMulitple);
                    System.out.println("Velocity vector at 0.00 seconds: (" + vVec1.x + "," + vVec1.y + "," + vVec1.z + ")");

                    double pVecBX = (vVec1.x/2) * 0.02;
                    double pVecBY = (vVec1.y/2) * 0.02;
                    double pVecBZ = (vVec1.z/2) * 0.02;

                    System.out.println("Position vector at 0.00 seconds: (0,0)");
                    System.out.println(" ");

                    for(double time = 0.02; time < 0.2; time = time + 0.02){

                        pVecBX = pVecBX + (((vVec1.x)/2)*0.02);
                        pVecBY = pVecBY + (((vVec1.y)/2)*0.02);
                        pVecBZ = pVecBZ + (((vVec1.z)/2)*0.02);

                        vVec1.x = vVec1.x - (9.81 * 0.02);
                        vVec1.y = vVec1.y - (9.81 * 0.02);
                        vVec1.z = vVec1.z - (9.81 * 0.02);

                        System.out.println("Velocity vector at " + time + " seconds: (" + vVec1.x + "," + vVec1.y + "," + vVec1.z + ")");
                        System.out.println("Position vector at " + time + " seconds: (" + pVecBX + "," + pVecBY + "," + pVecBZ + ")");
                        System.out.println(" ");

}

This is where I am trying to answer the question. The mass isn’t written in the question but I’ve hard coded it to be 0.1kg.

Can anyone help?

Is there a way to view my Java LibGDX game while a breakpoint is active in Intellij?

I am developing a Java game with LibGdx and Intellij. I am rendering images in the game window. I have a for loop that renders individual images in different spots, but they are not rendering in the right place and I need to find out why. It would make it so much easier if I could see where each individual piece is rendering based on their coordinates I calculate, but the window is completely black whenever the program stops for a breakpoint. Is there any way I can make it display the last outputted frame while it’s paused for a breakpoint?

Groovy 3 performance? Especially for testing?

There’s a high-rep guy here talking about bad experiences with Groovy vs “pure” Java.

But that was 7 years ago!

I’m very tempted to switch to Groovy but just wonder a bit about the performance aspect (due to the “fancy” features including dynamic typing). As people say over and over again, 99% of the time this is not terribly important, and with Groovy you can of course always put “pure Java” modules in where you want.

But what about the testing angle? I’m a TDD fanatic … speed of tests is important to me. Should I just dismiss this concern?

Finally, I’ve found very little about testing of Groovy 3 performance. It’s not even clear to me when this version came out: I’ve seen stuff out there talking about plans for Groovy 3 in 2014, and yet the Wikipedia page doesn’t even mention a version 3.