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 2013-2014 Richard M. Hightower
* 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.
*
* __________ _____ __ .__
* \______ \ ____ ____ ____ /\ / \ _____ | | _|__| ____ ____
* | | _// _ \ / _ \ / \ \/ / \ / \\__ \ | |/ / |/ \ / ___\
* | | ( <_> | <_> ) | \ /\ / Y \/ __ \| <| | | \/ /_/ >
* |______ /\____/ \____/|___| / \/ \____|__ (____ /__|_ \__|___| /\___ /
* \/ \/ \/ \/ \/ \//_____/
* ____. ___________ _____ ______________.___.
* | |____ ___ _______ \_ _____/ / _ \ / _____/\__ | |
* | \__ \\ \/ /\__ \ | __)_ / /_\ \ \_____ \ / | |
* /\__| |/ __ \\ / / __ \_ | \/ | \/ \ \____ |
* \________(____ /\_/ (____ / /_______ /\____|__ /_______ / / ______|
* \/ \/ \/ \/ \/ \/
*/
package org.boon;
import org.boon.core.Typ;
import org.boon.core.Type;
import org.boon.core.reflection.BeanUtils;
import org.boon.core.Conversions;
import org.boon.core.reflection.MapObjectConversion;
import org.boon.primitive.CharBuf;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentSkipListMap;
import static org.boon.Exceptions.die;
import static org.boon.Exceptions.requireNonNull;
public class Maps {
public static List lazyCreate( List lazy ) {
if (lazy == null) {
lazy = new ArrayList<>();
}
return lazy;
}
public static Map lazyCreate( Map lazy ) {
if (lazy == null) {
lazy = new LinkedHashMap();
}
return lazy;
}
public static Map lazyCreate( HashMap lazy ) {
if (lazy == null) {
lazy = new HashMap();
}
return lazy;
}
public static Map lazyCreate( LinkedHashMap lazy ) {
if (lazy == null) {
lazy = new LinkedHashMap();
}
return lazy;
}
public static Map lazyCreateLinked( Map lazy ) {
if (lazy == null) {
lazy = new LinkedHashMap();
}
return lazy;
}
public static Map lazyCreate( ConcurrentHashMap lazy ) {
if (lazy == null) {
lazy = new ConcurrentHashMap();
}
return lazy;
}
public static Map lazyCreateSafe( Map lazy ) {
if (lazy == null) {
lazy = new ConcurrentHashMap();
}
return lazy;
}
@Universal
public static int lengthOf( Map, ?> map ) {
return len ( map );
}
@Universal
public static V atIndex( Map map, K k ) {
return idx(map, k );
}
@Universal
public static SortedMap sliceOf( NavigableMap map, K startIndex, K endIndex ) {
return slc(map, startIndex, endIndex);
}
@Universal
public static SortedMap endSliceOf( NavigableMap map, K fromKey ) {
return slcEnd(map, fromKey);
}
/**
* Universal methods.
*/
@Universal
public static int len( Map, ?> map ) {
return map.size();
}
@Universal
public static boolean in( K key, Map map ) {
return map.containsKey( key );
}
@Universal
public static void add( Map map, Entry entry ) {
map.put( entry.key(), entry.value() );
}
@Universal
public static V idx( Map map, K k ) {
return map.get( k );
}
@Universal
public static void idx( Map map, K k, V v ) {
map.put( k, v );
}
public static String idxStr( Map map, K k ) {
return (String)map.get( k );
}
public static Integer idxInt( Map map, K k ) {
return (Integer)map.get( k );
}
public static Long idxLong( Map map, K k ) {
return (Long)map.get( k );
}
public static Map idxMap( Map map, K k ) {
return (Map) map.get( k );
}
public static List idxList( Map map, K k ) {
return (List) map.get( k );
}
public static long toLong( Map map, K key ) {
V value = map.get(key);
long l = Conversions.toLong ( value, Long.MIN_VALUE );
if ( l == Long.MIN_VALUE ) {
die("Cannot convert", key, "into long value", value);
}
return l;
}
public static int toInt( Map map, K key ) {
V value = map.get(key);
int v = Conversions.toInt ( value, Integer.MIN_VALUE );
if ( v == Integer.MIN_VALUE ) {
die("Cannot convert", key, "into int value", value);
}
return v;
}
@Universal
public static SortedMap copy( SortedMap map ) {
if ( map instanceof TreeMap ) {
return new TreeMap<>( map );
} else if ( map instanceof ConcurrentSkipListMap ) {
return new ConcurrentSkipListMap<>( map );
} else {
return new TreeMap<>( map );
}
}
@Universal
public static Map copy( Map map ) {
if ( map instanceof LinkedHashMap ) {
return new LinkedHashMap<>( map );
} else if ( map instanceof ConcurrentHashMap ) {
return new ConcurrentHashMap<>( map );
} else {
return new LinkedHashMap<>( map );
}
}
/** Grabs the first value from a tree map (Navigable map). */
@Universal
public static V first( NavigableMap map ) {
return map.firstEntry().getValue();
}
/** Grabs the last value from a tree map (Navigable map). */
@Universal
public static V last( NavigableMap map ) {
return map.lastEntry().getValue() ;
}
/** Grabs the value after this key from a tree map (Navigable map). */
@Universal
public static V after( NavigableMap map, final K index ) {
return map.get( map.higherKey( index ) );
}
/** Grabs the value before this key from a tree map (Navigable map). */
@Universal
public static V before( NavigableMap map, final K index ) {
return map.get( map.lowerKey( index ) );
}
@Universal
public static SortedMap slc( NavigableMap map, K startIndex, K endIndex ) {
return map.subMap( startIndex, endIndex );
}
@Universal
public static SortedMap slcEnd( NavigableMap map, K fromKey ) {
return map.tailMap( fromKey );
}
@Universal
public static SortedMap slc( NavigableMap map, K toKey ) {
return map.headMap( toKey );
}
/**
* End universal methods.
*/
public static boolean valueIn( V value, Map map ) {
return map.containsValue( value );
}
public static Entry entry( final K k, final V v ) {
return new Pair<>( k, v );
}
public static Entry entry( Entry entry ) {
return new Pair<>( entry );
}
public static Map, ?> mapFromArray( Object... args ) {
Map