Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*-
* #%L
* Amazon Athena Query Federation SDK
* %%
* Copyright (C) 2019 - 2020 Amazon Web Services
* %%
* 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.
* #L%
*/
package com.amazonaws.athena.connector.lambda.data;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import java.io.IOException;
import java.io.InputStream;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.Properties;
import java.util.Set;
import java.util.TreeMap;
import static java.lang.Character.isDigit;
import static java.lang.Math.abs;
import static java.lang.Math.max;
import static java.util.Locale.ENGLISH;
import static java.util.Objects.requireNonNull;
/**
* Class for representing timezone to be used in encoding datetime value and timezone value to a single long
* Source: Presto TimeZoneKey
*/
public final class TimeZoneKey
{
public static final TimeZoneKey UTC_KEY = new TimeZoneKey("UTC", (short) 0);
public static final short MAX_TIME_ZONE_KEY;
private static final Map ZONE_ID_TO_KEY;
private static final Set ZONE_KEYS;
private static final TimeZoneKey[] TIME_ZONE_KEYS;
private static final short OFFSET_TIME_ZONE_MIN = -14 * 60;
private static final short OFFSET_TIME_ZONE_MAX = 14 * 60;
private static final TimeZoneKey[] OFFSET_TIME_ZONE_KEYS = new TimeZoneKey[OFFSET_TIME_ZONE_MAX - OFFSET_TIME_ZONE_MIN + 1];
static {
try (InputStream in = TimeZoneKey.class.getResourceAsStream("zone-index.properties")) {
// load zone file
// todo parse file by hand since Properties ignores duplicate entries
Properties data = new Properties()
{
@Override
public synchronized Object put(Object key, Object value)
{
Object existingEntry = super.put(key, value);
if (existingEntry != null) {
throw new AssertionError("Zone file has duplicate entries for " + key);
}
return null;
}
};
data.load(in);
if (data.containsKey("0")) {
throw new AssertionError("Zone file should not contain a mapping for key 0");
}
Map zoneIdToKey = new TreeMap<>();
zoneIdToKey.put(UTC_KEY.getId().toLowerCase(ENGLISH), UTC_KEY);
short maxZoneKey = 0;
for (Entry