Skip to content

Commit

Permalink
Created a common project for utilities and also created a Teiid proje…
Browse files Browse the repository at this point in the history
…ct for Teiid-related model objects, validators, etc.
  • Loading branch information
elvisisking committed Jan 6, 2013
1 parent b50e5ba commit b4f396f
Show file tree
Hide file tree
Showing 47 changed files with 3,785 additions and 82 deletions.
36 changes: 36 additions & 0 deletions komodo-common/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
23 changes: 23 additions & 0 deletions komodo-common/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>komodo-common</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
</projectDescription>
13 changes: 13 additions & 0 deletions komodo-common/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.komodo</groupId>
<artifactId>komodo-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>

<artifactId>komodo-common</artifactId>
<packaging>jar</packaging>
<name>Komodo Common</name>
<description>Komodo common utilities module</description>
</project>
110 changes: 110 additions & 0 deletions komodo-common/src/main/java/org/komodo/common/util/CollectionUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/*
* JBoss, Home of Professional Open Source.
*
* See the LEGAL.txt file distributed with this work for information regarding copyright ownership and licensing.
*
* See the AUTHORS.txt file distributed with this work for a full listing of individual contributors.
*/
package org.komodo.common.util;

import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

/**
* Utilities for use with collections.
*/
public class CollectionUtil {

/**
* @param collection the collection being checked (can be <code>null</code> or empty)
* @return <code>true</code> if <code>null</code> or empty
*/
public static boolean isEmpty(final Collection<?> collection) {
return ((collection == null) || collection.isEmpty());
}

/**
* The order of the elements in the list does not matter.
*
* @param thisList one of the lists being compared (can be <code>null</code>)
* @param thatList the other list being compared (can be <code>null</code>)
* @return <code>true</code> if the lists are both <code>null</code>, both empty, or contain all the same entries
*/
public static boolean matches(final List<?> thisList,
final List<?> thatList) {
if (thisList == null) {
return (thatList == null);
}

if (thatList == null) {
return false;
}

if (thisList.size() != thatList.size()) {
return false;
}

for (final Object element : thisList) {
if (!thatList.contains(element)) {
return false;
}
}

return true;
}

/**
* @param thisMap one of the maps being compared (can be <code>null</code>)
* @param thatMap the other map being compared (can be <code>null</code>)
* @return <code>true</code> if the maps are both <code>null</code>, both empty, or contain all the same entries
*/
public static boolean matches(final Map<?, ?> thisMap,
final Map<?, ?> thatMap) {
if (thisMap == null) {
return (thatMap == null);
}

if (thatMap == null) {
return false;
}

if (thisMap.size() != thatMap.size()) {
return false;
}

for (final Entry<?, ?> entry : thisMap.entrySet()) {
final Object key = entry.getKey();

if (!thatMap.containsKey(key)) {
return false;
}

final Object value = entry.getValue();
final Object otherValue = thatMap.get(key);

if (value == null) {
if (otherValue != null) {
return false;
}
} else if (otherValue == null) {
return false;
}

if (!value.equals(otherValue)) {
return false;
}
}

return true;
}

/**
* Don't allow construction.
*/
private CollectionUtil() {
// nothing to do
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*
* See the AUTHORS.txt file distributed with this work for a full listing of individual contributors.
*/
package org.teiid.komodo.repository.util;
package org.komodo.common.util;

import java.io.BufferedReader;
import java.io.File;
Expand Down
82 changes: 82 additions & 0 deletions komodo-common/src/main/java/org/komodo/common/util/HashCode.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
* JBoss, Home of Professional Open Source.
*
* See the LEGAL.txt file distributed with this work for information regarding copyright ownership and licensing.
*
* See the AUTHORS.txt file distributed with this work for a full listing of individual contributors.
*/
package org.komodo.common.util;

import java.util.Arrays;

/**
* Utilities for use in calculating hashCodes.
*/
public class HashCode {

// Prime number used in improving distribution
private static final int PRIME = 103;

/**
* Compute a combined hash code from the supplied objects using the supplied seed.
*
* @param seed a value upon which the hash code will be based; may be 0
* @param objects the objects that should be used to compute the hash code
* @return the hash code
*/
private static int _compute(final int seed,
final Object... objects) {
if ((objects == null) || (objects.length == 0)) {
return seed * HashCode.PRIME;
}

// Compute the hash code for all of the objects ...
int hc = seed;

for (final Object object : objects) {
hc = HashCode.PRIME * hc;

if (object instanceof byte[]) {
hc += Arrays.hashCode((byte[])object);
} else if (object instanceof boolean[]) {
hc += Arrays.hashCode((boolean[])object);
} else if (object instanceof short[]) {
hc += Arrays.hashCode((short[])object);
} else if (object instanceof int[]) {
hc += Arrays.hashCode((int[])object);
} else if (object instanceof long[]) {
hc += Arrays.hashCode((long[])object);
} else if (object instanceof float[]) {
hc += Arrays.hashCode((float[])object);
} else if (object instanceof double[]) {
hc += Arrays.hashCode((double[])object);
} else if (object instanceof char[]) {
hc += Arrays.hashCode((char[])object);
} else if (object instanceof Object[]) {
hc += Arrays.hashCode((Object[])object);
} else if (object != null) {
hc += object.hashCode();
}
}

return hc;
}

/**
* Compute a combined hash code from the supplied objects. This method always returns 0 if no objects are supplied.
*
* @param objects the objects that should be used to compute the hash code
* @return the hash code
*/
public static int compute(final Object... objects) {
return _compute(0, objects);
}

/**
* Don't allow public construction.
*/
private HashCode() {
// nothing to do
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*
* See the AUTHORS.txt file distributed with this work for a full listing of individual contributors.
*/
package org.teiid.komodo.repository.util;
package org.komodo.common.util;

import java.text.MessageFormat;

Expand Down
54 changes: 54 additions & 0 deletions komodo-common/src/main/java/org/komodo/common/util/StringUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* JBoss, Home of Professional Open Source.
*
* See the LEGAL.txt file distributed with this work for information regarding copyright ownership and licensing.
*
* See the AUTHORS.txt file distributed with this work for a full listing of individual contributors.
*/
package org.komodo.common.util;

/**
* Utilities for use with string types.
*/
public class StringUtil {

/**
* A empty string constant.
*/
public static final String EMPTY_STRING = ""; //$NON-NLS-1$

/**
* A empty string array constant.
*/
public static final String[] EMPTY_STRING_ARRAY = {};

/**
* @param text the string being checked (can be <code>null</code> or empty)
* @return <code>true</code> if <code>null</code> or empty
*/
public static boolean isEmpty(final String text) {
return ((text == null) || text.isEmpty());
}

/**
* @param thisString one of the strings being checked (can be <code>null</code> or empty)
* @param thatString the other string being checked (can be <code>null</code> or empty)
* @return <code>true</code> if both strings are <code>null</code> or equals
*/
public static boolean matches(final String thisString,
final String thatString) {
if (thisString == null) {
return (thatString == null);
}

return thisString.equals(thatString);
}

/**
* Don't allow public construction.
*/
private StringUtil() {
// nothing to do
}

}

0 comments on commit b4f396f

Please sign in to comment.