How do you use copyToRealmOrUpdate for a list?












1














This is some code in my Android App:



public class Offer extends RealmObject {
@PrimaryKey
private long id;


}



In my service class:



  RealmList<Offer> currentLocalMerchantOfferList = currentLocalMerchant.getOffers();
RealmList<Offer> findIncomingMerchantOfferList = findIncomingMerchant.getOffers();
if (!EqualsUtil.areEqual(currentLocalMerchantOfferList, findIncomingMerchantOfferList)) {
currentLocalMerchant.setOffers(findIncomingMerchantOfferList == null ? null : realm.copyToRealmOrUpdate(findIncomingMerchantOfferList));
}


I get compile error:



error: incompatible types: bad type in conditional expression
currentLocalMerchant.setOffers(findIncomingMerchantOfferList == null ? null : realm.copyToRealmOrUpdate(findIncomingMerchantOfferList));


Am I using copyToRealmOrUpdate correctly? If not, how do you use it correctly?










share|improve this question





























    1














    This is some code in my Android App:



    public class Offer extends RealmObject {
    @PrimaryKey
    private long id;


    }



    In my service class:



      RealmList<Offer> currentLocalMerchantOfferList = currentLocalMerchant.getOffers();
    RealmList<Offer> findIncomingMerchantOfferList = findIncomingMerchant.getOffers();
    if (!EqualsUtil.areEqual(currentLocalMerchantOfferList, findIncomingMerchantOfferList)) {
    currentLocalMerchant.setOffers(findIncomingMerchantOfferList == null ? null : realm.copyToRealmOrUpdate(findIncomingMerchantOfferList));
    }


    I get compile error:



    error: incompatible types: bad type in conditional expression
    currentLocalMerchant.setOffers(findIncomingMerchantOfferList == null ? null : realm.copyToRealmOrUpdate(findIncomingMerchantOfferList));


    Am I using copyToRealmOrUpdate correctly? If not, how do you use it correctly?










    share|improve this question



























      1












      1








      1







      This is some code in my Android App:



      public class Offer extends RealmObject {
      @PrimaryKey
      private long id;


      }



      In my service class:



        RealmList<Offer> currentLocalMerchantOfferList = currentLocalMerchant.getOffers();
      RealmList<Offer> findIncomingMerchantOfferList = findIncomingMerchant.getOffers();
      if (!EqualsUtil.areEqual(currentLocalMerchantOfferList, findIncomingMerchantOfferList)) {
      currentLocalMerchant.setOffers(findIncomingMerchantOfferList == null ? null : realm.copyToRealmOrUpdate(findIncomingMerchantOfferList));
      }


      I get compile error:



      error: incompatible types: bad type in conditional expression
      currentLocalMerchant.setOffers(findIncomingMerchantOfferList == null ? null : realm.copyToRealmOrUpdate(findIncomingMerchantOfferList));


      Am I using copyToRealmOrUpdate correctly? If not, how do you use it correctly?










      share|improve this question















      This is some code in my Android App:



      public class Offer extends RealmObject {
      @PrimaryKey
      private long id;


      }



      In my service class:



        RealmList<Offer> currentLocalMerchantOfferList = currentLocalMerchant.getOffers();
      RealmList<Offer> findIncomingMerchantOfferList = findIncomingMerchant.getOffers();
      if (!EqualsUtil.areEqual(currentLocalMerchantOfferList, findIncomingMerchantOfferList)) {
      currentLocalMerchant.setOffers(findIncomingMerchantOfferList == null ? null : realm.copyToRealmOrUpdate(findIncomingMerchantOfferList));
      }


      I get compile error:



      error: incompatible types: bad type in conditional expression
      currentLocalMerchant.setOffers(findIncomingMerchantOfferList == null ? null : realm.copyToRealmOrUpdate(findIncomingMerchantOfferList));


      Am I using copyToRealmOrUpdate correctly? If not, how do you use it correctly?







      android realm






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 12 at 8:49

























      asked Nov 12 at 8:36









      Alexei

      1,10311024




      1,10311024
























          2 Answers
          2






          active

          oldest

          votes


















          0














          realm.copyToRealmOrUpdate(findIncomingMerchantOfferList) returns a List<T> and not a RealmList<T>.



          RealmList represents many-relationship to another object type. Therefore, these randomly inserted objects aren't a many-relationship, therefore they are not RealmList.



          In fact, they are internally returned as an ArrayList.



          The way you can change your code to accomodate is by:



          currentLocalMerchant.getOffers().clear();
          currentLocalMerchant.getOffers().addAll(realm.copyToRealmOrUpdate(findIncomingMerchantOfferList));





          share|improve this answer





















          • I need to update items in list in same orders. Is method "addAll()" do this?
            – Alexei
            Nov 12 at 14:20










          • I mean, it's just for(Item item: items) { targetList.add(item) } pretty much
            – EpicPandaForce
            Nov 12 at 15:12



















          -1














          I think you don't need to use copyToRealmOrUpdate method to set value. Just set the value that you have



           if (!EqualsUtil.areEqual(currentLocalMerchantOfferList, findIncomingMerchantOfferList)) {
          currentLocalMerchant.setOffers(findIncomingMerchantOfferList)
          }


          If findIncomingMerchant.getOffers() back to you persistent data than it will work perfectly.






          share|improve this answer





















          • Not work. I get error: java.lang.IllegalArgumentException: 'value' is not a valid managed object.
            – Alexei
            Nov 12 at 14:18










          • I already mentioned that you can add only persistent to persistent data. I think you don't understand my point. Apply this currentLocalMerchant.setOffers(realm.copyfromRealm(findIncomingMerchantOfferList))
            – Sultan Mahmud
            Nov 13 at 8:52










          • currentLocalMerchant.setOffers(realm.copyToRealm(findIncomingMerchantOfferList)); But I geterror: incompatible types: no instance(s) of type variable(s) E exist so that List<E> conforms to RealmList<Offer> currentLocalMerchant.setOffers(realm.copyToRealm(findIncomingMerchantOfferList));
            – Alexei
            Nov 14 at 9:05











          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%2f53258385%2fhow-do-you-use-copytorealmorupdate-for-a-list%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          realm.copyToRealmOrUpdate(findIncomingMerchantOfferList) returns a List<T> and not a RealmList<T>.



          RealmList represents many-relationship to another object type. Therefore, these randomly inserted objects aren't a many-relationship, therefore they are not RealmList.



          In fact, they are internally returned as an ArrayList.



          The way you can change your code to accomodate is by:



          currentLocalMerchant.getOffers().clear();
          currentLocalMerchant.getOffers().addAll(realm.copyToRealmOrUpdate(findIncomingMerchantOfferList));





          share|improve this answer





















          • I need to update items in list in same orders. Is method "addAll()" do this?
            – Alexei
            Nov 12 at 14:20










          • I mean, it's just for(Item item: items) { targetList.add(item) } pretty much
            – EpicPandaForce
            Nov 12 at 15:12
















          0














          realm.copyToRealmOrUpdate(findIncomingMerchantOfferList) returns a List<T> and not a RealmList<T>.



          RealmList represents many-relationship to another object type. Therefore, these randomly inserted objects aren't a many-relationship, therefore they are not RealmList.



          In fact, they are internally returned as an ArrayList.



          The way you can change your code to accomodate is by:



          currentLocalMerchant.getOffers().clear();
          currentLocalMerchant.getOffers().addAll(realm.copyToRealmOrUpdate(findIncomingMerchantOfferList));





          share|improve this answer





















          • I need to update items in list in same orders. Is method "addAll()" do this?
            – Alexei
            Nov 12 at 14:20










          • I mean, it's just for(Item item: items) { targetList.add(item) } pretty much
            – EpicPandaForce
            Nov 12 at 15:12














          0












          0








          0






          realm.copyToRealmOrUpdate(findIncomingMerchantOfferList) returns a List<T> and not a RealmList<T>.



          RealmList represents many-relationship to another object type. Therefore, these randomly inserted objects aren't a many-relationship, therefore they are not RealmList.



          In fact, they are internally returned as an ArrayList.



          The way you can change your code to accomodate is by:



          currentLocalMerchant.getOffers().clear();
          currentLocalMerchant.getOffers().addAll(realm.copyToRealmOrUpdate(findIncomingMerchantOfferList));





          share|improve this answer












          realm.copyToRealmOrUpdate(findIncomingMerchantOfferList) returns a List<T> and not a RealmList<T>.



          RealmList represents many-relationship to another object type. Therefore, these randomly inserted objects aren't a many-relationship, therefore they are not RealmList.



          In fact, they are internally returned as an ArrayList.



          The way you can change your code to accomodate is by:



          currentLocalMerchant.getOffers().clear();
          currentLocalMerchant.getOffers().addAll(realm.copyToRealmOrUpdate(findIncomingMerchantOfferList));






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 12 at 9:55









          EpicPandaForce

          47.1k14126246




          47.1k14126246












          • I need to update items in list in same orders. Is method "addAll()" do this?
            – Alexei
            Nov 12 at 14:20










          • I mean, it's just for(Item item: items) { targetList.add(item) } pretty much
            – EpicPandaForce
            Nov 12 at 15:12


















          • I need to update items in list in same orders. Is method "addAll()" do this?
            – Alexei
            Nov 12 at 14:20










          • I mean, it's just for(Item item: items) { targetList.add(item) } pretty much
            – EpicPandaForce
            Nov 12 at 15:12
















          I need to update items in list in same orders. Is method "addAll()" do this?
          – Alexei
          Nov 12 at 14:20




          I need to update items in list in same orders. Is method "addAll()" do this?
          – Alexei
          Nov 12 at 14:20












          I mean, it's just for(Item item: items) { targetList.add(item) } pretty much
          – EpicPandaForce
          Nov 12 at 15:12




          I mean, it's just for(Item item: items) { targetList.add(item) } pretty much
          – EpicPandaForce
          Nov 12 at 15:12













          -1














          I think you don't need to use copyToRealmOrUpdate method to set value. Just set the value that you have



           if (!EqualsUtil.areEqual(currentLocalMerchantOfferList, findIncomingMerchantOfferList)) {
          currentLocalMerchant.setOffers(findIncomingMerchantOfferList)
          }


          If findIncomingMerchant.getOffers() back to you persistent data than it will work perfectly.






          share|improve this answer





















          • Not work. I get error: java.lang.IllegalArgumentException: 'value' is not a valid managed object.
            – Alexei
            Nov 12 at 14:18










          • I already mentioned that you can add only persistent to persistent data. I think you don't understand my point. Apply this currentLocalMerchant.setOffers(realm.copyfromRealm(findIncomingMerchantOfferList))
            – Sultan Mahmud
            Nov 13 at 8:52










          • currentLocalMerchant.setOffers(realm.copyToRealm(findIncomingMerchantOfferList)); But I geterror: incompatible types: no instance(s) of type variable(s) E exist so that List<E> conforms to RealmList<Offer> currentLocalMerchant.setOffers(realm.copyToRealm(findIncomingMerchantOfferList));
            – Alexei
            Nov 14 at 9:05
















          -1














          I think you don't need to use copyToRealmOrUpdate method to set value. Just set the value that you have



           if (!EqualsUtil.areEqual(currentLocalMerchantOfferList, findIncomingMerchantOfferList)) {
          currentLocalMerchant.setOffers(findIncomingMerchantOfferList)
          }


          If findIncomingMerchant.getOffers() back to you persistent data than it will work perfectly.






          share|improve this answer





















          • Not work. I get error: java.lang.IllegalArgumentException: 'value' is not a valid managed object.
            – Alexei
            Nov 12 at 14:18










          • I already mentioned that you can add only persistent to persistent data. I think you don't understand my point. Apply this currentLocalMerchant.setOffers(realm.copyfromRealm(findIncomingMerchantOfferList))
            – Sultan Mahmud
            Nov 13 at 8:52










          • currentLocalMerchant.setOffers(realm.copyToRealm(findIncomingMerchantOfferList)); But I geterror: incompatible types: no instance(s) of type variable(s) E exist so that List<E> conforms to RealmList<Offer> currentLocalMerchant.setOffers(realm.copyToRealm(findIncomingMerchantOfferList));
            – Alexei
            Nov 14 at 9:05














          -1












          -1








          -1






          I think you don't need to use copyToRealmOrUpdate method to set value. Just set the value that you have



           if (!EqualsUtil.areEqual(currentLocalMerchantOfferList, findIncomingMerchantOfferList)) {
          currentLocalMerchant.setOffers(findIncomingMerchantOfferList)
          }


          If findIncomingMerchant.getOffers() back to you persistent data than it will work perfectly.






          share|improve this answer












          I think you don't need to use copyToRealmOrUpdate method to set value. Just set the value that you have



           if (!EqualsUtil.areEqual(currentLocalMerchantOfferList, findIncomingMerchantOfferList)) {
          currentLocalMerchant.setOffers(findIncomingMerchantOfferList)
          }


          If findIncomingMerchant.getOffers() back to you persistent data than it will work perfectly.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 12 at 9:23









          Sultan Mahmud

          23017




          23017












          • Not work. I get error: java.lang.IllegalArgumentException: 'value' is not a valid managed object.
            – Alexei
            Nov 12 at 14:18










          • I already mentioned that you can add only persistent to persistent data. I think you don't understand my point. Apply this currentLocalMerchant.setOffers(realm.copyfromRealm(findIncomingMerchantOfferList))
            – Sultan Mahmud
            Nov 13 at 8:52










          • currentLocalMerchant.setOffers(realm.copyToRealm(findIncomingMerchantOfferList)); But I geterror: incompatible types: no instance(s) of type variable(s) E exist so that List<E> conforms to RealmList<Offer> currentLocalMerchant.setOffers(realm.copyToRealm(findIncomingMerchantOfferList));
            – Alexei
            Nov 14 at 9:05


















          • Not work. I get error: java.lang.IllegalArgumentException: 'value' is not a valid managed object.
            – Alexei
            Nov 12 at 14:18










          • I already mentioned that you can add only persistent to persistent data. I think you don't understand my point. Apply this currentLocalMerchant.setOffers(realm.copyfromRealm(findIncomingMerchantOfferList))
            – Sultan Mahmud
            Nov 13 at 8:52










          • currentLocalMerchant.setOffers(realm.copyToRealm(findIncomingMerchantOfferList)); But I geterror: incompatible types: no instance(s) of type variable(s) E exist so that List<E> conforms to RealmList<Offer> currentLocalMerchant.setOffers(realm.copyToRealm(findIncomingMerchantOfferList));
            – Alexei
            Nov 14 at 9:05
















          Not work. I get error: java.lang.IllegalArgumentException: 'value' is not a valid managed object.
          – Alexei
          Nov 12 at 14:18




          Not work. I get error: java.lang.IllegalArgumentException: 'value' is not a valid managed object.
          – Alexei
          Nov 12 at 14:18












          I already mentioned that you can add only persistent to persistent data. I think you don't understand my point. Apply this currentLocalMerchant.setOffers(realm.copyfromRealm(findIncomingMerchantOfferList))
          – Sultan Mahmud
          Nov 13 at 8:52




          I already mentioned that you can add only persistent to persistent data. I think you don't understand my point. Apply this currentLocalMerchant.setOffers(realm.copyfromRealm(findIncomingMerchantOfferList))
          – Sultan Mahmud
          Nov 13 at 8:52












          currentLocalMerchant.setOffers(realm.copyToRealm(findIncomingMerchantOfferList)); But I geterror: incompatible types: no instance(s) of type variable(s) E exist so that List<E> conforms to RealmList<Offer> currentLocalMerchant.setOffers(realm.copyToRealm(findIncomingMerchantOfferList));
          – Alexei
          Nov 14 at 9:05




          currentLocalMerchant.setOffers(realm.copyToRealm(findIncomingMerchantOfferList)); But I geterror: incompatible types: no instance(s) of type variable(s) E exist so that List<E> conforms to RealmList<Offer> currentLocalMerchant.setOffers(realm.copyToRealm(findIncomingMerchantOfferList));
          – Alexei
          Nov 14 at 9:05


















          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.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • 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%2f53258385%2fhow-do-you-use-copytorealmorupdate-for-a-list%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

          The Sandy Post

          Danny Elfman

          Pages that link to "Head v. Amoskeag Manufacturing Co."