hamcrest-core-1.1

16:36:19.679 INFO  jd.cli.Main - Decompiling hamcrest-core-1.1.jar
package org.hamcrest;

import java.util.Arrays;
import java.util.Iterator;
import org.hamcrest.internal.ArrayIterator;
import org.hamcrest.internal.SelfDescribingValueIterator;

public abstract class BaseDescription
  implements Description
{
  public Description appendText(String text)
  {
    append(text);
    return this;
  }
  
  public Description appendDescriptionOf(SelfDescribing value)
  {
    value.describeTo(this);
    return this;
  }
  
  public Description appendValue(Object value)
  {
    if (value == null)
    {
      append("null");
    }
    else if ((value instanceof String))
    {
      toJavaSyntax((String)value);
    }
    else if ((value instanceof Character))
    {
      append('"');
      toJavaSyntax(((Character)value).charValue());
      append('"');
    }
    else if ((value instanceof Short))
    {
      append('<');
      append(String.valueOf(value));
      append("s>");
    }
    else if ((value instanceof Long))
    {
      append('<');
      append(String.valueOf(value));
      append("L>");
    }
    else if ((value instanceof Float))
    {
      append('<');
      append(String.valueOf(value));
      append("F>");
    }
    else if (value.getClass().isArray())
    {
      appendValueList("[", ", ", "]", new ArrayIterator(value));
    }
    else
    {
      append('<');
      append(String.valueOf(value));
      append('>');
    }
    return this;
  }
  
  public <T> Description appendValueList(String start, String separator, String end, T... values)
  {
    return appendValueList(start, separator, end, Arrays.asList(values));
  }
  
  public <T> Description appendValueList(String start, String separator, String end, Iterable<T> values)
  {
    return appendValueList(start, separator, end, values.iterator());
  }
  
  private <T> Description appendValueList(String start, String separator, String end, Iterator<T> values)
  {
    return appendList(start, separator, end, new SelfDescribingValueIterator(values));
  }
  
  public Description appendList(String start, String separator, String end, Iterable<? extends SelfDescribing> values)
  {
    return appendList(start, separator, end, values.iterator());
  }
  
  private Description appendList(String start, String separator, String end, Iterator<? extends SelfDescribing> i)
  {
    boolean separate = false;
    
    append(start);
    while (i.hasNext())
    {
      if (separate) {
        append(separator);
      }
      appendDescriptionOf((SelfDescribing)i.next());
      separate = true;
    }
    append(end);
    
    return this;
  }
  
  protected void append(String str)
  {
    for (int i = 0; i < str.length(); i++) {
      append(str.charAt(i));
    }
  }
  
  protected abstract void append(char paramChar);
  
  private void toJavaSyntax(String unformatted)
  {
    append('"');
    for (int i = 0; i < unformatted.length(); i++) {
      toJavaSyntax(unformatted.charAt(i));
    }
    append('"');
  }
  
  private void toJavaSyntax(char ch)
  {
    switch (ch)
    {
    case '"': 
      append("\\\"");
      break;
    case '\n': 
      append("\\n");
      break;
    case '\r': 
      append("\\r");
      break;
    case '\t': 
      append("\\t");
      break;
    default: 
      append(ch);
    }
  }
}

/* Location:
 * Qualified Name:     org.hamcrest.BaseDescription
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.hamcrest;

public abstract class BaseMatcher<T>
  implements Matcher<T>
{
  public final void _dont_implement_Matcher___instead_extend_BaseMatcher_() {}
  
  public String toString()
  {
    return StringDescription.toString(this);
  }
}

/* Location:
 * Qualified Name:     org.hamcrest.BaseMatcher
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.hamcrest.core;

import java.util.Arrays;
import org.hamcrest.BaseMatcher;
import org.hamcrest.Description;
import org.hamcrest.Factory;
import org.hamcrest.Matcher;

public class AllOf<T>
  extends BaseMatcher<T>
{
  private final Iterable<Matcher<? extends T>> matchers;
  
  public AllOf(Iterable<Matcher<? extends T>> matchers)
  {
    this.matchers = matchers;
  }
  
  public boolean matches(Object o)
  {
    for (Matcher<? extends T> matcher : matchers) {
      if (!matcher.matches(o)) {
        return false;
      }
    }
    return true;
  }
  
  public void describeTo(Description description)
  {
    description.appendList("(", " and ", ")", matchers);
  }
  
  @Factory
  public static <T> Matcher<T> allOf(Matcher<? extends T>... matchers)
  {
    return allOf(Arrays.asList(matchers));
  }
  
  @Factory
  public static <T> Matcher<T> allOf(Iterable<Matcher<? extends T>> matchers)
  {
    return new AllOf(matchers);
  }
}

/* Location:
 * Qualified Name:     org.hamcrest.core.AllOf
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.hamcrest.core;

import java.util.Arrays;
import org.hamcrest.BaseMatcher;
import org.hamcrest.Description;
import org.hamcrest.Factory;
import org.hamcrest.Matcher;

public class AnyOf<T>
  extends BaseMatcher<T>
{
  private final Iterable<Matcher<? extends T>> matchers;
  
  public AnyOf(Iterable<Matcher<? extends T>> matchers)
  {
    this.matchers = matchers;
  }
  
  public boolean matches(Object o)
  {
    for (Matcher<? extends T> matcher : matchers) {
      if (matcher.matches(o)) {
        return true;
      }
    }
    return false;
  }
  
  public void describeTo(Description description)
  {
    description.appendList("(", " or ", ")", matchers);
  }
  
  @Factory
  public static <T> Matcher<T> anyOf(Matcher<? extends T>... matchers)
  {
    return anyOf(Arrays.asList(matchers));
  }
  
  @Factory
  public static <T> Matcher<T> anyOf(Iterable<Matcher<? extends T>> matchers)
  {
    return new AnyOf(matchers);
  }
}

/* Location:
 * Qualified Name:     org.hamcrest.core.AnyOf
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.hamcrest.core;

import java.util.regex.Pattern;
import org.hamcrest.BaseMatcher;
import org.hamcrest.Description;
import org.hamcrest.Factory;

public class DescribedAs<T>
  extends BaseMatcher<T>
{
  private final String descriptionTemplate;
  private final org.hamcrest.Matcher<T> matcher;
  private final Object[] values;
  private static final Pattern ARG_PATTERN = Pattern.compile("%([0-9]+)");
  
  public DescribedAs(String descriptionTemplate, org.hamcrest.Matcher<T> matcher, Object[] values)
  {
    this.descriptionTemplate = descriptionTemplate;
    this.matcher = matcher;
    this.values = ((Object[])values.clone());
  }
  
  public boolean matches(Object o)
  {
    return matcher.matches(o);
  }
  
  public void describeTo(Description description)
  {
    java.util.regex.Matcher arg = ARG_PATTERN.matcher(descriptionTemplate);
    
    int textStart = 0;
    while (arg.find())
    {
      description.appendText(descriptionTemplate.substring(textStart, arg.start()));
      int argIndex = Integer.parseInt(arg.group(1));
      description.appendValue(values[argIndex]);
      textStart = arg.end();
    }
    if (textStart < descriptionTemplate.length()) {
      description.appendText(descriptionTemplate.substring(textStart));
    }
  }
  
  @Factory
  public static <T> org.hamcrest.Matcher<T> describedAs(String description, org.hamcrest.Matcher<T> matcher, Object... values)
  {
    return new DescribedAs(description, matcher, values);
  }
}

/* Location:
 * Qualified Name:     org.hamcrest.core.DescribedAs
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.hamcrest.core;

import org.hamcrest.BaseMatcher;
import org.hamcrest.Description;
import org.hamcrest.Factory;
import org.hamcrest.Matcher;

public class Is<T>
  extends BaseMatcher<T>
{
  private final Matcher<T> matcher;
  
  public Is(Matcher<T> matcher)
  {
    this.matcher = matcher;
  }
  
  public boolean matches(Object arg)
  {
    return matcher.matches(arg);
  }
  
  public void describeTo(Description description)
  {
    description.appendText("is ").appendDescriptionOf(matcher);
  }
  
  @Factory
  public static <T> Matcher<T> is(Matcher<T> matcher)
  {
    return new Is(matcher);
  }
  
  @Factory
  public static <T> Matcher<T> is(T value)
  {
    return is(IsEqual.equalTo(value));
  }
  
  @Factory
  public static Matcher<Object> is(Class<?> type)
  {
    return is(IsInstanceOf.instanceOf(type));
  }
}

/* Location:
 * Qualified Name:     org.hamcrest.core.Is
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.hamcrest.core;

import org.hamcrest.BaseMatcher;
import org.hamcrest.Description;
import org.hamcrest.Factory;
import org.hamcrest.Matcher;

public class IsAnything<T>
  extends BaseMatcher<T>
{
  private final String description;
  
  public IsAnything()
  {
    this("ANYTHING");
  }
  
  public IsAnything(String description)
  {
    this.description = description;
  }
  
  public boolean matches(Object o)
  {
    return true;
  }
  
  public void describeTo(Description description)
  {
    description.appendText(this.description);
  }
  
  @Factory
  public static <T> Matcher<T> anything()
  {
    return new IsAnything();
  }
  
  @Factory
  public static <T> Matcher<T> anything(String description)
  {
    return new IsAnything(description);
  }
  
  @Factory
  public static <T> Matcher<T> any(Class<T> type)
  {
    return new IsAnything();
  }
}

/* Location:
 * Qualified Name:     org.hamcrest.core.IsAnything
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.hamcrest.core;

import java.lang.reflect.Array;
import org.hamcrest.BaseMatcher;
import org.hamcrest.Description;
import org.hamcrest.Factory;
import org.hamcrest.Matcher;

public class IsEqual<T>
  extends BaseMatcher<T>
{
  private final Object object;
  
  public IsEqual(T equalArg)
  {
    object = equalArg;
  }
  
  public boolean matches(Object arg)
  {
    return areEqual(object, arg);
  }
  
  public void describeTo(Description description)
  {
    description.appendValue(object);
  }
  
  private static boolean areEqual(Object o1, Object o2)
  {
    if ((o1 == null) || (o2 == null)) {
      return (o1 == null) && (o2 == null);
    }
    if (isArray(o1)) {
      return (isArray(o2)) && (areArraysEqual(o1, o2));
    }
    return o1.equals(o2);
  }
  
  private static boolean areArraysEqual(Object o1, Object o2)
  {
    return (areArrayLengthsEqual(o1, o2)) && (areArrayElementsEqual(o1, o2));
  }
  
  private static boolean areArrayLengthsEqual(Object o1, Object o2)
  {
    return Array.getLength(o1) == Array.getLength(o2);
  }
  
  private static boolean areArrayElementsEqual(Object o1, Object o2)
  {
    for (int i = 0; i < Array.getLength(o1); i++) {
      if (!areEqual(Array.get(o1, i), Array.get(o2, i))) {
        return false;
      }
    }
    return true;
  }
  
  private static boolean isArray(Object o)
  {
    return o.getClass().isArray();
  }
  
  @Factory
  public static <T> Matcher<T> equalTo(T operand)
  {
    return new IsEqual(operand);
  }
}

/* Location:
 * Qualified Name:     org.hamcrest.core.IsEqual
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.hamcrest.core;

import org.hamcrest.BaseMatcher;
import org.hamcrest.Description;
import org.hamcrest.Factory;
import org.hamcrest.Matcher;

public class IsInstanceOf
  extends BaseMatcher<Object>
{
  private final Class<?> theClass;
  
  public IsInstanceOf(Class<?> theClass)
  {
    this.theClass = theClass;
  }
  
  public boolean matches(Object item)
  {
    return theClass.isInstance(item);
  }
  
  public void describeTo(Description description)
  {
    description.appendText("an instance of ").appendText(theClass.getName());
  }
  
  @Factory
  public static Matcher<Object> instanceOf(Class<?> type)
  {
    return new IsInstanceOf(type);
  }
}

/* Location:
 * Qualified Name:     org.hamcrest.core.IsInstanceOf
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.hamcrest.core;

import org.hamcrest.BaseMatcher;
import org.hamcrest.Description;
import org.hamcrest.Factory;
import org.hamcrest.Matcher;

public class IsNot<T>
  extends BaseMatcher<T>
{
  private final Matcher<T> matcher;
  
  public IsNot(Matcher<T> matcher)
  {
    this.matcher = matcher;
  }
  
  public boolean matches(Object arg)
  {
    return !matcher.matches(arg);
  }
  
  public void describeTo(Description description)
  {
    description.appendText("not ").appendDescriptionOf(matcher);
  }
  
  @Factory
  public static <T> Matcher<T> not(Matcher<T> matcher)
  {
    return new IsNot(matcher);
  }
  
  @Factory
  public static <T> Matcher<T> not(T value)
  {
    return not(IsEqual.equalTo(value));
  }
}

/* Location:
 * Qualified Name:     org.hamcrest.core.IsNot
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.hamcrest.core;

import org.hamcrest.BaseMatcher;
import org.hamcrest.Description;
import org.hamcrest.Factory;
import org.hamcrest.Matcher;

public class IsNull<T>
  extends BaseMatcher<T>
{
  public boolean matches(Object o)
  {
    return o == null;
  }
  
  public void describeTo(Description description)
  {
    description.appendText("null");
  }
  
  @Factory
  public static <T> Matcher<T> nullValue()
  {
    return new IsNull();
  }
  
  @Factory
  public static <T> Matcher<T> notNullValue()
  {
    return IsNot.not(nullValue());
  }
  
  @Factory
  public static <T> Matcher<T> nullValue(Class<T> type)
  {
    return nullValue();
  }
  
  @Factory
  public static <T> Matcher<T> notNullValue(Class<T> type)
  {
    return notNullValue();
  }
}

/* Location:
 * Qualified Name:     org.hamcrest.core.IsNull
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.hamcrest.core;

import org.hamcrest.BaseMatcher;
import org.hamcrest.Description;
import org.hamcrest.Factory;
import org.hamcrest.Matcher;

public class IsSame<T>
  extends BaseMatcher<T>
{
  private final T object;
  
  public IsSame(T object)
  {
    this.object = object;
  }
  
  public boolean matches(Object arg)
  {
    return arg == object;
  }
  
  public void describeTo(Description description)
  {
    description.appendText("same(").appendValue(object).appendText(")");
  }
  
  @Factory
  public static <T> Matcher<T> sameInstance(T object)
  {
    return new IsSame(object);
  }
}

/* Location:
 * Qualified Name:     org.hamcrest.core.IsSame
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.hamcrest;

import org.hamcrest.core.AllOf;
import org.hamcrest.core.AnyOf;
import org.hamcrest.core.DescribedAs;
import org.hamcrest.core.Is;
import org.hamcrest.core.IsAnything;
import org.hamcrest.core.IsEqual;
import org.hamcrest.core.IsInstanceOf;
import org.hamcrest.core.IsNot;
import org.hamcrest.core.IsNull;
import org.hamcrest.core.IsSame;

public class CoreMatchers
{
  public static <T> Matcher<T> is(Matcher<T> matcher)
  {
    return Is.is(matcher);
  }
  
  public static <T> Matcher<T> is(T value)
  {
    return Is.is(value);
  }
  
  public static Matcher<Object> is(Class<?> type)
  {
    return Is.is(type);
  }
  
  public static <T> Matcher<T> not(Matcher<T> matcher)
  {
    return IsNot.not(matcher);
  }
  
  public static <T> Matcher<T> not(T value)
  {
    return IsNot.not(value);
  }
  
  public static <T> Matcher<T> equalTo(T operand)
  {
    return IsEqual.equalTo(operand);
  }
  
  public static Matcher<Object> instanceOf(Class<?> type)
  {
    return IsInstanceOf.instanceOf(type);
  }
  
  public static <T> Matcher<T> allOf(Matcher<? extends T>... matchers)
  {
    return AllOf.allOf(matchers);
  }
  
  public static <T> Matcher<T> allOf(Iterable<Matcher<? extends T>> matchers)
  {
    return AllOf.allOf(matchers);
  }
  
  public static <T> Matcher<T> anyOf(Matcher<? extends T>... matchers)
  {
    return AnyOf.anyOf(matchers);
  }
  
  public static <T> Matcher<T> anyOf(Iterable<Matcher<? extends T>> matchers)
  {
    return AnyOf.anyOf(matchers);
  }
  
  public static <T> Matcher<T> sameInstance(T object)
  {
    return IsSame.sameInstance(object);
  }
  
  public static <T> Matcher<T> anything()
  {
    return IsAnything.anything();
  }
  
  public static <T> Matcher<T> anything(String description)
  {
    return IsAnything.anything(description);
  }
  
  public static <T> Matcher<T> any(Class<T> type)
  {
    return IsAnything.any(type);
  }
  
  public static <T> Matcher<T> nullValue()
  {
    return IsNull.nullValue();
  }
  
  public static <T> Matcher<T> nullValue(Class<T> type)
  {
    return IsNull.nullValue(type);
  }
  
  public static <T> Matcher<T> notNullValue()
  {
    return IsNull.notNullValue();
  }
  
  public static <T> Matcher<T> notNullValue(Class<T> type)
  {
    return IsNull.notNullValue(type);
  }
  
  public static <T> Matcher<T> describedAs(String description, Matcher<T> matcher, Object... values)
  {
    return DescribedAs.describedAs(description, matcher, values);
  }
}

/* Location:
 * Qualified Name:     org.hamcrest.CoreMatchers
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.hamcrest;

public abstract interface Description
{
  public abstract Description appendText(String paramString);
  
  public abstract Description appendDescriptionOf(SelfDescribing paramSelfDescribing);
  
  public abstract Description appendValue(Object paramObject);
  
  public abstract <T> Description appendValueList(String paramString1, String paramString2, String paramString3, T... paramVarArgs);
  
  public abstract <T> Description appendValueList(String paramString1, String paramString2, String paramString3, Iterable<T> paramIterable);
  
  public abstract Description appendList(String paramString1, String paramString2, String paramString3, Iterable<? extends SelfDescribing> paramIterable);
}

/* Location:
 * Qualified Name:     org.hamcrest.Description
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.hamcrest;

import java.lang.annotation.Annotation;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Retention(RetentionPolicy.RUNTIME)
@Target({java.lang.annotation.ElementType.METHOD})
public @interface Factory {}

/* Location:
 * Qualified Name:     org.hamcrest.Factory
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.hamcrest.internal;

import java.lang.reflect.Array;
import java.util.Iterator;

public class ArrayIterator
  implements Iterator<Object>
{
  private final Object array;
  private int currentIndex = 0;
  
  public ArrayIterator(Object array)
  {
    if (!array.getClass().isArray()) {
      throw new IllegalArgumentException("not an array");
    }
    this.array = array;
  }
  
  public boolean hasNext()
  {
    return currentIndex < Array.getLength(array);
  }
  
  public Object next()
  {
    return Array.get(array, currentIndex++);
  }
  
  public void remove()
  {
    throw new UnsupportedOperationException("cannot remove items from an array");
  }
}

/* Location:
 * Qualified Name:     org.hamcrest.internal.ArrayIterator
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.hamcrest.internal;

import org.hamcrest.Description;
import org.hamcrest.SelfDescribing;

public class SelfDescribingValue<T>
  implements SelfDescribing
{
  private T value;
  
  public SelfDescribingValue(T value)
  {
    this.value = value;
  }
  
  public void describeTo(Description description)
  {
    description.appendValue(value);
  }
}

/* Location:
 * Qualified Name:     org.hamcrest.internal.SelfDescribingValue
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.hamcrest.internal;

import java.util.Iterator;
import org.hamcrest.SelfDescribing;

public class SelfDescribingValueIterator<T>
  implements Iterator<SelfDescribing>
{
  private Iterator<T> values;
  
  public SelfDescribingValueIterator(Iterator<T> values)
  {
    this.values = values;
  }
  
  public boolean hasNext()
  {
    return values.hasNext();
  }
  
  public SelfDescribing next()
  {
    return new SelfDescribingValue(values.next());
  }
  
  public void remove()
  {
    values.remove();
  }
}

/* Location:
 * Qualified Name:     org.hamcrest.internal.SelfDescribingValueIterator
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.hamcrest;

public abstract interface Matcher<T>
  extends SelfDescribing
{
  public abstract boolean matches(Object paramObject);
  
  public abstract void _dont_implement_Matcher___instead_extend_BaseMatcher_();
}

/* Location:
 * Qualified Name:     org.hamcrest.Matcher
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.hamcrest;

public abstract interface SelfDescribing
{
  public abstract void describeTo(Description paramDescription);
}

/* Location:
 * Qualified Name:     org.hamcrest.SelfDescribing
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.hamcrest;

import java.io.IOException;

public class StringDescription
  extends BaseDescription
{
  private final Appendable out;
  
  public StringDescription()
  {
    this(new StringBuilder());
  }
  
  public StringDescription(Appendable out)
  {
    this.out = out;
  }
  
  public static String toString(SelfDescribing value)
  {
    return new StringDescription().appendDescriptionOf(value).toString();
  }
  
  public static String asString(SelfDescribing selfDescribing)
  {
    return toString(selfDescribing);
  }
  
  protected void append(String str)
  {
    try
    {
      out.append(str);
    }
    catch (IOException e)
    {
      throw new RuntimeException("Could not write description", e);
    }
  }
  
  protected void append(char c)
  {
    try
    {
      out.append(c);
    }
    catch (IOException e)
    {
      throw new RuntimeException("Could not write description", e);
    }
  }
  
  public String toString()
  {
    return out.toString();
  }
}

/* Location:
 * Qualified Name:     org.hamcrest.StringDescription
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
1

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2017. Infinite Loop Ltd