Skip to content

Commit

Permalink
Merge branch 'master' into r
Browse files Browse the repository at this point in the history
  • Loading branch information
Yegor Bugayenko committed Sep 27, 2013
2 parents 0e479b1 + 976c8d9 commit 5450d4a
Show file tree
Hide file tree
Showing 4 changed files with 137 additions and 126 deletions.
15 changes: 13 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.jcabi</groupId>
<artifactId>jcabi</artifactId>
<version>0.7.22</version>
<artifactId>parent</artifactId>
<version>0.9</version>
</parent>
<artifactId>jcabi-aspects</artifactId>
<version>0.11</version>
Expand All @@ -53,6 +53,17 @@
<developerConnection>scm:git:github.com:jcabi/jcabi-aspects.git</developerConnection>
<url>https://github.com/jcabi/jcabi-aspects</url>
</scm>
<distributionManagement>
<site>
<!--
Deploying the site to Amazon S3. "jcabi.s3" server details
are defined in "settings.xml" file, provided by continuous integration
server during build cycle.
-->
<id>www.jcabi.com</id>
<url>s3://www.jcabi.com/jcabi-aspects</url>
</site>
</distributionManagement>
<dependencies>
<dependency>
<groupId>com.jcabi</groupId>
Expand Down
126 changes: 63 additions & 63 deletions src/main/java/com/jcabi/aspects/aj/MethodLogger.java
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,69 @@ private static boolean enabled(final int level, final Class<?> log) {
return enabled;
}

/**
* Checks whether array of types contains given type.
* @param array Array of them
* @param exp The exception to find
* @return TRUE if it's there
*/
private static boolean contains(final Class<? extends Throwable>[] array,
final Throwable exp) {
boolean contains = false;
for (Class<? extends Throwable> type : array) {
if (MethodLogger.instanceOf(exp.getClass(), type)) {
contains = true;
break;
}
}
return contains;
}

/**
* The type is an instance of another type?
* @param child The child type
* @param parent Parent type
* @return TRUE if child is really a child of a parent
*/
private static boolean instanceOf(final Class<?> child,
final Class<?> parent) {
boolean instance = child.equals(parent)
|| (child.getSuperclass() != null
&& MethodLogger.instanceOf(child.getSuperclass(), parent));
if (!instance) {
for (Class<?> iface : child.getInterfaces()) {
instance = MethodLogger.instanceOf(iface, parent);
if (instance) {
break;
}
}
}
return instance;
}

/**
* Textualize a stacktrace.
* @param trace Array of stacktrace elements
* @return The text
*/
private static String textualize(final StackTraceElement[] trace) {
final StringBuilder text = new StringBuilder();
for (int pos = 0; pos < trace.length; ++pos) {
if (text.length() > 0) {
text.append(", ");
}
text.append(
String.format(
"%s#%s[%d]",
trace[pos].getClassName(),
trace[pos].getMethodName(),
trace[pos].getLineNumber()
)
);
}
return text.toString();
}

/**
* Marker of a running method.
*/
Expand Down Expand Up @@ -405,67 +468,4 @@ public int compareTo(final Marker marker) {
}
}

/**
* Checks whether array of types contains given type.
* @param array Array of them
* @param exp The exception to find
* @return TRUE if it's there
*/
private static boolean contains(final Class<? extends Throwable>[] array,
final Throwable exp) {
boolean contains = false;
for (Class<? extends Throwable> type : array) {
if (MethodLogger.instanceOf(exp.getClass(), type)) {
contains = true;
break;
}
}
return contains;
}

/**
* The type is an instance of another type?
* @param child The child type
* @param parent Parent type
* @return TRUE if child is really a child of a parent
*/
private static boolean instanceOf(final Class<?> child,
final Class<?> parent) {
boolean instance = child.equals(parent)
|| (child.getSuperclass() != null
&& MethodLogger.instanceOf(child.getSuperclass(), parent));
if (!instance) {
for (Class<?> iface : child.getInterfaces()) {
instance = MethodLogger.instanceOf(iface, parent);
if (instance) {
break;
}
}
}
return instance;
}

/**
* Textualize a stacktrace.
* @param trace Array of stacktrace elements
* @return The text
*/
private static String textualize(final StackTraceElement[] trace) {
final StringBuilder text = new StringBuilder();
for (int pos = 0; pos < trace.length; ++pos) {
if (text.length() > 0) {
text.append(", ");
}
text.append(
String.format(
"%s#%s[%d]",
trace[pos].getClassName(),
trace[pos].getMethodName(),
trace[pos].getLineNumber()
)
);
}
return text.toString();
}

}
40 changes: 20 additions & 20 deletions src/main/java/com/jcabi/immutable/ArrayMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,26 +63,6 @@
@SuppressWarnings({ "rawtypes", "unchecked", "PMD.TooManyMethods" })
public final class ArrayMap<K, V> implements ConcurrentMap<K, V> {

/**
* Comparator.
*/
private static final class Cmp<K, V> implements
Comparator<ArrayMap.ImmutableEntry<K, V>> {
@Override
public int compare(final ImmutableEntry<K, V> left,
final ImmutableEntry<K, V> right) {
int compare;
if (left.getKey() instanceof Comparable) {
compare = Comparable.class.cast(left.getKey())
.compareTo(right.getKey());
} else {
compare = left.getKey().toString()
.compareTo(right.getKey().toString());
}
return compare;
}
}

/**
* All entries.
*/
Expand Down Expand Up @@ -375,6 +355,26 @@ public Set<Map.Entry<K, V>> entrySet() {
);
}

/**
* Comparator.
*/
private static final class Cmp<K, V> implements
Comparator<ArrayMap.ImmutableEntry<K, V>> {
@Override
public int compare(final ImmutableEntry<K, V> left,
final ImmutableEntry<K, V> right) {
int compare;
if (left.getKey() instanceof Comparable) {
compare = Comparable.class.cast(left.getKey())
.compareTo(right.getKey());
} else {
compare = left.getKey().toString()
.compareTo(right.getKey().toString());
}
return compare;
}
}

/**
* Immutable map entry.
*/
Expand Down
82 changes: 41 additions & 41 deletions src/main/java/com/jcabi/immutable/ArraySortedSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,47 +57,6 @@
@SuppressWarnings({ "unchecked", "PMD.TooManyMethods" })
public final class ArraySortedSet<T> implements SortedSet<T> {

/**
* Comparator.
* @param <T> Type of argument
*/
@Immutable
public interface Comparator<T> extends java.util.Comparator<T> {
/**
* Default comparator.
* @param <T> Type of argument
*/
@Immutable
final class Default<T> implements ArraySortedSet.Comparator<T> {
@Override
public int compare(final T left, final T right) {
return Comparable.class.cast(left).compareTo(right);
}
};
/**
* Neutral comparator (never compares).
* @param <T> Type of argument
*/
@Immutable
final class Neutral<T> implements ArraySortedSet.Comparator<T> {
@Override
public int compare(final T left, final T right) {
return 1;
}
};
/**
* Reverse comparator.
* @param <T> Type of argument
*/
@Immutable
final class Reverse<T> implements ArraySortedSet.Comparator<T> {
@Override
public int compare(final T left, final T right) {
return Comparable.class.cast(right).compareTo(left);
}
};
};

/**
* All values.
*/
Expand Down Expand Up @@ -389,4 +348,45 @@ public void clear() {
throw new UnsupportedOperationException();
}

/**
* Comparator.
* @param <T> Type of argument
*/
@Immutable
public interface Comparator<T> extends java.util.Comparator<T> {
/**
* Default comparator.
* @param <T> Type of argument
*/
@Immutable
final class Default<T> implements ArraySortedSet.Comparator<T> {
@Override
public int compare(final T left, final T right) {
return Comparable.class.cast(left).compareTo(right);
}
};
/**
* Neutral comparator (never compares).
* @param <T> Type of argument
*/
@Immutable
final class Neutral<T> implements ArraySortedSet.Comparator<T> {
@Override
public int compare(final T left, final T right) {
return 1;
}
};
/**
* Reverse comparator.
* @param <T> Type of argument
*/
@Immutable
final class Reverse<T> implements ArraySortedSet.Comparator<T> {
@Override
public int compare(final T left, final T right) {
return Comparable.class.cast(right).compareTo(left);
}
};
};

}

0 comments on commit 5450d4a

Please sign in to comment.