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.
/*******************************************************************************
* Copyright (c) 2018, TechEmpower, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name TechEmpower, Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL TECHEMPOWER, INC. BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
package com.techempower.util;
import java.io.*;
import java.net.*;
import java.nio.charset.*;
import java.util.*;
import java.util.Map.Entry;
import com.techempower.*;
import com.techempower.collection.*;
import com.techempower.helper.*;
/**
* Similar to the standard Java Properties class but tuned for configuration
* files containing named strings (key-value mappings where the values are
* strings). The value strings can then be parsed by convenience methods
* into integers, longs, and booleans.
*
* EnhancedProperties supports simple macro-expansion using ${PropName}
* syntax.
*
* A focused view limited to only property names that begin with a specified
* prefix can be created using the focus() method.
*/
public class EnhancedProperties
implements MutableNamedValues
{
//
// Constants.
//
public static final String MACRO_START = "${";
public static final String MACRO_END = "}";
//
// Member variables.
//
private final transient TechEmpowerApplication application;
private final Properties backing;
//
// Member methods.
//
/**
* Constructor. Takes in a reference to a TechEmpower application.
*/
public EnhancedProperties(TechEmpowerApplication application)
{
this.application = application;
this.backing = new Properties();
}
/**
* Basic constructor.
*/
public EnhancedProperties()
{
this(null);
}
/**
* Gets the TechEmpowerApplication reference.
*/
public TechEmpowerApplication getApplication()
{
return this.application;
}
/**
* Gets the backing Properties reference. This is not recommended but is
* enabled for legacy applications.
*
* @deprecated This should not be used in new applications.
*/
@Deprecated
public Properties getBackingProperties()
{
return backing;
}
/**
* Store an arbitrary object.
*/
private EnhancedProperties putObject(String name, Object value)
{
backing.put(name, value);
return this;
}
@Override
public EnhancedProperties put(String name, String value)
{
return putObject(name, value);
}
@Override
public EnhancedProperties put(String name, int value)
{
return putObject(name, Integer.toString(value));
}
@Override
public EnhancedProperties put(String name, long value)
{
return putObject(name, Long.toString(value));
}
@Override
public EnhancedProperties put(String name, boolean value)
{
return putObject(name, Boolean.toString(value));
}
@Override
public EnhancedProperties remove(String name)
{
backing.remove(name);
return this;
}
@Override
public EnhancedProperties clear()
{
backing.clear();
return this;
}
@Override
public String get(String name)
{
return getBackingProperty(name);
}
@Override
public String get(String name, String defaultValue)
{
return getBackingProperty(name, defaultValue);
}
@Override
public Set names()
{
final Set