Assert class is now officialy OUT of the "utils" package. From now on we should use java's keyword "assert".

cusax-fix
Alexander Pelov 20 years ago
parent f7d999dc4a
commit 36793b9458

@ -11,7 +11,6 @@
import net.java.sip.communicator.service.configuration.ConfigurationService;
import net.java.sip.communicator.service.fileaccess.FileAccessService;
import net.java.sip.communicator.util.Assert;
import net.java.sip.communicator.util.Logger;
/**
@ -114,7 +113,7 @@ public File getTemporaryDirectory() throws IOException {
* Thrown if the configuration service is not set
*/
public File getPrivatePersistentFile(String fileName) throws Exception {
Assert.assertNonNull(fileName, "Parameter fileName should be non-null");
// TODO: Validate: Assert.assertNonNull(fileName, "Parameter fileName should be non-null");
File file = null;
@ -140,7 +139,7 @@ public File getPrivatePersistentFile(String fileName) throws Exception {
public File getPrivatePersistentDirectory(String dirName)
throws Exception
{
Assert.assertNonNull(dirName, "Parameter dirName should be non-null");
// TODO: Validate: Assert.assertNonNull(dirName, "Parameter dirName should be non-null");
String fullPath = getFullPath(dirName);
File dir = new File(fullPath, dirName);
@ -161,8 +160,8 @@ public File getPrivatePersistentDirectory(String dirName)
}
public File getPrivatePersistentDirectory(String[] dirNames) throws Exception {
Assert.assertNonNull(dirNames, "Parameter dirNames should be non-null");
Assert.assertTrue(dirNames.length > 0, "dirNames.length should be > 0");
// TODO: Validate: Assert.assertNonNull(dirNames, "Parameter dirNames should be non-null");
// TODO: Validate: Assert.assertTrue(dirNames.length > 0, "dirNames.length should be > 0");
StringBuffer dirName = new StringBuffer();
for(int i = 0; i < dirNames.length; i++) {
@ -176,15 +175,15 @@ public File getPrivatePersistentDirectory(String[] dirNames) throws Exception {
}
private String getFullPath(String fileName) {
Assert.assertNonNull(fileName, "The filename should be non-null.");
// TODO: Validate: Assert.assertNonNull(fileName, "The filename should be non-null.");
String userhome = null;
String sipSubdir = null;
// Obtain configuration service lock
synchronized(this.syncRoot) {
Assert.assertNonNull(this.configurationService,
"The configurationService should be non-null.");
// TODO: Assert: Assert.assertNonNull(this.configurationService,
// "The configurationService should be non-null.");
userhome = this.configurationService.getString(FileAccessService.CONFPROPERTYKEY_USER_HOME);
sipSubdir = this.configurationService.getString(FileAccessService.CONFPROPERTYKEY_SIP_DIRECTORY);

@ -20,7 +20,6 @@
import net.java.sip.communicator.service.history.HistoryReader;
import net.java.sip.communicator.service.history.HistoryWriter;
import net.java.sip.communicator.service.history.records.HistoryRecordStructure;
import net.java.sip.communicator.util.Assert;
import net.java.sip.communicator.util.Logger;
import net.java.sip.communicator.util.xml.XMLUtils;
@ -52,9 +51,9 @@ protected HistoryImpl(
try {
log.logEntry();
Assert.assertNonNull(historyServiceImpl, "The historyServiceImpl should be non-null.");
Assert.assertNonNull(id, "The ID should be non-null.");
Assert.assertNonNull(historyRecordStructure, "The structure should be non-null.");
// TODO: Assert: Assert.assertNonNull(historyServiceImpl, "The historyServiceImpl should be non-null.");
// TODO: Assert: Assert.assertNonNull(id, "The ID should be non-null.");
// TODO: Assert: Assert.assertNonNull(historyRecordStructure, "The structure should be non-null.");
this.id = id;
this.directory = directory;
@ -102,7 +101,7 @@ private void reloadDocumentList() {
this.historyDocuments.clear();
File[] files = this.directory.listFiles();
Assert.assertNonNull(files, "The list of files should be non-null.");
// TODO: Assert: Assert.assertNonNull(files, "The list of files should be non-null.");
for(int i = 0; i < files.length; i++) {
if(!files[i].isDirectory()) {
@ -186,8 +185,8 @@ protected Document getDocumentForFile(String filename)
// Cache the loaded document for reuse
this.historyDocuments.put(filename, retVal);
} else {
Assert.fail("Internal error - the data type " +
"should be either Document or File.");
// TODO: Assert: Assert.fail("Internal error - the data type " +
// "should be either Document or File.");
}
}

@ -19,7 +19,6 @@
import net.java.sip.communicator.service.history.HistoryWriter;
import net.java.sip.communicator.service.history.records.HistoryRecord;
import net.java.sip.communicator.service.history.records.HistoryRecordStructure;
import net.java.sip.communicator.util.Assert;
/**
* @author Alexander Pelov
@ -125,8 +124,8 @@ private void createNewDoc(Date date, boolean loadLastFile) {
this.currentDoc = this.historyImpl.createDocument(this.currentFile);
}
Assert.assertNonNull(this.currentDoc,
"There should be a current document created.");
// TODO: Assert: Assert.assertNonNull(this.currentDoc,
// "There should be a current document created.");
this.currentDocElements = this.currentDoc.getFirstChild().getChildNodes().getLength();
}

@ -6,8 +6,6 @@
*/
package net.java.sip.communicator.service.history;
import net.java.sip.communicator.util.Assert;
/**
* Object used to uniquely identify a group of history records.
*
@ -39,8 +37,8 @@ private HistoryID(String[] id) {
* strings and they will be safely converted to valid IDs.
*/
public static HistoryID createFromRawID(String[] rawid) {
Assert.assertNonNull(rawid, "Parameter RAWID should be non-null");
Assert.assertTrue(rawid.length > 0, "RAWID.length should be > 0");
// TODO: Validate: Assert.assertNonNull(rawid, "Parameter RAWID should be non-null");
// TODO: Validate: Assert.assertTrue(rawid.length > 0, "RAWID.length should be > 0");
String[] id = new String[rawid.length];
for(int i = 0; i < rawid.length; i++) {
@ -60,8 +58,8 @@ public static HistoryID createFromRawID(String[] rawid) {
public static HistoryID createFromID(String[] id)
throws IllegalArgumentException
{
Assert.assertNonNull(id, "Parameter ID should be non-null");
Assert.assertTrue(id.length > 0, "ID.length should be > 0");
// TODO: Validate: Assert.assertNonNull(id, "Parameter ID should be non-null");
// TODO: Validate: Assert.assertTrue(id.length > 0, "ID.length should be > 0");
for(int i = 0; i < id.length; i++) {
if(!HistoryID.isIDValid(id[i])) {

@ -8,8 +8,6 @@
import java.util.Date;
import net.java.sip.communicator.util.Assert;
/**
* @author Alexander Pelov
*/
@ -63,12 +61,12 @@ public HistoryRecord(HistoryRecordStructure entryStructure, String[] propertyVal
* @param timestamp
*/
public HistoryRecord(String[] propertyNames, String[] propertyValues, Date timestamp) {
Assert.assertNonNull(propertyNames, "The property names should be non-null.");
Assert.assertNonNull(propertyValues, "The property values should be non-null.");
Assert.assertNonNull(timestamp, "The timestamp should be non-null.");
// TODO: Validate: Assert.assertNonNull(propertyNames, "The property names should be non-null.");
// TODO: Validate: Assert.assertNonNull(propertyValues, "The property values should be non-null.");
// TODO: Validate: Assert.assertNonNull(timestamp, "The timestamp should be non-null.");
Assert.assertTrue(propertyNames.length == propertyValues.length,
"The length of the property names and property values should be equal.");
// TODO: Validate Assert.assertTrue(propertyNames.length == propertyValues.length,
// "The length of the property names and property values should be equal.");
this.propertyNames = propertyNames;
this.propertyValues = propertyValues;

@ -6,8 +6,6 @@
*/
package net.java.sip.communicator.service.history.records;
import net.java.sip.communicator.util.Assert;
/**
* @author Alexander Pelov
*/
@ -25,7 +23,8 @@ public class HistoryRecordStructure {
* @param propertyNames
*/
public HistoryRecordStructure(String[] propertyNames) {
Assert.assertNonNull(propertyNames, "Parameter propertyNames should be non-null.");
// TODO: Validate: Assert.assertNonNull(propertyNames, "Parameter propertyNames should be non-null.");
this.propertyNames = new String[propertyNames.length];
System.arraycopy(propertyNames, 0, this.propertyNames, 0, this.propertyNames.length);
}

@ -1,80 +0,0 @@
/*
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/package net.java.sip.communicator.util;
/**
* @author Alexander Pelov
*/
public class Assert {
/**
* The logger for this class.
*/
private static final Logger log = Logger.getLogger(Assert.class.getName());
/**
* Enables or disables assertion checks.
*/
public static boolean EnableAssertions = true;
/**
* Throws an exception if the passed condition is false and
* <code>EnableAssertions == true</code>.
*
* @param condition The condition to be met.
* @param message The message to be displayed as explanation on assertion fail.
* @throws IllegalArgumentException Thrown if condition is false and
* assertions are enabled.
*/
public static final void assertTrue(boolean condition, String message) throws AssertionError {
if (EnableAssertions && !condition) {
StackTraceElement caller = new Throwable().getStackTrace()[1];
String fullText = "Assertion failed at " + caller.getMethodName() + ", line " +
caller.getLineNumber() +
"\n\tMessage: " + message;
log.error(fullText);
throw new AssertionError(fullText);
}
}
/**
* Throws an exception if <code>EnableAssertions == true</code>.
*
* @param message The message to be displayed as explanation on assertion fail.
* @throws IllegalArgumentException Thrown if assertions are enabled.
*/
public static final void fail(String message) throws AssertionError {
Assert.assertTrue(false, message);
}
/**
* Throws an exception if the passed object is null and
* <code>EnableAssertions == true</code>.
*
* @param obj The object to be checked.
* @param message The message to be displayed as explanation on assertion fail.
* @throws IllegalArgumentException Thrown if obj is null
* and assertions are enabled.
*/
public static final void assertNonNull(Object obj, String message) throws AssertionError {
Assert.assertTrue(obj != null, message);
}
/**
* Throws an exception if the passed object is not null and
* <code>EnableAssertions == true</code>.
*
* @param obj The object to be checked.
* @param message The message to be displayed as explanation on assertion fail.
* @throws IllegalArgumentException Thrown if obj is not null and
* assertions are enabled.
*/
public static final void assertNull(Object obj, String message) throws AssertionError {
Assert.assertTrue(obj == null, message);
}
}
Loading…
Cancel
Save