Back to project page NFCAndroid.
The source code is released under:
Copyright (c) 2012, Wireless Sensor Technologies, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following ...
If you think the Android project NFCAndroid listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.gototags.nfc.records; //from w w w . j a v a 2 s .c o m import java.util.Locale; import com.google.common.base.Preconditions; import com.gototags.nfc.ndef.TextNdefRecord; import android.nfc.NdefRecord; public class TextRecord extends Record { private Locale locale; private String text; public TextRecord() { } public TextRecord(Locale locale, String text) { this.setLocale(locale); this.setText(text); } public Locale getLocale() { return this.locale; } public void setLocale(Locale locale) { this.locale = locale; } public String getText() { return text; } public void setText(String text) { this.text = text; } @Override public void Validate() { Preconditions.checkNotNull(this.getLocale(), "The locale must not be null."); Preconditions.checkNotNull(this.getLocale().getLanguage(), "The locale's language must not be null."); Preconditions.checkNotNull(this.getText(), "The text must not be null."); } @Override public boolean equals(Object obj) { if (this == obj) return true; else if (!(this instanceof TextRecord)) return false; else { TextRecord textRecord = (TextRecord)obj; return (this.getText() == null && textRecord.getText() == null) || (this.getText().equals(textRecord.getText())); } } @Override public int hashCode() { if (this.getText() == null) return 0; else return this.getText().hashCode(); } @Override public String toString() { return this.getText(); } @Override protected NdefRecord toNdefRecord() { try { TextNdefRecord textNdefRecord = new TextNdefRecord(this.getLocale(), this.getText()); return textNdefRecord.toNdefRecord(); } catch (Exception exception) { throw new IllegalArgumentException(exception); } } public static TextRecord fromNdefRecord(NdefRecord ndefRecord) { Preconditions.checkNotNull(ndefRecord); try { TextNdefRecord textNdefRecord = TextNdefRecord.fromNdefRecord(ndefRecord); TextRecord textRecord = new TextRecord(textNdefRecord.getLocale(), textNdefRecord.getText()); return textRecord; } catch (Exception exception) { throw new IllegalArgumentException(exception); } } public static boolean isTextRecord(NdefRecord ndefRecord) { try { TextRecord.fromNdefRecord(ndefRecord); return true; } catch (IllegalArgumentException illegalArgumentException) { return false; } } }