Android Open Source - android-plotter Check






From Project

Back to project page android-plotter.

License

The source code is released under:

Apache License

If you think the Android project android-plotter listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*
 * Copyright 2014 serso aka se.solovyev/*from   ww  w  .  ja v a  2  s  .  c  o m*/
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 * Contact details
 *
 * Email: se.solovyev@gmail.com
 * Site:  http://se.solovyev.org
 */

package org.solovyev.android.plotter;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.Collection;
import java.util.Map;

import static java.lang.Thread.currentThread;

public final class Check {

  private static final boolean junit = isJunit();

  private static boolean isJunit() {
    final StackTraceElement[] stackTrace = currentThread().getStackTrace();
    for (StackTraceElement element : stackTrace) {
      if (element.getClassName().startsWith("org.junit.")) {
        return true;
      }
    }
    return false;
  }

  private Check() {
    throw new AssertionError();
  }

  public static void isMainThread() {
    if (!junit && !Plot.isMainThread()) {
      throw new AssertionException("Should be called on the main thread");
    }
  }

  public static void isAnyThread() {
  }

  public static void isNotMainThread() {
    if (!junit && Plot.isMainThread()) {
      throw new AssertionException("Should be called on the background thread");
    }
  }

  public static void isGlThread() {
    if (!junit && !glThread()) {
      throw new AssertionException("Should be called on the GL thread");
    }
  }

  private static boolean glThread() {
    return Thread.currentThread().getName().contains("GL");
  }

  public static void isNotNull(@Nullable Object o) {
    isNotNull(o, "Object should not be null");
  }

  public static void isNotNull(@Nullable Object o, @Nonnull String message) {
    if (o == null) {
      throw new AssertionException(message);
    }
  }

  static void notEquals(int expected, int actual) {
    if (expected == actual) {
      throw new AssertionException("Should not be equal");
    }
  }

  public static void equals(int expected, int actual) {
    if (expected != actual) {
      throw new AssertionException("Should be equal");
    }
  }

  public static void isTrue(boolean expression, @Nonnull String message) {
    if (!expression) {
      throw new AssertionException(message);
    }
  }

  static void isFalse(boolean expression, @Nonnull String message) {
    if (expression) {
      throw new AssertionException(message);
    }
  }

  static void isNull(@Nullable Object o) {
    isNull(o, "Object should be null");
  }

  static void isNull(@Nullable Object o, @Nonnull String message) {
    if (o != null) {
      throw new AssertionException(message);
    }
  }

  static void isNotEmpty(@Nullable String s) {
    if (s == null || s.length() == 0) {
      throw new AssertionException("String should not be empty");
    }
  }

  static void isNotEmpty(@Nullable String[] array) {
    if (array == null || array.length == 0) {
      throw new AssertionException("Array should not be empty");
    }
  }

  static void isNotEmpty(@Nullable Collection<?> c) {
    if (c == null || c.size() == 0) {
      throw new AssertionException("Collection should not be empty");
    }
  }

  static void isNotEmpty(@Nullable Map<?, ?> c) {
    if (c == null || c.size() == 0) {
      throw new AssertionException("Map should not be empty");
    }
  }

  static void same(Object expected, Object actual) {
    if (expected != actual) {
      throw new AssertionException("Objects should be the same");
    }
  }

  private static final class AssertionException extends RuntimeException {
    private AssertionException(@Nonnull String message) {
      super(message);
    }
  }
}




Java Source Code List

com.android.texample.GLText.java
com.android.texample.SpriteBatch.java
com.android.texample.TexampleRenderer.java
com.android.texample.TextureRegion.java
com.android.texample.Vertices.java
org.solovyev.android.plotter.Angle.java
org.solovyev.android.plotter.AxisStyle.java
org.solovyev.android.plotter.Check.java
org.solovyev.android.plotter.Color.java
org.solovyev.android.plotter.DefaultPlotter.java
org.solovyev.android.plotter.Dimensions.java
org.solovyev.android.plotter.Frustum.java
org.solovyev.android.plotter.Function0.java
org.solovyev.android.plotter.Function1.java
org.solovyev.android.plotter.Function2.java
org.solovyev.android.plotter.Function.java
org.solovyev.android.plotter.LineStyle.java
org.solovyev.android.plotter.MeshConfig.java
org.solovyev.android.plotter.MultisampleConfigChooser.java
org.solovyev.android.plotter.PinchZoomTracker.java
org.solovyev.android.plotter.PlotData.java
org.solovyev.android.plotter.PlotFunction.java
org.solovyev.android.plotter.PlotRenderer.java
org.solovyev.android.plotter.PlotView.java
org.solovyev.android.plotter.Plot.java
org.solovyev.android.plotter.Plotter.java
org.solovyev.android.plotter.PlottingView.java
org.solovyev.android.plotter.Spf.java
org.solovyev.android.plotter.SuperFunction.java
org.solovyev.android.plotter.TouchHandler.java
org.solovyev.android.plotter.ZoomLevels.java
org.solovyev.android.plotter.Zoomer.java
org.solovyev.android.plotter.app.MainActivity.java
org.solovyev.android.plotter.app.PlotterApplication.java
org.solovyev.android.plotter.meshes.Arrays.java
org.solovyev.android.plotter.meshes.AxisGrid.java
org.solovyev.android.plotter.meshes.Axis.java
org.solovyev.android.plotter.meshes.BaseCube.java
org.solovyev.android.plotter.meshes.BaseCurve.java
org.solovyev.android.plotter.meshes.BaseMesh.java
org.solovyev.android.plotter.meshes.BaseSurface.java
org.solovyev.android.plotter.meshes.DimensionsAwareSwapper.java
org.solovyev.android.plotter.meshes.DimensionsAware.java
org.solovyev.android.plotter.meshes.DoubleBufferGroup.java
org.solovyev.android.plotter.meshes.DoubleBufferMesh.java
org.solovyev.android.plotter.meshes.FunctionGraph2d.java
org.solovyev.android.plotter.meshes.FunctionGraph3d.java
org.solovyev.android.plotter.meshes.FunctionGraphSwapper.java
org.solovyev.android.plotter.meshes.FunctionGraph.java
org.solovyev.android.plotter.meshes.Graph.java
org.solovyev.android.plotter.meshes.Group.java
org.solovyev.android.plotter.meshes.IndicesOrder.java
org.solovyev.android.plotter.meshes.ListGroup.java
org.solovyev.android.plotter.meshes.ListPool.java
org.solovyev.android.plotter.meshes.Mesh.java
org.solovyev.android.plotter.meshes.Meshes.java
org.solovyev.android.plotter.meshes.Pool.java
org.solovyev.android.plotter.meshes.Scene.java
org.solovyev.android.plotter.meshes.SolidCube.java
org.solovyev.android.plotter.meshes.SurfaceInitializer.java
org.solovyev.android.plotter.meshes.WireFrameCube.java