Search in sources :

Example 1 with GwtIncompatible

use of com.google_voltpatches.common.annotations.GwtIncompatible in project voltdb by VoltDB.

the class Throwables method getStackTraceAsString.

/**
   * Returns a string containing the result of {@link Throwable#toString() toString()}, followed by
   * the full, recursive stack trace of {@code throwable}. Note that you probably should not be
   * parsing the resulting string; if you need programmatic access to the stack frames, you can call
   * {@link Throwable#getStackTrace()}.
   */
// java.io.PrintWriter, java.io.StringWriter
@GwtIncompatible
public static String getStackTraceAsString(Throwable throwable) {
    StringWriter stringWriter = new StringWriter();
    throwable.printStackTrace(new PrintWriter(stringWriter));
    return stringWriter.toString();
}
Also used : StringWriter(java.io.StringWriter) PrintWriter(java.io.PrintWriter) GwtIncompatible(com.google_voltpatches.common.annotations.GwtIncompatible)

Example 2 with GwtIncompatible

use of com.google_voltpatches.common.annotations.GwtIncompatible in project voltdb by VoltDB.

the class ImmutableListMultimap method readObject.

// java.io.ObjectInputStream
@GwtIncompatible
private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException {
    stream.defaultReadObject();
    int keyCount = stream.readInt();
    if (keyCount < 0) {
        throw new InvalidObjectException("Invalid key count " + keyCount);
    }
    ImmutableMap.Builder<Object, ImmutableList<Object>> builder = ImmutableMap.builder();
    int tmpSize = 0;
    for (int i = 0; i < keyCount; i++) {
        Object key = stream.readObject();
        int valueCount = stream.readInt();
        if (valueCount <= 0) {
            throw new InvalidObjectException("Invalid value count " + valueCount);
        }
        ImmutableList.Builder<Object> valuesBuilder = ImmutableList.builder();
        for (int j = 0; j < valueCount; j++) {
            valuesBuilder.add(stream.readObject());
        }
        builder.put(key, valuesBuilder.build());
        tmpSize += valueCount;
    }
    ImmutableMap<Object, ImmutableList<Object>> tmpMap;
    try {
        tmpMap = builder.build();
    } catch (IllegalArgumentException e) {
        throw (InvalidObjectException) new InvalidObjectException(e.getMessage()).initCause(e);
    }
    FieldSettersHolder.MAP_FIELD_SETTER.set(this, tmpMap);
    FieldSettersHolder.SIZE_FIELD_SETTER.set(this, tmpSize);
}
Also used : InvalidObjectException(java.io.InvalidObjectException) GwtIncompatible(com.google_voltpatches.common.annotations.GwtIncompatible)

Example 3 with GwtIncompatible

use of com.google_voltpatches.common.annotations.GwtIncompatible in project voltdb by VoltDB.

the class ImmutableSetMultimap method readObject.

// java.io.ObjectInputStream
@GwtIncompatible
// Serialization type safety is at the caller's mercy.
@SuppressWarnings("unchecked")
private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException {
    stream.defaultReadObject();
    Comparator<Object> valueComparator = (Comparator<Object>) stream.readObject();
    int keyCount = stream.readInt();
    if (keyCount < 0) {
        throw new InvalidObjectException("Invalid key count " + keyCount);
    }
    ImmutableMap.Builder<Object, ImmutableSet<Object>> builder = ImmutableMap.builder();
    int tmpSize = 0;
    for (int i = 0; i < keyCount; i++) {
        Object key = stream.readObject();
        int valueCount = stream.readInt();
        if (valueCount <= 0) {
            throw new InvalidObjectException("Invalid value count " + valueCount);
        }
        ImmutableSet.Builder<Object> valuesBuilder = valuesBuilder(valueComparator);
        for (int j = 0; j < valueCount; j++) {
            valuesBuilder.add(stream.readObject());
        }
        ImmutableSet<Object> valueSet = valuesBuilder.build();
        if (valueSet.size() != valueCount) {
            throw new InvalidObjectException("Duplicate key-value pairs exist for key " + key);
        }
        builder.put(key, valueSet);
        tmpSize += valueCount;
    }
    ImmutableMap<Object, ImmutableSet<Object>> tmpMap;
    try {
        tmpMap = builder.build();
    } catch (IllegalArgumentException e) {
        throw (InvalidObjectException) new InvalidObjectException(e.getMessage()).initCause(e);
    }
    FieldSettersHolder.MAP_FIELD_SETTER.set(this, tmpMap);
    FieldSettersHolder.SIZE_FIELD_SETTER.set(this, tmpSize);
    FieldSettersHolder.EMPTY_SET_FIELD_SETTER.set(this, emptySet(valueComparator));
}
Also used : InvalidObjectException(java.io.InvalidObjectException) Comparator(java.util.Comparator) GwtIncompatible(com.google_voltpatches.common.annotations.GwtIncompatible)

Example 4 with GwtIncompatible

use of com.google_voltpatches.common.annotations.GwtIncompatible in project voltdb by VoltDB.

the class CharMatcher method precomputedInternal.

/**
   * This is the actual implementation of {@link #precomputed}, but we bounce calls through a method
   * on {@link Platform} so that we can have different behavior in GWT.
   *
   * <p>This implementation tries to be smart in a number of ways. It recognizes cases where the
   * negation is cheaper to precompute than the matcher itself; it tries to build small hash tables
   * for matchers that only match a few characters, and so on. In the worst-case scenario, it
   * constructs an eight-kilobyte bit array and queries that. In many situations this produces a
   * matcher which is faster to query than the original.
   */
// SmallCharMatcher
@GwtIncompatible
CharMatcher precomputedInternal() {
    final BitSet table = new BitSet();
    setBits(table);
    int totalCharacters = table.cardinality();
    if (totalCharacters * 2 <= DISTINCT_CHARS) {
        return precomputedPositive(totalCharacters, table, toString());
    } else {
        // TODO(lowasser): is it worth it to worry about the last character of large matchers?
        table.flip(Character.MIN_VALUE, Character.MAX_VALUE + 1);
        int negatedCharacters = DISTINCT_CHARS - totalCharacters;
        String suffix = ".negate()";
        final String description = toString();
        String negatedDescription = description.endsWith(suffix) ? description.substring(0, description.length() - suffix.length()) : description + suffix;
        return new NegatedFastMatcher(precomputedPositive(negatedCharacters, table, negatedDescription)) {

            @Override
            public String toString() {
                return description;
            }
        };
    }
}
Also used : BitSet(java.util.BitSet) GwtIncompatible(com.google_voltpatches.common.annotations.GwtIncompatible)

Example 5 with GwtIncompatible

use of com.google_voltpatches.common.annotations.GwtIncompatible in project voltdb by VoltDB.

the class BigIntegerMath method log10.

/**
   * Returns the base-10 logarithm of {@code x}, rounded according to the specified rounding mode.
   *
   * @throws IllegalArgumentException if {@code x <= 0}
   * @throws ArithmeticException if {@code mode} is {@link RoundingMode#UNNECESSARY} and {@code x}
   *     is not a power of ten
   */
// TODO
@GwtIncompatible
@SuppressWarnings("fallthrough")
public static int log10(BigInteger x, RoundingMode mode) {
    checkPositive("x", x);
    if (fitsInLong(x)) {
        return LongMath.log10(x.longValue(), mode);
    }
    int approxLog10 = (int) (log2(x, FLOOR) * LN_2 / LN_10);
    BigInteger approxPow = BigInteger.TEN.pow(approxLog10);
    int approxCmp = approxPow.compareTo(x);
    if (approxCmp > 0) {
        /*
       * The code is written so that even completely incorrect approximations will still yield the
       * correct answer eventually, but in practice this branch should almost never be entered, and
       * even then the loop should not run more than once.
       */
        do {
            approxLog10--;
            approxPow = approxPow.divide(BigInteger.TEN);
            approxCmp = approxPow.compareTo(x);
        } while (approxCmp > 0);
    } else {
        BigInteger nextPow = BigInteger.TEN.multiply(approxPow);
        int nextCmp = nextPow.compareTo(x);
        while (nextCmp <= 0) {
            approxLog10++;
            approxPow = nextPow;
            approxCmp = nextCmp;
            nextPow = BigInteger.TEN.multiply(approxPow);
            nextCmp = nextPow.compareTo(x);
        }
    }
    int floorLog = approxLog10;
    BigInteger floorPow = approxPow;
    int floorCmp = approxCmp;
    switch(mode) {
        case UNNECESSARY:
            checkRoundingUnnecessary(floorCmp == 0);
        // fall through
        case FLOOR:
        case DOWN:
            return floorLog;
        case CEILING:
        case UP:
            return floorPow.equals(x) ? floorLog : floorLog + 1;
        case HALF_DOWN:
        case HALF_UP:
        case HALF_EVEN:
            // Since sqrt(10) is irrational, log10(x) - floorLog can never be exactly 0.5
            BigInteger x2 = x.pow(2);
            BigInteger halfPowerSquared = floorPow.pow(2).multiply(BigInteger.TEN);
            return (x2.compareTo(halfPowerSquared) <= 0) ? floorLog : floorLog + 1;
        default:
            throw new AssertionError();
    }
}
Also used : BigInteger(java.math.BigInteger) GwtIncompatible(com.google_voltpatches.common.annotations.GwtIncompatible)

Aggregations

GwtIncompatible (com.google_voltpatches.common.annotations.GwtIncompatible)14 BigInteger (java.math.BigInteger)4 Math.rint (java.lang.Math.rint)3 InvalidObjectException (java.io.InvalidObjectException)2 ExecutionException (java.util.concurrent.ExecutionException)2 Future (java.util.concurrent.Future)2 ListFuture (com.google_voltpatches.common.util.concurrent.CollectionFuture.ListFuture)1 SimpleForwardingListenableFuture (com.google_voltpatches.common.util.concurrent.ForwardingListenableFuture.SimpleForwardingListenableFuture)1 ImmediateCancelledFuture (com.google_voltpatches.common.util.concurrent.ImmediateFuture.ImmediateCancelledFuture)1 ImmediateFailedCheckedFuture (com.google_voltpatches.common.util.concurrent.ImmediateFuture.ImmediateFailedCheckedFuture)1 ImmediateFailedFuture (com.google_voltpatches.common.util.concurrent.ImmediateFuture.ImmediateFailedFuture)1 ImmediateSuccessfulCheckedFuture (com.google_voltpatches.common.util.concurrent.ImmediateFuture.ImmediateSuccessfulCheckedFuture)1 ImmediateSuccessfulFuture (com.google_voltpatches.common.util.concurrent.ImmediateFuture.ImmediateSuccessfulFuture)1 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 Method (java.lang.reflect.Method)1 BigDecimal (java.math.BigDecimal)1 BitSet (java.util.BitSet)1 Comparator (java.util.Comparator)1 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)1