Share Elements of a List in an Object among Objects like cloud storage (standard library)












1















   class User{
private String Nickname;
private String password;
private ArrayList<E> userdata;
// methods
}


I have a lot of users, everyone with own "userdata".
I would allow a generic user "X" to access some elements of user "Y".



I did this:



class User{
private String Nickname;
private String password;
private ArrayList<E> userdata;
private ArrayList<E> data_shared_from_other_users_to_me;
// methods
}


If the user "Y" will be deleted, every data will be deleted with him, so I will be forced to scan every "User" which have elements of "Y" in his "data_shared_from_other_users_to_me" variable and than delete them.



Is there a better solution to allow sharing and in case of deletion of an user delete every shared data withot looking for them inside every user?










share|improve this question























  • It sounds like you want to re-invent a "database" ;)

    – paulsm4
    Nov 23 '18 at 0:59











  • @paulsm4 It's very difficult to explain well what I am looking for, but no, I don't want to create a database, or something difficult

    – PiKort
    Nov 23 '18 at 1:00











  • It's not "difficult". It sounds like it's probably "the correct design" :( But like anything, the "ideal solution" depends on tradeoffs, which in turn depend on the specific details of your specific "use case", or "requirements". And you haven't really told us anything about that yet...

    – paulsm4
    Nov 23 '18 at 1:05













  • @paulsm4 I have users, with files (userdata List). A user A can let other users to access some files, if A will be deleted in every user, files received from A will disappear and are not accessible anymore. In C it could be resolved using pointers

    – PiKort
    Nov 23 '18 at 1:17













  • Q: Have you considered storing the "files" as blobs in a database?

    – paulsm4
    Nov 23 '18 at 4:39
















1















   class User{
private String Nickname;
private String password;
private ArrayList<E> userdata;
// methods
}


I have a lot of users, everyone with own "userdata".
I would allow a generic user "X" to access some elements of user "Y".



I did this:



class User{
private String Nickname;
private String password;
private ArrayList<E> userdata;
private ArrayList<E> data_shared_from_other_users_to_me;
// methods
}


If the user "Y" will be deleted, every data will be deleted with him, so I will be forced to scan every "User" which have elements of "Y" in his "data_shared_from_other_users_to_me" variable and than delete them.



Is there a better solution to allow sharing and in case of deletion of an user delete every shared data withot looking for them inside every user?










share|improve this question























  • It sounds like you want to re-invent a "database" ;)

    – paulsm4
    Nov 23 '18 at 0:59











  • @paulsm4 It's very difficult to explain well what I am looking for, but no, I don't want to create a database, or something difficult

    – PiKort
    Nov 23 '18 at 1:00











  • It's not "difficult". It sounds like it's probably "the correct design" :( But like anything, the "ideal solution" depends on tradeoffs, which in turn depend on the specific details of your specific "use case", or "requirements". And you haven't really told us anything about that yet...

    – paulsm4
    Nov 23 '18 at 1:05













  • @paulsm4 I have users, with files (userdata List). A user A can let other users to access some files, if A will be deleted in every user, files received from A will disappear and are not accessible anymore. In C it could be resolved using pointers

    – PiKort
    Nov 23 '18 at 1:17













  • Q: Have you considered storing the "files" as blobs in a database?

    – paulsm4
    Nov 23 '18 at 4:39














1












1








1








   class User{
private String Nickname;
private String password;
private ArrayList<E> userdata;
// methods
}


I have a lot of users, everyone with own "userdata".
I would allow a generic user "X" to access some elements of user "Y".



I did this:



class User{
private String Nickname;
private String password;
private ArrayList<E> userdata;
private ArrayList<E> data_shared_from_other_users_to_me;
// methods
}


If the user "Y" will be deleted, every data will be deleted with him, so I will be forced to scan every "User" which have elements of "Y" in his "data_shared_from_other_users_to_me" variable and than delete them.



Is there a better solution to allow sharing and in case of deletion of an user delete every shared data withot looking for them inside every user?










share|improve this question














   class User{
private String Nickname;
private String password;
private ArrayList<E> userdata;
// methods
}


I have a lot of users, everyone with own "userdata".
I would allow a generic user "X" to access some elements of user "Y".



I did this:



class User{
private String Nickname;
private String password;
private ArrayList<E> userdata;
private ArrayList<E> data_shared_from_other_users_to_me;
// methods
}


If the user "Y" will be deleted, every data will be deleted with him, so I will be forced to scan every "User" which have elements of "Y" in his "data_shared_from_other_users_to_me" variable and than delete them.



Is there a better solution to allow sharing and in case of deletion of an user delete every shared data withot looking for them inside every user?







java object generics share






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 23 '18 at 0:56









PiKortPiKort

103




103













  • It sounds like you want to re-invent a "database" ;)

    – paulsm4
    Nov 23 '18 at 0:59











  • @paulsm4 It's very difficult to explain well what I am looking for, but no, I don't want to create a database, or something difficult

    – PiKort
    Nov 23 '18 at 1:00











  • It's not "difficult". It sounds like it's probably "the correct design" :( But like anything, the "ideal solution" depends on tradeoffs, which in turn depend on the specific details of your specific "use case", or "requirements". And you haven't really told us anything about that yet...

    – paulsm4
    Nov 23 '18 at 1:05













  • @paulsm4 I have users, with files (userdata List). A user A can let other users to access some files, if A will be deleted in every user, files received from A will disappear and are not accessible anymore. In C it could be resolved using pointers

    – PiKort
    Nov 23 '18 at 1:17













  • Q: Have you considered storing the "files" as blobs in a database?

    – paulsm4
    Nov 23 '18 at 4:39



















  • It sounds like you want to re-invent a "database" ;)

    – paulsm4
    Nov 23 '18 at 0:59











  • @paulsm4 It's very difficult to explain well what I am looking for, but no, I don't want to create a database, or something difficult

    – PiKort
    Nov 23 '18 at 1:00











  • It's not "difficult". It sounds like it's probably "the correct design" :( But like anything, the "ideal solution" depends on tradeoffs, which in turn depend on the specific details of your specific "use case", or "requirements". And you haven't really told us anything about that yet...

    – paulsm4
    Nov 23 '18 at 1:05













  • @paulsm4 I have users, with files (userdata List). A user A can let other users to access some files, if A will be deleted in every user, files received from A will disappear and are not accessible anymore. In C it could be resolved using pointers

    – PiKort
    Nov 23 '18 at 1:17













  • Q: Have you considered storing the "files" as blobs in a database?

    – paulsm4
    Nov 23 '18 at 4:39

















It sounds like you want to re-invent a "database" ;)

– paulsm4
Nov 23 '18 at 0:59





It sounds like you want to re-invent a "database" ;)

– paulsm4
Nov 23 '18 at 0:59













@paulsm4 It's very difficult to explain well what I am looking for, but no, I don't want to create a database, or something difficult

– PiKort
Nov 23 '18 at 1:00





@paulsm4 It's very difficult to explain well what I am looking for, but no, I don't want to create a database, or something difficult

– PiKort
Nov 23 '18 at 1:00













It's not "difficult". It sounds like it's probably "the correct design" :( But like anything, the "ideal solution" depends on tradeoffs, which in turn depend on the specific details of your specific "use case", or "requirements". And you haven't really told us anything about that yet...

– paulsm4
Nov 23 '18 at 1:05







It's not "difficult". It sounds like it's probably "the correct design" :( But like anything, the "ideal solution" depends on tradeoffs, which in turn depend on the specific details of your specific "use case", or "requirements". And you haven't really told us anything about that yet...

– paulsm4
Nov 23 '18 at 1:05















@paulsm4 I have users, with files (userdata List). A user A can let other users to access some files, if A will be deleted in every user, files received from A will disappear and are not accessible anymore. In C it could be resolved using pointers

– PiKort
Nov 23 '18 at 1:17







@paulsm4 I have users, with files (userdata List). A user A can let other users to access some files, if A will be deleted in every user, files received from A will disappear and are not accessible anymore. In C it could be resolved using pointers

– PiKort
Nov 23 '18 at 1:17















Q: Have you considered storing the "files" as blobs in a database?

– paulsm4
Nov 23 '18 at 4:39





Q: Have you considered storing the "files" as blobs in a database?

– paulsm4
Nov 23 '18 at 4:39












1 Answer
1






active

oldest

votes


















2















  1. Add an embedded or standalone relative database and use many-to-many relations with cascade

  2. Implement many-to-many relations using 2 hash maps (Map<SuperUser, List<ObservableUser>> and Map<ObservableUser, List<SuperUser>>). This will allow to retrieve user's shared data in O(1) and remove relations in one shot.

  3. You can add a list of users who can view current user data (Superusers) to a user profile (my_data_is_shared_with - list) and iterate only them on profile deletion

  4. On user deletion make all his userdata = null first. Then implement a getter for a SuperUser that will return data_shared_from_other_users_to_me.stream().filter(Object::notNull).collect(toList()) and update it if modified (some null values are filtered out)






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53439525%2fshare-elements-of-a-list-in-an-object-among-objects-like-cloud-storage-standard%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    2















    1. Add an embedded or standalone relative database and use many-to-many relations with cascade

    2. Implement many-to-many relations using 2 hash maps (Map<SuperUser, List<ObservableUser>> and Map<ObservableUser, List<SuperUser>>). This will allow to retrieve user's shared data in O(1) and remove relations in one shot.

    3. You can add a list of users who can view current user data (Superusers) to a user profile (my_data_is_shared_with - list) and iterate only them on profile deletion

    4. On user deletion make all his userdata = null first. Then implement a getter for a SuperUser that will return data_shared_from_other_users_to_me.stream().filter(Object::notNull).collect(toList()) and update it if modified (some null values are filtered out)






    share|improve this answer




























      2















      1. Add an embedded or standalone relative database and use many-to-many relations with cascade

      2. Implement many-to-many relations using 2 hash maps (Map<SuperUser, List<ObservableUser>> and Map<ObservableUser, List<SuperUser>>). This will allow to retrieve user's shared data in O(1) and remove relations in one shot.

      3. You can add a list of users who can view current user data (Superusers) to a user profile (my_data_is_shared_with - list) and iterate only them on profile deletion

      4. On user deletion make all his userdata = null first. Then implement a getter for a SuperUser that will return data_shared_from_other_users_to_me.stream().filter(Object::notNull).collect(toList()) and update it if modified (some null values are filtered out)






      share|improve this answer


























        2












        2








        2








        1. Add an embedded or standalone relative database and use many-to-many relations with cascade

        2. Implement many-to-many relations using 2 hash maps (Map<SuperUser, List<ObservableUser>> and Map<ObservableUser, List<SuperUser>>). This will allow to retrieve user's shared data in O(1) and remove relations in one shot.

        3. You can add a list of users who can view current user data (Superusers) to a user profile (my_data_is_shared_with - list) and iterate only them on profile deletion

        4. On user deletion make all his userdata = null first. Then implement a getter for a SuperUser that will return data_shared_from_other_users_to_me.stream().filter(Object::notNull).collect(toList()) and update it if modified (some null values are filtered out)






        share|improve this answer














        1. Add an embedded or standalone relative database and use many-to-many relations with cascade

        2. Implement many-to-many relations using 2 hash maps (Map<SuperUser, List<ObservableUser>> and Map<ObservableUser, List<SuperUser>>). This will allow to retrieve user's shared data in O(1) and remove relations in one shot.

        3. You can add a list of users who can view current user data (Superusers) to a user profile (my_data_is_shared_with - list) and iterate only them on profile deletion

        4. On user deletion make all his userdata = null first. Then implement a getter for a SuperUser that will return data_shared_from_other_users_to_me.stream().filter(Object::notNull).collect(toList()) and update it if modified (some null values are filtered out)







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 23 '18 at 5:27









        AzeeAzee

        1,4841319




        1,4841319
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53439525%2fshare-elements-of-a-list-in-an-object-among-objects-like-cloud-storage-standard%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            "Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

            Alcedinidae

            Origin of the phrase “under your belt”?