All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.logspace.agent.shaded.quartz.utils.StringKeyDirtyFlagMap Maven / Gradle / Ivy

There is a newer version: 0.3.2
Show newest version
/* 
 * Copyright 2001-2009 Terracotta, Inc. 
 * 
 * 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.
 */
package io.logspace.agent.shaded.quartz.utils;

import java.io.Serializable;

/**
 * 

* An implementation of Map that wraps another Map * and flags itself 'dirty' when it is modified, enforces that all keys are * Strings. *

* *

* All allowsTransientData flag related methods are deprecated as of version 1.6. *

*/ public class StringKeyDirtyFlagMap extends DirtyFlagMap { static final long serialVersionUID = -9076749120524952280L; /** * @deprecated JDBCJobStores no longer prune out transient data. If you * include non-Serializable values in the Map, you will now get an * exception when attempting to store it in a database. */ private boolean allowsTransientData = false; public StringKeyDirtyFlagMap() { super(); } public StringKeyDirtyFlagMap(int initialCapacity) { super(initialCapacity); } public StringKeyDirtyFlagMap(int initialCapacity, float loadFactor) { super(initialCapacity, loadFactor); } @Override public boolean equals(Object obj) { return super.equals(obj); } @Override public int hashCode() { return getWrappedMap().hashCode(); } /** * Get a copy of the Map's String keys in an array of Strings. */ public String[] getKeys() { return keySet().toArray(new String[size()]); } /** * Tell the StringKeyDirtyFlagMap that it should * allow non-Serializable values. Enforces that the Map * doesn't already include transient data. * * @deprecated JDBCJobStores no longer prune out transient data. If you * include non-Serializable values in the Map, you will now get an * exception when attempting to store it in a database. */ public void setAllowsTransientData(boolean allowsTransientData) { if (containsTransientData() && !allowsTransientData) { throw new IllegalStateException( "Cannot set property 'allowsTransientData' to 'false' " + "when data map contains non-serializable objects."); } this.allowsTransientData = allowsTransientData; } /** * Whether the StringKeyDirtyFlagMap allows * non-Serializable values. * * @deprecated JDBCJobStores no longer prune out transient data. If you * include non-Serializable values in the Map, you will now get an * exception when attempting to store it in a database. */ public boolean getAllowsTransientData() { return allowsTransientData; } /** * Determine whether any values in this Map do not implement * Serializable. Always returns false if this Map * is flagged to not allow transient data. * * @deprecated JDBCJobStores no longer prune out transient data. If you * include non-Serializable values in the Map, you will now get an * exception when attempting to store it in a database. */ public boolean containsTransientData() { if (!getAllowsTransientData()) { // short circuit... return false; } String[] keys = getKeys(); for (int i = 0; i < keys.length; i++) { Object o = super.get(keys[i]); if (!(o instanceof Serializable)) { return true; } } return false; } /** * Removes any data values in the map that are non-Serializable. Does * nothing if this Map does not allow transient data. * * @deprecated JDBCJobStores no longer prune out transient data. If you * include non-Serializable values in the Map, you will now get an * exception when attempting to store it in a database. */ public void removeTransientData() { if (!getAllowsTransientData()) { // short circuit... return; } String[] keys = getKeys(); for (int i = 0; i < keys.length; i++) { Object o = super.get(keys[i]); if (!(o instanceof Serializable)) { remove(keys[i]); } } } // Due to Generic enforcement, this override method is no longer needed. // /** // *

// * Adds the name-value pairs in the given Map to the // * StringKeyDirtyFlagMap. // *

// * // *

// * All keys must be Strings. // *

// */ // @Override // public void putAll(Map map) { // for (Iterator entryIter = map.entrySet().iterator(); entryIter.hasNext();) { // Map.Entry entry = (Map.Entry) entryIter.next(); // // // will throw IllegalArgumentException if key is not a String // put(entry.getKey(), entry.getValue()); // } // } /** *

* Adds the given int value to the StringKeyDirtyFlagMap. *

*/ public void put(String key, int value) { super.put(key, Integer.valueOf(value)); } /** *

* Adds the given long value to the StringKeyDirtyFlagMap. *

*/ public void put(String key, long value) { super.put(key, Long.valueOf(value)); } /** *

* Adds the given float value to the StringKeyDirtyFlagMap. *

*/ public void put(String key, float value) { super.put(key, Float.valueOf(value)); } /** *

* Adds the given double value to the StringKeyDirtyFlagMap. *

*/ public void put(String key, double value) { super.put(key, Double.valueOf(value)); } /** *

* Adds the given boolean value to the StringKeyDirtyFlagMap. *

*/ public void put(String key, boolean value) { super.put(key, Boolean.valueOf(value)); } /** *

* Adds the given char value to the StringKeyDirtyFlagMap. *

*/ public void put(String key, char value) { super.put(key, Character.valueOf(value)); } /** *

* Adds the given String value to the StringKeyDirtyFlagMap. *

*/ public void put(String key, String value) { super.put(key, value); } /** *

* Adds the given Object value to the StringKeyDirtyFlagMap. *

*/ @Override public Object put(String key, Object value) { return super.put((String)key, value); } /** *

* Retrieve the identified int value from the StringKeyDirtyFlagMap. *

* * @throws ClassCastException * if the identified object is not an Integer. */ public int getInt(String key) { Object obj = get(key); try { if(obj instanceof Integer) return ((Integer) obj).intValue(); return Integer.parseInt((String)obj); } catch (Exception e) { throw new ClassCastException("Identified object is not an Integer."); } } /** *

* Retrieve the identified long value from the StringKeyDirtyFlagMap. *

* * @throws ClassCastException * if the identified object is not a Long. */ public long getLong(String key) { Object obj = get(key); try { if(obj instanceof Long) return ((Long) obj).longValue(); return Long.parseLong((String)obj); } catch (Exception e) { throw new ClassCastException("Identified object is not a Long."); } } /** *

* Retrieve the identified float value from the StringKeyDirtyFlagMap. *

* * @throws ClassCastException * if the identified object is not a Float. */ public float getFloat(String key) { Object obj = get(key); try { if(obj instanceof Float) return ((Float) obj).floatValue(); return Float.parseFloat((String)obj); } catch (Exception e) { throw new ClassCastException("Identified object is not a Float."); } } /** *

* Retrieve the identified double value from the StringKeyDirtyFlagMap. *

* * @throws ClassCastException * if the identified object is not a Double. */ public double getDouble(String key) { Object obj = get(key); try { if(obj instanceof Double) return ((Double) obj).doubleValue(); return Double.parseDouble((String)obj); } catch (Exception e) { throw new ClassCastException("Identified object is not a Double."); } } /** *

* Retrieve the identified boolean value from the StringKeyDirtyFlagMap. *

* * @throws ClassCastException * if the identified object is not a Boolean. */ public boolean getBoolean(String key) { Object obj = get(key); try { if(obj instanceof Boolean) return ((Boolean) obj).booleanValue(); return Boolean.parseBoolean((String)obj); } catch (Exception e) { throw new ClassCastException("Identified object is not a Boolean."); } } /** *

* Retrieve the identified char value from the StringKeyDirtyFlagMap. *

* * @throws ClassCastException * if the identified object is not a Character. */ public char getChar(String key) { Object obj = get(key); try { if(obj instanceof Character) return ((Character) obj).charValue(); return ((String)obj).charAt(0); } catch (Exception e) { throw new ClassCastException("Identified object is not a Character."); } } /** *

* Retrieve the identified String value from the StringKeyDirtyFlagMap. *

* * @throws ClassCastException * if the identified object is not a String. */ public String getString(String key) { Object obj = get(key); try { return (String) obj; } catch (Exception e) { throw new ClassCastException("Identified object is not a String."); } } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy