Moving or copying data from one node to another in firebase database

I am trying to move my data present at one node i.e cart_details/UID to another node orders/UID/order1. I tried different ways of doing it but all seem to be a bit confusing. Is there any built-in functionality or method that could possibly make the job easier? Any help is appreciated.

I have attached the image for the same. IMAGE.


I recomand you to use this method:

public void copyRecord(Firebase fromPath, final Firebase toPath) {
    fromPath.addListenerForSingleValueEvent(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            toPath.setValue(dataSnapshot.getValue(), new Firebase.CompletionListener() {
                @Override
                public void onComplete(FirebaseError firebaseError, Firebase firebase) {
                    if (firebaseError != null) {
                        System.out.println("Copy failed");
                    } else {
                        System.out.println("Success");
                    }
                }
            });
        }

        @Override
        public void onCancelled(FirebaseError firebaseError) {}
    });
}

This is a copy and not a move as you probably see, so the original will remain at his original place. If you would like to delete, you can use removeValue() method on the fromPath just after the System.out.println("Success");.

Edit: (03 May 2018).

Here is the code for using the new Api.

private void moveRecord(DatabaseReference fromPath, final DatabaseReference toPath) {
    ValueEventListener valueEventListener = new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            toPath.setValue(dataSnapshot.getValue()).addOnCompleteListener(new OnCompleteListener<Void>() {
                @Override
                public void onComplete(@NonNull Task<Void> task) {
                    if (task.isComplete()) {
                        Log.d(TAG, "Success!");
                    } else {
                        Log.d(TAG, "Copy failed!");
                    }
                }
            });
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {}
    };
    fromPath.addListenerForSingleValueEvent(valueEventListener);
}