View Javadoc
1   package com.srv4pos.server.api.sync.sample;
2   
3   import com.srv4pos.server.api.category.CategoryInfo;
4   import com.srv4pos.server.api.commodity.CommodityInfo;
5   import com.srv4pos.server.api.day.DayInfo;
6   import com.srv4pos.server.api.keyboard.KeyboardInfo;
7   import com.srv4pos.server.api.keyboardentry.KeyboardEntryInfo;
8   import com.srv4pos.server.api.order.OrderInfo;
9   import com.srv4pos.server.api.product.ProductInfo;
10  import com.srv4pos.server.api.sale.SaleInfo;
11  import com.srv4pos.server.api.sale.SaleSlotInfo;
12  import com.srv4pos.server.api.seller.SellerInfo;
13  import com.srv4pos.server.api.sync.SyncVersionInfo;
14  import com.srv4pos.server.api.tax.TaxInfo;
15  import com.srv4pos.server.api.transportation.TripInfo;
16  import com.srv4pos.server.api.treasurer.TreasurerInfo;
17  
18  import java.util.ArrayList;
19  import java.util.List;
20  
21  public class MemoryLocalStorage {
22  
23      private SellerInfo seller;
24      private boolean sellerIsSynced;
25  
26      private List<SyncProduct> products = new ArrayList<SyncProduct>();
27      private List<SyncTax> taxes = new ArrayList<SyncTax>();
28      private List<SyncCategory> categories = new ArrayList<SyncCategory>();
29      private List<SyncCommodity> commodities = new ArrayList<SyncCommodity>();
30      private List<SyncTreasurer> treasurers = new ArrayList<SyncTreasurer>();
31      private List<SyncOrder> orders = new ArrayList<SyncOrder>();
32      private List<SyncKeyboard> keyboards = new ArrayList<SyncKeyboard>();
33      private List<SyncKeyboardEntry> keyboardEntries = new ArrayList<SyncKeyboardEntry>();
34      private List<SyncSaleSlot> saleSlots = new ArrayList<SyncSaleSlot>();
35      private List<SyncDay> days = new ArrayList<SyncDay>();
36      private List<SyncTrip> trips = new ArrayList<SyncTrip>();
37      private List<SyncSale> sales = new ArrayList<SyncSale>();
38  
39      private int localVersion;
40  
41      public MemoryLocalStorage() {
42          localVersion = 0;
43      }
44  
45      public String toString() {
46          StringBuilder sb = new StringBuilder();
47  
48          sb.append("version: ")
49                  .append(localVersion).append("\n")
50                  .append((sellerIsSynced ? "synced " : "not synced "))
51                  .append(seller).append("\n");
52  
53          for (final SyncTax tax : taxes) {
54              sb.append(tax).append("\n");
55          }
56  
57          for (final SyncProduct product : products) {
58              sb.append(product).append("\n");
59          }
60  
61          for (final SyncCategory category : categories) {
62              sb.append(category).append("\n");
63          }
64  
65          for (final SyncCommodity commodity : commodities) {
66              sb.append(commodity).append("\n");
67          }
68  
69          for (final SyncTreasurer treasurer : treasurers) {
70              sb.append(treasurer).append("\n");
71          }
72  
73          for (final SyncOrder order : orders) {
74              sb.append(order).append("\n");
75          }
76  
77          return sb.toString();
78      }
79  
80      // alternative to this: make MemoryLocalStorage to implement SyncVersionInfo
81      // or even use some independent class which implements SyncVersionInfo
82      private SyncVersionInfo syncInfo = new SyncVersionInfo() {
83          public int getVersion() {
84              return localVersion;
85          }
86  
87          public void setVersion(int version) {
88              localVersion = version;
89          }
90  
91          public String toString() {
92              return String.format("SyncInfo version: %d", getVersion());
93          }
94      };
95  
96      public SyncVersionInfo getSyncInfo() {
97          return syncInfo;
98      }
99  
100     public int getLocalVersion() {
101         return localVersion;
102     }
103 
104 
105     public SellerInfo getSeller() {
106         return seller;
107     }
108 
109     public void setSeller(final SellerInfo seller) {
110         this.seller = seller;
111         setSellerSynced(false);
112     }
113 
114     public boolean isSellerSynced() {
115         return sellerIsSynced;
116     }
117 
118     public void setSellerSynced(final boolean sellerSynced) {
119         this.sellerIsSynced = sellerSynced;
120     }
121 
122 
123     public List<SyncProduct> getProducts() {
124         return products;
125     }
126 
127     public void setProducts(final List<SyncProduct> products) {
128         this.products = products;
129     }
130 
131     public SyncProduct getProduct(final int index) {
132         if (index >= getProducts().size()) {
133             return null;
134         }
135         return getProducts().get(index);
136     }
137 
138     public SyncProduct getProductByIdentifier(final String identifier) {
139         if (identifier == null) {
140             return null;
141         }
142 
143         for (final SyncProduct p : products) {
144             final ProductInfo info = p.getInfo();
145             if (info != null //&& !info.isDeleted()
146                     && info.getIdentifier() != null
147                     && info.getIdentifier().equals(identifier)) {
148                 return p;
149             }
150         }
151         return null;
152     }
153 
154     public List<SyncProduct> getProductsByTax(final SyncTax tax) {
155 
156         List<SyncProduct> productList = new ArrayList<SyncProduct>();
157 
158         for (final SyncProduct syncProduct : getProducts()) {
159             if (!syncProduct.getInfo().isDeleted()
160                     && syncProduct.getTax() == tax) {
161                 productList.add(syncProduct);
162             }
163         }
164 
165         return productList;
166     }
167 
168     public List<SyncProduct> getProductsByTaxIndex(final int index) {
169         return getProductsByTax(getTax(index));
170     }
171 
172     public List<SyncProduct> getProductsByCategory(final SyncCategory category) {
173 
174         List<SyncProduct> productList = new ArrayList<SyncProduct>();
175 
176         for (final SyncCommodity commodity : getCommodities()) {
177             if (commodity.getCategory() == category
178                     && !commodity.getInfo().isDeleted()) {
179 
180                 final SyncProduct product = commodity.getProduct();
181 
182                 if (product != null && !product.getInfo().isDeleted()) {
183                     productList.add(product);
184                 }
185             }
186         }
187 
188         return productList;
189     }
190 
191     public List<SyncProduct> getProductsByCategoryIndex(final int index) {
192         return getProductsByCategory(getCategory(index));
193     }
194 
195     public void add(final SyncProduct p) {
196         products.add(p);
197     }
198 
199     public int delete(final SyncProduct product, final boolean forceDeleteRelated) {
200 
201         int countDeleted = 0;
202 
203         for (SyncCommodity commodity : getCommodities()) {
204             if (commodity.getProduct() == product) {
205                 if (forceDeleteRelated) {
206                     commodity.getInfo().setDeleted(true);
207                     countDeleted++;
208                     break;
209                 } else {
210                     return 0;
211                 }
212             }
213         }
214         product.getInfo().setDeleted(true);
215         countDeleted++;
216 
217         return countDeleted;
218     }
219 
220 
221     public List<SyncTax> getTaxes() {
222         return taxes;
223     }
224 
225     public void setTaxes(final List<SyncTax> taxes) {
226         this.taxes = taxes;
227     }
228 
229     public SyncTax getTax(final int index) {
230         if (index >= getTaxes().size()) {
231             return null;
232         }
233         return getTaxes().get(index);
234     }
235 
236     public SyncTax getTaxByIdentifier(final String identifier) {
237         if (identifier == null) {
238             return null;
239         }
240 
241         for (final SyncTax tax : taxes) {
242             final TaxInfo info = tax.getInfo();
243             if (info != null //&& !info.isDeleted()
244                     && info.getIdentifier() != null
245                     && info.getIdentifier().equals(identifier)) {
246                 return tax;
247             }
248         }
249         return null;
250     }
251 
252     public SyncTax getTaxByVat(final int vat) {
253 
254         for (final SyncTax tax : taxes) {
255             final TaxInfo info = tax.getInfo();
256             if (info != null && !info.isDeleted() && info.getVat() == vat) {
257                 return tax;
258             }
259         }
260         return null;
261     }
262 
263     public void add(final SyncTax tax) {
264         taxes.add(tax);
265     }
266 
267     public int delete(final SyncTax tax, final boolean forceDeleteRelated) {
268 
269         int countDeleted = 0;
270 
271         for (SyncProduct product : getProducts()) {
272             if (product.getTax() == tax) {
273                 if (forceDeleteRelated) {
274                     countDeleted += delete(product, forceDeleteRelated);
275                 } else {
276                     return 0;
277                 }
278             }
279         }
280         tax.getInfo().setDeleted(true);
281         countDeleted++;
282 
283         return countDeleted;
284     }
285 
286 
287     public List<SyncCategory> getCategories() {
288         return categories;
289     }
290 
291     public void setCategories(final List<SyncCategory> categories) {
292         this.categories = categories;
293     }
294 
295     public SyncCategory getCategory(final int index) {
296         if (index >= getCategories().size()) {
297             return null;
298         }
299         return getCategories().get(index);
300     }
301 
302     public SyncCategory getCategoryByIdentifier(final String identifier) {
303         if (identifier == null) {
304             return null;
305         }
306 
307         for (final SyncCategory cat : categories) {
308             final CategoryInfo info = cat.getInfo();
309             if (info != null //&& !info.isDeleted()
310                     && info.getIdentifier() != null
311                     && info.getIdentifier().equals(identifier)) {
312                 return cat;
313             }
314         }
315         return null;
316     }
317 
318     public void add(final SyncCategory cat) {
319         categories.add(cat);
320     }
321 
322     public int delete(final SyncCategory cat, final boolean forceDeleteRelated) {
323 
324         int countDeleted = 0;
325 
326         for (SyncCommodity commodity : getCommodities()) {
327             if (commodity.getCategory() == cat) {
328                 if (forceDeleteRelated) {
329                     countDeleted += delete(commodity, forceDeleteRelated);
330                 } else {
331                     return 0;
332                 }
333             }
334         }
335         cat.getInfo().setDeleted(true);
336         countDeleted++;
337 
338         return countDeleted;
339     }
340 
341 
342     public List<SyncCommodity> getCommodities() {
343         return commodities;
344     }
345 
346     public void setCommodities(final List<SyncCommodity> commodities) {
347         this.commodities = commodities;
348     }
349 
350     public SyncCommodity getCommodity(final int index) {
351         if (index >= getCommodities().size()) {
352             return null;
353         }
354         return getCommodities().get(index);
355     }
356 
357     public SyncCommodity getCommodityByIdentifier(final String identifier) {
358         return getCommodityByIdentifier(identifier, true); // default behaviour for all getByIdentifier - including deleted too
359     }
360 
361     public SyncCommodity getCommodityByIdentifier(final String identifier, boolean checkDeletedToo) {
362         if (identifier == null) {
363             return null;
364         }
365 
366         for (final SyncCommodity c : commodities) {
367             final CommodityInfo info = c.getInfo();
368             if (info != null && (!info.isDeleted() || checkDeletedToo)
369                     && info.getIdentifier() != null
370                     && info.getIdentifier().equals(identifier)) {
371                 return c;
372             }
373         }
374         return null;
375     }
376 
377     public void add(final SyncCommodity c) {
378         commodities.add(c);
379     }
380 
381     public int delete(final SyncCommodity c, final boolean forceDeleteRelated) {
382 
383         int countDeleted = 0;
384 
385         if (c.getProduct() != null) {
386             if (forceDeleteRelated) {
387                 c.getProduct().getInfo().setDeleted(true);
388                 countDeleted++;
389             } else {
390                 return 0;
391             }
392         }
393 
394         c.getInfo().setDeleted(true);
395         countDeleted++;
396 
397         return countDeleted;
398     }
399 
400     public List<SyncTreasurer> getTreasurers() {
401         return treasurers;
402     }
403 
404     public void setTreasurers(List<SyncTreasurer> treasurers) {
405         this.treasurers = treasurers;
406     }
407 
408     public SyncTreasurer getTreasurer(final int index) {
409         if (index >= getTreasurers().size()) {
410             return null;
411         }
412         return getTreasurers().get(index);
413     }
414 
415     public SyncTreasurer getTreasurerByIdentifier(final String identifier) {
416         if (identifier == null) {
417             return null;
418         }
419 
420         for (final SyncTreasurer t : treasurers) {
421             final TreasurerInfo info = t.getInfo();
422             if (info != null //&& !info.isDeleted()
423                     && info.getIdentifier() != null
424                     && info.getIdentifier().equals(identifier)) {
425                 return t;
426             }
427         }
428         return null;
429     }
430 
431     public void add(final SyncTreasurer t) {
432         treasurers.add(t);
433     }
434 
435     public int delete(final SyncTreasurer t, final boolean forceDeleteRelated) {
436 
437         int countDeleted = 0;
438 
439         t.getInfo().setDeleted(true);
440         countDeleted++;
441 
442         return countDeleted;
443     }
444 
445     public SyncTreasurer getTreasurerBySsn(final String ssn) {
446 
447         if (ssn == null) {
448             return null;
449         }
450 
451         for (final SyncTreasurer t : treasurers) {
452             final TreasurerInfo info = t.getInfo();
453             if (info != null && !info.isDeleted() && ssn.equals(info.getSsn())) {
454                 return t;
455             }
456         }
457         return null;
458     }
459 
460     public SyncTreasurer getTreasurerByName(final String name) {
461 
462         if (name == null) {
463             return null;
464         }
465 
466         for (final SyncTreasurer t : treasurers) {
467             final TreasurerInfo info = t.getInfo();
468             if (info != null && !info.isDeleted() && name.equals(info.getName())) {
469                 return t;
470             }
471         }
472         return null;
473     }
474 
475 
476     public List<SyncOrder> getOrders() {
477         return orders;
478     }
479 
480     public void setOrders(List<SyncOrder> orders) {
481         this.orders = orders;
482     }
483 
484     public SyncOrder getOrder(final int index) {
485         if (index >= getOrders().size()) {
486             return null;
487         }
488         return getOrders().get(index);
489     }
490 
491     public SyncOrder getOrderByIdentifier(final String identifier) {
492         if (identifier == null) {
493             return null;
494         }
495 
496         for (final SyncOrder order : orders) {
497             final OrderInfo info = order.getInfo();
498             if (info != null //&& !info.isDeleted()
499                     && info.getIdentifier() != null
500                     && info.getIdentifier().equals(identifier)) {
501                 return order;
502             }
503         }
504         return null;
505     }
506 
507     public void add(final SyncOrder order) {
508         orders.add(order);
509     }
510 
511     public int delete(final SyncOrder order, final boolean forceDeleteRelated) {
512 
513         int countDeleted = 0;
514 
515         order.getInfo().setDeleted(true);
516         countDeleted++;
517 
518         return countDeleted;
519     }
520 
521     public List<SyncKeyboard> getKeyboards() {
522         return keyboards;
523     }
524 
525     public void setKeyboards(List<SyncKeyboard> keyboards) {
526         this.keyboards = keyboards;
527     }
528 
529     public SyncKeyboard getKeyboard(final int index) {
530         if (index >= getKeyboards().size()) {
531             return null;
532         }
533         return getKeyboards().get(index);
534     }
535 
536     public SyncKeyboard getKeyboardByIdentifier(final String idenifier) {
537         if (idenifier == null) {
538             return null;
539         }
540 
541         for (final SyncKeyboard keyboard : keyboards) {
542             final KeyboardInfo info = keyboard.getInfo();
543             if (info != null && info.getIdentifier() != null && info.getIdentifier().equals(idenifier)) {
544                 return keyboard;
545             }
546         }
547         return null;
548     }
549 
550     public void add(final SyncKeyboard keyboard) {
551         keyboards.add(keyboard);
552     }
553 
554     public int delete(final SyncKeyboard keyboard) {
555 
556         int countDeleted = 0;
557 
558         keyboard.getInfo().setDeleted(true);
559         countDeleted++;
560 
561         return countDeleted;
562     }
563 
564     public List<SyncKeyboardEntry> getKeyboardEntries() {
565         return keyboardEntries;
566     }
567 
568     public List<SyncSaleSlot> getSaleSlots() {
569         return saleSlots;
570     }
571 
572     public void setKeyboardEntries(List<SyncKeyboardEntry> keyboardEntries) {
573         this.keyboardEntries = keyboardEntries;
574     }
575 
576     public void setSaleSlots(List<SyncSaleSlot> saleSlots) {
577         this.saleSlots = saleSlots;
578     }
579 
580     public SyncKeyboardEntry getKeyboardEntry(final int index) {
581         if (index >= getKeyboardEntries().size()) {
582             return null;
583         }
584         return getKeyboardEntries().get(index);
585     }
586 
587     public SyncSaleSlot getSaleSlot(final int index) {
588         if (index >= getSaleSlots().size()) {
589             return null;
590         }
591         return getSaleSlots().get(index);
592     }
593 
594     public SyncKeyboardEntry getKeyboardEntryByIdentifier(final String idenifier) {
595         if (idenifier == null) {
596             return null;
597         }
598 
599         for (final SyncKeyboardEntry keyboardEntry : keyboardEntries) {
600             final KeyboardEntryInfo info = keyboardEntry.getInfo();
601             if (info != null && info.getIdentifier() != null && info.getIdentifier().equals(idenifier)) {
602                 return keyboardEntry;
603             }
604         }
605         return null;
606     }
607 
608     public SyncSaleSlot getSaleSlotByIdentifier(final String identifier) {
609         if (identifier == null) {
610             return null;
611         }
612 
613         for (final SyncSaleSlot saleSlot : saleSlots) {
614             final SaleSlotInfo info = saleSlot.getInfo();
615             if (info != null && info.getIdentifier() != null && info.getIdentifier().equals(identifier)) {
616                 return saleSlot;
617             }
618         }
619         return null;
620     }
621 
622     public void add(final SyncSaleSlot saleSlot) {
623         saleSlots.add(saleSlot);
624     }
625 
626     public void add(final SyncKeyboardEntry keyboardEntry) {
627         keyboardEntries.add(keyboardEntry);
628     }
629 
630     public List<SyncDay> getDays() {
631         return days;
632     }
633 
634     public SyncDay getDayByIdentifier(String identifier) {
635         if (identifier == null) {
636             return null;
637         }
638 
639         for (final SyncDay day : days) {
640             final DayInfo info = day.getInfo();
641             if (info != null && info.getIdentifier() != null && info.getIdentifier().equals(identifier)) {
642                 return day;
643             }
644         }
645 
646         return null;
647     }
648 
649     public void add(SyncDay day) {
650         days.add(day);
651     }
652 
653     public void add(SyncTrip trip) {
654         trips.add(trip);
655     }
656 
657     public SyncTrip getTripByIdentifier(String identifier) {
658         if (identifier == null) {
659             return null;
660         }
661 
662         for (SyncTrip trip : trips) {
663             TripInfo info = trip.getInfo();
664             if (info != null && info.getIdentifier() != null && info.getIdentifier().equals(identifier)) {
665                 return trip;
666             }
667         }
668 
669         return null;
670     }
671 
672     public List<SyncTrip> getTrips() {
673         return trips;
674     }
675 
676     public List<SyncSale> getSales() {
677         return sales;
678     }
679 
680     public SyncSale getSaleByIdentifier(String identifier) {
681         if (identifier == null) {
682             return null;
683         }
684 
685         for (SyncSale sale : sales) {
686             SaleInfo info = sale.getInfo();
687             if (info != null && info.getIdentifier() != null && info.getIdentifier().equals(identifier)) {
688                 return sale;
689             }
690         }
691 
692         return null;
693     }
694 
695     public List<SyncSale> getSalesByTripIdentifier(String tripIdentifier) {
696         if (tripIdentifier == null) {
697             return null;
698         }
699 
700         List<SyncSale> sales = new ArrayList<SyncSale>();
701         for (SyncSale sale : sales) {
702             if (sale.getInfo() == null) {
703                 continue;
704             }
705 
706             TripInfo info = getTripByIdentifier(sale.getInfo().getTripIdentifier()).getInfo();
707 
708             if (info != null && info.getIdentifier() != null && info.getIdentifier().equals(tripIdentifier)) {
709                 sales.add(sale);
710             }
711         }
712 
713         if (sales.isEmpty()) {
714             return null;
715         } else {
716             return sales;
717         }
718     }
719 
720     public void add(SyncSale sale) {
721         sales.add(sale);
722     }
723 
724     public int delete(final SyncKeyboardEntry keyboardEntry) {
725 
726         int countDeleted = 0;
727 
728         keyboardEntry.getInfo().setDeleted(true);
729         countDeleted++;
730 
731         return countDeleted;
732     }
733     /**
734      * <p>Simple check if current storage object is a superset of other memory storage (contains everything from other storage).<br/>
735      * Does not compare full contents of entities, compares just entity identifiers. Ignores deleted entities.</p>
736      *
737      * @param storage MemoryLocalStorage to compare with
738      * @return true if self contains everything from storage
739      */
740     public boolean isSupersetOf(final MemoryLocalStorage storage) {
741 
742         if (this == storage) {
743             throw new UnsupportedOperationException("It is useless to compare some storage with itself");
744         }
745 
746         for (final SyncCommodity commodity : storage.getCommodities()) {
747             final CommodityInfo info = commodity.getInfo();
748             if (!info.isDeleted()) {
749 
750                 // for Commodity (a link between Product and Category) we are testing:
751                 // 1) commodity identifiers are equal
752                 // 2) category identifiers for both commodities are equal (or both are null)
753                 // 3) product identifiers for both producs are equal (or both are null)
754 
755                 final SyncCommodity commodityByIdentifier = getCommodityByIdentifier(info.getIdentifier());
756                 if (commodityByIdentifier == null) {
757                     return false;
758                 }
759 
760                 final CommodityInfo localInfo = commodityByIdentifier.getInfo();
761 
762                 if (info.getCategory() != null && localInfo.getCategory() != null) {
763                     if (!info.getCategory().equals(localInfo.getCategory())) {
764                         return false;
765                     }
766                 } else if (info.getCategory() != null || localInfo.getCategory() != null) {
767                     // e.g. one of them is non-null => they are not equal
768                     return false;
769                 }
770 
771                 if (info.getProduct() != null && localInfo.getProduct() != null) {
772                     if (!info.getProduct().equals(localInfo.getProduct())) {
773                         return false;
774                     }
775                 } else if (info.getProduct() != null || localInfo.getProduct() != null) {
776                     return false;
777                 } else if (info.isDeleted() && localInfo.isDeleted() || !info.isDeleted() && localInfo.isDeleted()) {
778                     return false;
779                 }
780             }
781         }
782 
783         for (final SyncCategory cat : storage.getCategories()) {
784             final CategoryInfo info = cat.getInfo();
785             if (!info.isDeleted() && getCategoryByIdentifier(info.getIdentifier()) == null) {
786                 return false;
787             }
788         }
789 
790         for (final SyncTax tax : storage.getTaxes()) {
791             final TaxInfo info = tax.getInfo();
792             if (!info.isDeleted() && getTaxByIdentifier(info.getIdentifier()) == null) {
793                 return false;
794             }
795         }
796 
797         for (final SyncProduct product : storage.getProducts()) {
798             final ProductInfo info = product.getInfo();
799             if (!info.isDeleted()) {
800 
801                 // for Product (which has a link with Tax) we are testing:
802                 // 1) product identifiers are equal
803                 // 2) tax identifiers for both products are equal
804                 //    (in the future we can even test that tax vat value for both product are equal)
805 
806                 final SyncProduct productByIdentifier = getProductByIdentifier(info.getIdentifier());
807 
808                 if (productByIdentifier == null) {
809                     return false;
810                 }
811 
812                 final ProductInfo localInfo = productByIdentifier.getInfo();
813 
814                 if (info.getTax() != null && localInfo.getTax() != null) {
815                     if (!info.getTax().equals(localInfo.getTax())) {
816                         return false;
817                     } else {
818                         final SyncTax syncTax = storage.getTaxByIdentifier(info.getTax());
819                         final SyncTax localSyncTax = getTaxByIdentifier(localInfo.getTax());
820 
821                         if (syncTax == null || localSyncTax == null) {
822                             return false;
823                         }
824                         if (syncTax.getInfo().getVat() != localSyncTax.getInfo().getVat()) {
825                             return false;
826                         }
827                         if (syncTax.getInfo().isDeleted() && !localSyncTax.getInfo().isDeleted() ||
828                                 !syncTax.getInfo().isDeleted() && localSyncTax.getInfo().isDeleted()) {
829                             return false;
830                         }
831                     }
832                 } else if (info.getTax() != null || localInfo.getTax() != null) {
833                     // e.g. one of them is non-null => they are not equal
834                     return false;
835                 }
836             }
837         }
838 
839         for (final SyncTreasurer treasurer : storage.getTreasurers()) {
840             final TreasurerInfo info = treasurer.getInfo();
841             if (!info.isDeleted() && getTreasurerByIdentifier(info.getIdentifier()) == null) {
842                 return false;
843             }
844         }
845 
846         for (final SyncOrder order : storage.getOrders()) {
847             final OrderInfo info = order.getInfo();
848             if (!info.isDeleted() && getOrderByIdentifier(info.getIdentifier()) == null) {
849                 return false;
850             }
851         }
852 
853         if (storage.getSeller() != null && getSeller() != null) {
854             if (storage.isSellerSynced() != isSellerSynced() || !storage.getSeller().getCorporateId().equals(getSeller().getCorporateId())) {
855                 return false;
856             }
857         }
858 
859         if (storage.getLocalVersion() != getLocalVersion()) {
860             return false;
861         }
862 
863         return true;
864     }
865 
866     /**
867      * <p>Simple compare of two memory storages.<br/>
868      * Compares just entity identifiers. Ignores deleted entities.</p>
869      *
870      * @param storage MemoryLocalStorage to compare with
871      * @return true if both storages are equal
872      */
873     public boolean isEqualTo(final MemoryLocalStorage storage) {
874         return isSupersetOf(storage) && storage.isSupersetOf(this);
875     }
876 }