Mercurial Hosting > junotu
changeset 64:e8d83f1a6100
Moved card identifier list parsing to newly created TagUtility class
author | Fox |
---|---|
date | Fri, 23 Dec 2022 21:33:05 +0100 |
parents | 1304d3d5b4a4 |
children | 4dd7d78e19a1 |
files | src/junotu/TabBoard.java src/junotu/TagUtility.java |
diffstat | 2 files changed, 58 insertions(+), 56 deletions(-) [+] |
line wrap: on
line diff
--- a/src/junotu/TabBoard.java Fri Dec 23 20:43:31 2022 +0100 +++ b/src/junotu/TabBoard.java Fri Dec 23 21:33:05 2022 +0100 @@ -200,25 +200,17 @@ titleSet(card.titleGet()); String cardsString = card.<String>tagGetAsOr( Card.TAG_BOARD_COLUMN_CARDS, "" ); - String cardsSplit[] = cardsString.split(" "); - System.out.print("Loading cards string: "+cardsString+"\n"); + Card[] cardsSplit = TagUtility.parseCardList(cardsString); for( int i = 0; i < cardsSplit.length; i++ ) { - try { - long identifier = Long.parseLong(cardsSplit[i]); - Card childCard = Main.database.cardGetByIdentifier(identifier); - - if( childCard == null ){ - System.out.print("Column '"+card.titleGet()+"', identifier "+Long.toString(card.identifierGet())+": Failed to load card by identifier "+Long.toString(identifier)+"\n"); - } - insertCard( childCard, -1 ); - } catch( NumberFormatException e ) { - System.out.print("Column '"+card.titleGet()+"', identifier "+Long.toString(card.identifierGet())+": Failed to convert card identifier '"+cardsSplit[i]+"' to long, aborting cards loading. Full cards tag: '"+cardsString+"'\n"); + if( cardsSplit[i] == null ) { + System.out.print("Column '"+card.titleGet()+"', identifier "+Long.toString(card.identifierGet())+": Failed to retrieve card identifier by index "+Integer.toString(i)+", aborting cards loading. Full cards tag: '"+cardsString+"'\n"); break; - } catch( Exception e ) { - throw new RuntimeException(e); } + + insertCard( cardsSplit[i], -1 ); + } } @@ -521,22 +513,14 @@ Card card; - try { - card = Main.database.cardGetByIdentifier(identifier); - } catch( Exception e ) { - throw new RuntimeException(e); - } + card = Main.database.cardGetByIdentifier(identifier); if( card == null ) { throw new RuntimeException(); } if( card.<String>tagGetAsOr( Card.TAG_BOARD_COLUMN_CARD, "" ).equals(Card.VALUE_BOARD_COLUMN_CARD_ONLY) ) { - try { - Main.database.cardDelete(card.identifierGet()); - } catch( Exception e ) { - throw new RuntimeException(e); - } + Main.database.cardDelete(card.identifierGet()); } } @@ -605,26 +589,17 @@ } String columnsString = card.<String>tagGetAsOr(Card.TAG_BOARD_COLUMNS, ""); - String[] columnsSplit = columnsString.split(" "); + Card[] columnCards = TagUtility.parseCardList(columnsString); - for( int i = 0; i < columnsSplit.length; i++ ) { - try { - long identifier = Long.parseLong(columnsSplit[i]); - Card columnCard = Main.database.cardGetByIdentifier(identifier); - - if( columnCard == null ){ - System.out.print("Board '"+card.titleGet()+"': Failed to load column by identifier "+Long.toString(identifier)+"\n"); - } - - ColumnWidget column = new ColumnWidget(this, columnCard); - insertColumnRaw(column); - - } catch( NumberFormatException e ) { - System.out.print("Board '"+card.titleGet()+"': Failed to convert column identifier '"+columnsSplit[i]+"' to long, aborting column loading. Full columns tag: '"+columnsString+"'\n"); + for( int i = 0; i < columnCards.length; i++ ) { + + if( columnCards[i] == null ) { + System.out.print("Board '"+card.titleGet()+"': Failed to get card for column identifier index "+Integer.toString(i)+", aborting column loading. Full columns tag: '"+columnsString+"'\n"); break; - } catch( Exception e ) { - throw new RuntimeException(e); } + + ColumnWidget column = new ColumnWidget(this, columnCards[i]); + insertColumnRaw(column); } } @@ -644,23 +619,19 @@ } Card card; - - try { - card = Main.database.cardGetByIdentifier(identifier); - - if( card == null ) { - throw new RuntimeException(); - } - - card.titleSet( title.getText() ); - card.tagValueSetOnly( Card.TAG_BOARD, null ); - card.tagValueSetOnly( Card.TAG_BOARD_COLUMNS, columnIdentifiers ); - - Main.database.cardUpdate(card); - } catch( Exception e ) { - throw new RuntimeException(e); + + card = Main.database.cardGetByIdentifier(identifier); + + if( card == null ) { + throw new RuntimeException(); } + card.titleSet( title.getText() ); + card.tagValueSetOnly( Card.TAG_BOARD, null ); + card.tagValueSetOnly( Card.TAG_BOARD_COLUMNS, columnIdentifiers ); + + Main.database.cardUpdate(card); + return card; }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/junotu/TagUtility.java Fri Dec 23 21:33:05 2022 +0100 @@ -0,0 +1,31 @@ +package junotu; + +import java.lang.Long; + +import junotu.Main; +import junotu.Card; + +public class TagUtility { + + public static Card[] parseCardList( String value ) + { + if( value.length() == 0 ) { + return new Card[0]; + } + /* This split on an empty string will actually return an array of length 1. */ + String[] identifierStrings = value.split(" "); + Card[] cards = new Card[identifierStrings.length]; + for( int i = 0; i < identifierStrings.length; i++ ) { + long identifier; + try { + identifier = Long.parseLong(identifierStrings[i]); + } catch( NumberFormatException e ) { + cards[i] = null; + continue; + } + cards[i] = Main.database.cardGetByIdentifier(identifier); + } + return cards; + } + +}