package Ġcom . sy g ic . travel . sdk . synchron ization . services Ċ Ċ import Ġcom . sy g ic . travel . sdk . common . api . S yg ic Travel ApiClient Ċ import Ġcom . sy g ic . travel . sdk . favorites . api . model . Favorite Request Ċ import Ġcom . sy g ic . travel . sdk . favorites . model . Favorite Ċ import Ġcom . sy g ic . travel . sdk . favorites . service . Favorite Service Ċ import Ġcom . sy g ic . travel . sdk . synchron ization . model . Synchronization Result Ċ import Ġtim ber . log . Tim ber Ċ Ċ internal Ġclass ĠF avorites Synchronization Service Ġconstructor ( Ċ ĉ private Ġval ĠapiClient : ĠS yg ic Travel ApiClient , Ċ ĉ private Ġval Ġfavorite Service : ĠF avorite Service Ċ ) Ġ{ Ċ ĉ fun Ġsync ( added Favorite Ids : ĠList < String >, Ġdeleted Favorite Ids : ĠList < String >, Ġsync Result : ĠSynchron ization Result ) Ġ{ Ċĉ ĉ for Ġ( favorite Id Ġin Ġadded Favorite Ids ) Ġ{ Ċĉĉ ĉ favorite Service . add Place ( favorite Id ) Ċĉ ĉ } ĊĊĉ ĉ for Ġ( favorite Id Ġin Ġdeleted Favorite Ids ) Ġ{ Ċĉĉ ĉ favorite Service . hard Delete Place ( favorite Id ) Ċĉ ĉ } ĊĊĉ ĉ for Ġ( favorite Ġin Ġfavorite Service . getF avorites For Synchronization ()) Ġ{ Ċĉĉ ĉ if Ġ( favorite . id . startsWith ("* ")) Ġ{ Ċĉĉĉ ĉ Tim ber . e (" Favorite Ġ${ favorite . id } Ġcannot Ġbe Ġsynced Ġbecause Ġit Ġhas Ġplace Ġwith Ġlocal Ġid .") Ċĉĉĉ ĉ continue Ċĉĉ ĉ } Ċĉĉ ĉ if Ġ( favorite . state Ġ== ĠF avorite . STATE _ TO _ ADD ) Ġ{ Ċĉĉĉ ĉ val Ġcreate Response Ġ= ĠapiClient . create Favorite ( Favorite Request ( favorite . id )). execute () Ċĉĉĉ ĉ when Ġ{ Ċĉĉĉĉ ĉ create Response . is Successful Ġ-> Ġ{ Ċĉĉĉĉĉ ĉ favorite Service . mark As Synchron ized ( favorite ) Ċĉĉĉĉ ĉ } Ċĉĉĉĉ ĉ create Response . code () Ġin Ġ 4 0 0 .. 4 9 9 Ġ-> Ġ{ Ċĉĉĉĉĉ ĉ // Ġplace Ġid Ġdoes Ġnot Ġexist Ċĉĉĉĉĉ ĉ favorite Service . hard Delete Place ( favorite . id ) Ċĉĉĉĉ ĉ } Ċĉĉĉĉ ĉ else Ġ-> Ġ{ Ċĉĉĉĉĉ ĉ // Ġtry Ġdeleting Ġnext Ġtime Ċĉĉĉĉ ĉ } Ċĉĉĉ ĉ } ĊĊĉĉ ĉ } Ġelse Ġif Ġ( favorite . state Ġ== ĠF avorite . STATE _ TO _ REMOVE ) Ġ{ Ċĉĉĉ ĉ val Ġdelete Response Ġ= ĠapiClient . delete Favorite ( Favorite Request ( favorite . id )). execute () Ċĉĉĉ ĉ if Ġ( delete Response . is Successful Ġ|| Ġdelete Response . code () Ġin Ġ 4 0 0 .. 4 9 9 ) Ġ{ Ċĉĉĉĉ ĉ favorite Service . hard Delete Place ( favorite . id ) Ċĉĉĉ ĉ } Ġelse Ġ{ Ċĉĉĉĉ ĉ // Ġtry Ġdeleting Ġnext Ġtime Ċĉĉĉ ĉ } Ċĉĉ ĉ } Ċĉ ĉ } ĊĊĉ ĉ sync Result . changed Favorite Ids . addAll ( added Favorite Ids . union ( deleted Favorite Ids )) Ċ ĉ } Ċ } Ċ