Example usage for java.lang Long MIN_VALUE

List of usage examples for java.lang Long MIN_VALUE

Introduction

In this page you can find the example usage for java.lang Long MIN_VALUE.

Prototype

long MIN_VALUE

To view the source code for java.lang Long MIN_VALUE.

Click Source Link

Document

A constant holding the minimum value a long can have, -263.

Usage

From source file:lucee.runtime.config.ConfigWebFactory.java

public static long toLong(String value, long defaultValue) {

    if (value == null || value.trim().length() == 0)
        return defaultValue;
    long longValue = Caster.toLongValue(value.trim(), Long.MIN_VALUE);
    if (longValue == Long.MIN_VALUE)
        return defaultValue;
    return longValue;
}

From source file:gov.noaa.pfel.coastwatch.Projects.java

/** Can netcdf-java write longs (64bit integers) into a nc3 file? 
 * 2017-02-08:/*from   w ww  . java 2s.  c  om*/
java.lang.IllegalArgumentException: illegal dataType: long not supported in netcdf-3
at ucar.nc2.NetcdfFileWriter.addVariable(NetcdfFileWriter.java:538)
at ucar.nc2.NetcdfFileWriter.addVariable(NetcdfFileWriter.java:518)
at gov.noaa.pfel.coastwatch.Projects.testLongInNc3(Projects.java:3237)    +5
at gov.noaa.pfel.coastwatch.TestAll.main(TestAll.java:442)
 */
public static void testLongInNc3() throws Exception {
    String2.log("\n*** Projects.testLongInNc3");

    //get a list of files
    NetcdfFileWriter newFile = null;
    String dirFileName = "/data/ethan/testLongInNc3.nc";
    try {
        newFile = NetcdfFileWriter.createNew(NetcdfFileWriter.Version.netcdf3, dirFileName);
        boolean nc3Mode = true;
        Group rootGroup = newFile.addGroup(null, "");

        //create the dimensions
        Dimension dim = newFile.addDimension(rootGroup, "row", 5);
        ArrayList<Dimension> dims = new ArrayList();
        dims.add(dim);

        ArrayList<Dimension> dimensions = new ArrayList();
        DataType dataType = DataType.LONG;

        Attributes atts = new Attributes();
        atts.set("units", "count");

        Variable var = newFile.addVariable(rootGroup, "longs", dataType, dims);
        NcHelper.setAttributes(nc3Mode, var, atts);

        //define GLOBAL metadata 
        Attributes gatts = new Attributes();
        gatts.set("title", "test of 64bit integers");
        NcHelper.setAttributes(nc3Mode, rootGroup, gatts);

        //leave define mode
        newFile.create();

        ArrayLong.D1 array = new ArrayLong.D1(5);
        array.set(0, Long.MIN_VALUE);
        array.set(0, -999);
        array.set(0, 0);
        array.set(0, 999);
        array.set(0, Long.MAX_VALUE);

        newFile.write(var, array);

        newFile.close();
        newFile = null;

        String2.log("newFile=" + NcHelper.dumpString(dirFileName, true));

        String2.log("\n*** Projects.testLongInNc3 finished successfully.");

    } catch (Exception e) {
        try {
            newFile.close();
        } catch (Exception e2) {
        }
        String2.log(MustBe.throwableToString(e));
    }
}

From source file:io.warp10.continuum.gts.GTSHelper.java

/**
 * Return the value of the most recent tick in this GTS.
 * //from  w w w. ja v a 2s .  co  m
 * @param gts GTS instance to extract value from.
 * 
 * @return
 */
public static Object getLastValue(GeoTimeSerie gts) {

    // Easy one, if the GTS has no values then value is null

    if (0 == gts.values) {
        return null;
    }

    if (isBucketized(gts)) {
        for (int i = 0; i < gts.values; i++) {
            if (gts.lastbucket == gts.ticks[i]) {
                return GTSHelper.valueAtIndex(gts, i);
            }
        }
        return null;
    } else {
        long ts = Long.MIN_VALUE;
        int idx = -1;

        for (int i = 0; i < gts.values; i++) {
            if (gts.ticks[i] > ts) {
                ts = gts.ticks[i];
                idx = i;
            }
        }

        if (-1 != idx) {
            return GTSHelper.valueAtIndex(gts, idx);
        } else {
            return null;
        }
    }
}

From source file:io.warp10.continuum.gts.GTSHelper.java

/**
 * Normalize a GTS, replacing X by (X-MIN)/(MAX-MIN) or 1.0
 * @param gts//  w w  w  .ja  va  2  s . co m
 * @return
 */
public static GeoTimeSerie normalize(GeoTimeSerie gts) {
    //
    // Return immediately if GTS is not numeric or has no values
    //
    if ((TYPE.DOUBLE != gts.getType() && TYPE.LONG != gts.getType()) || 0 == gts.values) {
        return gts.clone();
    }

    //
    // Extract min/max
    //

    double dmin = Double.POSITIVE_INFINITY;
    double dmax = Double.NEGATIVE_INFINITY;

    long lmin = Long.MAX_VALUE;
    long lmax = Long.MIN_VALUE;

    if (TYPE.LONG == gts.getType()) {
        for (int i = 0; i < gts.values; i++) {
            long value = (long) GTSHelper.valueAtIndex(gts, i);

            if (value > lmax) {
                lmax = value;
            }
            if (value < lmin) {
                lmin = value;
            }
        }
    } else {
        for (int i = 0; i < gts.values; i++) {
            double value = (double) GTSHelper.valueAtIndex(gts, i);

            if (value > dmax) {
                dmax = value;
            }
            if (value < dmin) {
                dmin = value;
            }
        }
    }

    boolean constant = false;

    if (lmin == lmax || dmin == dmax) {
        constant = true;
    }

    //
    // Don't use clone or cloneEmpty, this would force the type to that of 'gts'

    GeoTimeSerie normalized = new GeoTimeSerie(gts.lastbucket, gts.bucketcount, gts.bucketspan, gts.values);
    normalized.setName(gts.getName());
    normalized.setLabels(gts.getLabels());

    for (int i = 0; i < gts.values; i++) {
        Object value;

        if (constant) {
            value = 1.0D;
        } else if (TYPE.LONG == gts.getType()) {
            value = ((long) GTSHelper.valueAtIndex(gts, i) - lmin) / (double) (lmax - lmin);
        } else {
            value = ((double) GTSHelper.valueAtIndex(gts, i) - dmin) / (double) (dmax - dmin);
        }

        GTSHelper.setValue(normalized, gts.ticks[i], GTSHelper.locationAtIndex(gts, i),
                GTSHelper.elevationAtIndex(gts, i), value, false);
    }

    return normalized;
}

From source file:io.warp10.continuum.gts.GTSHelper.java

/**
 * Normalize a GTS, replacing X by (X-MEAN)/(MAX-MIN) or 1.0
 * @param gts/* w w w .j  a  v a 2 s  . c  om*/
 * @return
 */
public static GeoTimeSerie isonormalize(GeoTimeSerie gts) {
    //
    // Return immediately if GTS is not numeric or has no values
    //
    if ((TYPE.DOUBLE != gts.getType() && TYPE.LONG != gts.getType()) || 0 == gts.values) {
        return gts.clone();
    }

    //
    // Extract min/max
    //

    double sum = 0.0D;

    double dmin = Double.POSITIVE_INFINITY;
    double dmax = Double.NEGATIVE_INFINITY;

    long lmin = Long.MAX_VALUE;
    long lmax = Long.MIN_VALUE;

    if (TYPE.LONG == gts.getType()) {
        for (int i = 0; i < gts.values; i++) {
            long value = (long) GTSHelper.valueAtIndex(gts, i);

            if (value > lmax) {
                lmax = value;
            }
            if (value < lmin) {
                lmin = value;
            }

            sum += value;
        }
    } else {
        for (int i = 0; i < gts.values; i++) {
            double value = (double) GTSHelper.valueAtIndex(gts, i);

            if (value > dmax) {
                dmax = value;
            }
            if (value < dmin) {
                dmin = value;
            }

            sum += value;
        }
    }

    boolean constant = false;

    if (lmin == lmax || dmin == dmax) {
        constant = true;
    }

    //
    // Don't use clone or cloneEmpty, this would force the type to that of 'gts'

    GeoTimeSerie isonormalized = new GeoTimeSerie(gts.lastbucket, gts.bucketcount, gts.bucketspan, gts.values);
    isonormalized.setName(gts.getName());
    isonormalized.setLabels(gts.getLabels());

    double mean = sum / gts.values;

    for (int i = 0; i < gts.values; i++) {
        Object value;

        if (constant) {
            value = 1.0D;
        } else if (TYPE.LONG == gts.getType()) {
            value = ((long) GTSHelper.valueAtIndex(gts, i) - mean) / (double) (lmax - lmin);
        } else {
            value = ((double) GTSHelper.valueAtIndex(gts, i) - mean) / (double) (dmax - dmin);
        }

        GTSHelper.setValue(isonormalized, gts.ticks[i], GTSHelper.locationAtIndex(gts, i),
                GTSHelper.elevationAtIndex(gts, i), value, false);
    }

    return isonormalized;
}

From source file:io.warp10.continuum.gts.GTSHelper.java

public static GeoTimeSerie fuse(Collection<GeoTimeSerie> chunks) throws WarpScriptException {
    ///*from  ww w. j  a  va2 s.  co  m*/
    // Check if all chunks are of the same type
    //

    if (!chunks.isEmpty()) {

        TYPE type = null;

        int size = 0;

        for (GeoTimeSerie chunk : chunks) {
            // Set the type of the result from the type of the first chunk with
            // a defined type.
            if (null == type) {
                if (TYPE.UNDEFINED != chunk.type) {
                    type = chunk.type;
                }
                continue;
            }
            if (0 != chunk.values && type != chunk.type) {
                throw new WarpScriptException("Inconsistent types for chunks to fuse.");
            }
            size += chunk.values;
        }

        //
        // Determine if we have compatible bucketization parameters.
        // bucketspan should be the same for all chunks and lastbucket should
        // be congruent to the same value modulo bucketspan
        //

        long lastbucket = Long.MIN_VALUE;
        long bucketspan = 0L;
        long firstbucket = Long.MAX_VALUE;

        for (GeoTimeSerie chunk : chunks) {
            // If one chunk is not bucketized, exit
            if (!isBucketized(chunk)) {
                bucketspan = 0L;
                break;
            }
            if (0L == bucketspan) {
                bucketspan = chunk.bucketspan;
                lastbucket = chunk.lastbucket;
                firstbucket = lastbucket - bucketspan * (chunk.bucketcount - 1);
            } else {
                // If bucketspan is not the same as the previous one, exit, result won't be bucketized
                if (bucketspan != chunk.bucketspan) {
                    bucketspan = 0L;
                    break;
                }
                // Check if lastbucket and chunk.lastbucket are congruent to the same value modulo the bucketspan, if not result is not bucketized
                if ((lastbucket % bucketspan) != (chunk.lastbucket % bucketspan)) {
                    bucketspan = 0L;
                    break;
                }
                // Update lastbucket and firstbucket
                if (chunk.lastbucket > lastbucket) {
                    lastbucket = chunk.lastbucket;
                }
                if (chunk.lastbucket - (chunk.bucketcount - 1) * chunk.bucketspan < firstbucket) {
                    firstbucket = chunk.lastbucket - (chunk.bucketcount - 1) * chunk.bucketspan;
                }
            }
        }

        int bucketcount = 0;

        if (0L == bucketspan) {
            lastbucket = 0L;
        } else {
            // Compute bucketcount
            bucketcount = (int) (1 + ((lastbucket - firstbucket) / bucketspan));
        }

        // Create the fused GTS
        GeoTimeSerie fused = new GeoTimeSerie(lastbucket, bucketcount, bucketspan, size);

        // Merge the datapoints and jointly determine class and labels

        String classname = null;
        boolean hasClass = false;
        Map<String, String> labels = null;

        for (GeoTimeSerie chunk : chunks) {

            if (null == classname) {
                classname = chunk.getMetadata().getName();
                hasClass = true;
            } else if (!classname.equals(chunk.getMetadata().getName())) {
                hasClass = false;
            }

            Map<String, String> chunklabels = chunk.getMetadata().getLabels();

            if (null == labels) {
                labels = new HashMap<String, String>();
                labels.putAll(chunklabels);
            } else {
                // Determine the common labels of chunks
                for (Entry<String, String> entry : chunklabels.entrySet()) {
                    if (!entry.getValue().equals(labels.get(entry.getKey()))) {
                        labels.remove(entry.getKey());
                    }
                }
            }

            for (int i = 0; i < chunk.values; i++) {
                setValue(fused, GTSHelper.tickAtIndex(chunk, i), GTSHelper.locationAtIndex(chunk, i),
                        GTSHelper.elevationAtIndex(chunk, i), GTSHelper.valueAtIndex(chunk, i), false);
            }
        }

        //
        // Set labels and class
        //

        if (hasClass) {
            fused.setName(classname);
        }

        fused.setLabels(labels);

        return fused;

    }

    return new GeoTimeSerie();
}

From source file:de.innovationgate.webgate.api.WGDatabase.java

private void updateRevision(WGDatabaseRevision revision) throws WGAPIException {
    if (getSessionContext() != null && getSessionContext().isTransactionActive()) {
        return;/*from   w ww. j  ava2s  .c om*/
    }
    _revision = revision;

    if (_revision == null) {
        _revision = WGDatabaseRevision.forValue(new Date(Long.MIN_VALUE));
        _revisionDate = new Date(Long.MIN_VALUE);
    } else {
        if (_revision.getRevisionValue() instanceof Date) {
            _revisionDate = (Date) _revision.getRevisionValue();
        } else {
            _revisionDate = getCore().getRevisionDate(_revision.getRevisionValue());
        }
    }

}

From source file:io.warp10.continuum.gts.GTSHelper.java

public static int[] getFirstLastTicks(long[] ticks) {
    ////from ww  w  . j  ava  2  s . c om
    // Determine first and last ticks
    //

    long firsttick = Long.MAX_VALUE;
    long lasttick = Long.MIN_VALUE;

    int firstidx = -1;
    int lastidx = -1;

    for (int i = 0; i < ticks.length; i++) {
        if (ticks[i] < firsttick) {
            firstidx = i;
            firsttick = ticks[i];
        }
        if (ticks[i] > lasttick) {
            lastidx = i;
            lasttick = ticks[i];
        }
    }

    return new int[] { firstidx, lastidx };
}

From source file:de.innovationgate.webgate.api.WGDatabase.java

/**
 * Returns the system time where the last cache maintenance happened
 *//*w  w w  .  ja v a2 s .co m*/
public Date getLastCacheMaintenance() {
    if (lastCacheMaintenance != null) {
        return lastCacheMaintenance;
    } else {
        return new Date(Long.MIN_VALUE);
    }
}