dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #37669
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 19229: ConversionUtils, removed obsolete methods
------------------------------------------------------------
revno: 19229
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2015-06-01 22:07:22 +0200
message:
ConversionUtils, removed obsolete methods
removed:
dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/util/ConversionUtilsTest.java
modified:
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DefaultDataValueSetService.java
dhis-2/dhis-support/dhis-support-commons/src/main/java/org/hisp/dhis/util/ConversionUtils.java
dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/imp/ImportAction.java
--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DefaultDataValueSetService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DefaultDataValueSetService.java 2015-06-01 19:49:10 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DefaultDataValueSetService.java 2015-06-01 20:07:22 +0000
@@ -35,7 +35,6 @@
import static org.hisp.dhis.system.notification.NotificationLevel.INFO;
import static org.hisp.dhis.system.util.DateUtils.getDefaultDate;
import static org.hisp.dhis.system.util.DateUtils.parseDate;
-import static org.hisp.dhis.util.ConversionUtils.wrap;
import java.io.InputStream;
import java.io.OutputStream;
@@ -99,6 +98,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import com.csvreader.CsvReader;
+import com.google.common.collect.Sets;
/**
* @author Lars Helge Overland
@@ -197,8 +197,8 @@
period_ = periodService.reloadPeriod( period_ );
- dataValueSetStore.writeDataValueSetXml( newHashSet( dataSet_ ), completeDate, period_, orgUnit_, wrap( period_ ),
- wrap( orgUnit_ ), out, idSchemes );
+ dataValueSetStore.writeDataValueSetXml( newHashSet( dataSet_ ), completeDate, period_, orgUnit_, Sets.newHashSet( period_ ),
+ Sets.newHashSet( orgUnit_ ), out, idSchemes );
}
@Override
@@ -263,8 +263,8 @@
period_ = periodService.reloadPeriod( period_ );
- dataValueSetStore.writeDataValueSetJson( newHashSet( dataSet_ ), completeDate, period_, orgUnit_, wrap( period_ ),
- wrap( orgUnit_ ), outputStream, idSchemes );
+ dataValueSetStore.writeDataValueSetJson( newHashSet( dataSet_ ), completeDate, period_, orgUnit_, Sets.newHashSet( period_ ),
+ Sets.newHashSet( orgUnit_ ), outputStream, idSchemes );
}
@Override
@@ -335,8 +335,8 @@
period_ = periodService.reloadPeriod( period_ );
- dataValueSetStore.writeDataValueSetCsv( newHashSet( dataSet_ ), completeDate, period_, orgUnit_, wrap( period_ ),
- wrap( orgUnit_ ), writer, idSchemes );
+ dataValueSetStore.writeDataValueSetCsv( newHashSet( dataSet_ ), completeDate, period_, orgUnit_, Sets.newHashSet( period_ ),
+ Sets.newHashSet( orgUnit_ ), writer, idSchemes );
}
@Override
=== modified file 'dhis-2/dhis-support/dhis-support-commons/src/main/java/org/hisp/dhis/util/ConversionUtils.java'
--- dhis-2/dhis-support/dhis-support-commons/src/main/java/org/hisp/dhis/util/ConversionUtils.java 2015-05-21 15:20:54 +0000
+++ dhis-2/dhis-support/dhis-support-commons/src/main/java/org/hisp/dhis/util/ConversionUtils.java 2015-06-01 20:07:22 +0000
@@ -31,11 +31,7 @@
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collection;
-import java.util.HashMap;
-import java.util.HashSet;
import java.util.List;
-import java.util.Map;
-import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -76,57 +72,6 @@
}
/**
- * Creates a collection of the identifiers of the objects passed as argument.
- * The object are assumed to have a <code>int getId()</code> method.
- *
- * @param clazz the clazz of the argument objects.
- * @param objects for which to get the identifiers.
- */
- public static Collection<String> getUids( Class<?> clazz, Collection<?> objects )
- {
- try
- {
- Collection<String> identifiers = new ArrayList<>();
-
- Method method = clazz.getMethod( "getUid", new Class[0] );
-
- for ( Object object : objects )
- {
- String identifier = (String) method.invoke( object, new Object[0] );
-
- identifiers.add( identifier );
- }
-
- return identifiers;
- }
- catch ( Exception ex )
- {
- throw new RuntimeException( "Failed to convert objects", ex );
- }
- }
-
- /**
- * Returns the identifier of the argument object. The object is assumed to
- * have a <code>int getId()</code> method.
- *
- * @param object the object.
- * @return the identifier of the argument object.
- */
- public static Integer getIdentifier( Object object )
- {
- try
- {
- Method method = object.getClass().getMethod( "getId", new Class[0] );
-
- return (Integer) method.invoke( object, new Object[0] );
- }
- catch ( Exception ex )
- {
- throw new RuntimeException( "Failed to convert object", ex );
- }
- }
-
- /**
* Creates a collection of Integers out of a collection of Strings.
*
* @param strings the collection of Strings.
@@ -148,119 +93,6 @@
}
/**
- * Creates an array of Integers out of an array of Strings.
- *
- * @param strings the array of Strings.
- * @return an array of Integers, an empty array if input is null.
- */
- public static Integer[] getIntegerArray( String[] strings )
- {
- if ( strings == null )
- {
- return new Integer[0];
- }
-
- Integer[] integers = new Integer[strings.length];
-
- for ( int i = 0; i < strings.length; i++ )
- {
- integers[i] = Integer.valueOf( strings[i] );
- }
- return integers;
- }
-
- /**
- * Parses the string argument as a signed decimal integer. Null is returedn
- * if the argument is null or has zero length.
- *
- * @param string the string to parse.
- * @return an integer or null.
- */
- public static Integer parseInt( String string )
- {
- if ( string == null || string.isEmpty() )
- {
- return null;
- }
-
- return Integer.parseInt( string );
- }
-
- /**
- * Creates a Set of objects out of a Collection of objects.
- *
- * @param objects the Collection of objects.
- * @return a Set of objects.
- */
- public static <T> Set<T> getSet( Collection<T> objects )
- {
- Set<T> set = new HashSet<>();
-
- for ( T object : objects )
- {
- set.add( object );
- }
-
- return set;
- }
-
- /**
- * Creates a List of objects out of a Collection of objects.
- *
- * @param objects the Collection of objects.
- * @return a List of objects.
- */
- public static <T> List<T> getList( Collection<T> objects )
- {
- List<T> list = new ArrayList<>();
-
- for ( T object : objects )
- {
- list.add( object );
- }
-
- return list;
- }
-
- /**
- * Creates a List out of an array of objects.
- *
- * @param objects the array of objects.
- * @return a List of objects.
- */
- @SafeVarargs
- public static final <T> List<T> getList( final T... objects )
- {
- final List<T> list = new ArrayList<>();
-
- for ( T object : objects )
- {
- list.add( object );
- }
-
- return list;
- }
-
- /**
- * Returns a Map based on an argument Collection of objects where the key is
- * the object identifier and the value if the object itself.
- *
- * @param collection the Collection of objects.
- * @return a Map with identifier object pairs.
- */
- public static <T> Map<Integer, T> getIdentifierMap( Collection<T> collection )
- {
- Map<Integer, T> map = new HashMap<>();
-
- for ( T object : collection )
- {
- map.put( getIdentifier( object ), object );
- }
-
- return map;
- }
-
- /**
* Converts a List<Double> into a double[].
*
* @param list the List.
@@ -300,37 +132,4 @@
return null;
}
-
- /**
- * Wraps an object in a set.
- *
- * @param object the object to wrap.
- * @return a set with the given object as element.
- */
- public static <T> Set<T> wrap( T object )
- {
- Set<T> set = new HashSet<>();
- set.add( object );
- return set;
- }
-
- /**
- * Casts the elements in the given collection to the desired return type. It
- * is the caller's responsibility that the types legally can be casted.
- *
- * @param collection the collection.
- * @return a collection.
- */
- @SuppressWarnings("unchecked")
- public static <T> Collection<T> cast( Collection<? super T> collection )
- {
- Collection<T> list = new ArrayList<>();
-
- for ( Object o : collection )
- {
- list.add( (T) o );
- }
-
- return list;
- }
}
=== removed file 'dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/util/ConversionUtilsTest.java'
--- dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/util/ConversionUtilsTest.java 2015-05-28 14:33:21 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/util/ConversionUtilsTest.java 1970-01-01 00:00:00 +0000
@@ -1,59 +0,0 @@
-package org.hisp.dhis.system.util;
-
-/*
- * Copyright (c) 2004-2015, University of Oslo
- * 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 of the HISP project 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 THE COPYRIGHT OWNER OR CONTRIBUTORS 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.
- */
-
-import static org.junit.Assert.assertEquals;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.hisp.dhis.util.ConversionUtils;
-import org.junit.Test;
-
-/**
- * @author Lars Helge Overland
- */
-public class ConversionUtilsTest
-{
- @Test
- public void getArray()
- {
- List<Double> list = new ArrayList<>();
- list.add( 1.0 );
- list.add( 2.0 );
- list.add( 3.0 );
-
- double[] array = ConversionUtils.getArray( list );
-
- assertEquals( 3, array.length );
- assertEquals( 1.0, array[0], 0.01 );
- assertEquals( 2.0, array[1], 0.01 );
- assertEquals( 3.0, array[2], 0.01 );
- }
-}
=== modified file 'dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/imp/ImportAction.java'
--- dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/imp/ImportAction.java 2015-05-28 16:10:07 +0000
+++ dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/imp/ImportAction.java 2015-06-01 20:07:22 +0000
@@ -31,7 +31,6 @@
import static org.hisp.dhis.importexport.action.util.ImportExportInternalProcessUtil.getCurrentRunningProcessImportFormat;
import static org.hisp.dhis.importexport.action.util.ImportExportInternalProcessUtil.setCurrentImportFileName;
import static org.hisp.dhis.importexport.action.util.ImportExportInternalProcessUtil.setCurrentRunningProcessType;
-import static org.hisp.dhis.util.ConversionUtils.getList;
import static org.hisp.dhis.util.InternalProcessUtil.PROCESS_KEY_IMPORT;
import static org.hisp.dhis.util.InternalProcessUtil.setCurrentRunningProcess;
@@ -53,6 +52,7 @@
import org.hisp.dhis.system.util.DateUtils;
import org.hisp.dhis.user.CurrentUserService;
+import com.google.common.collect.Lists;
import com.opensymphony.xwork2.Action;
/**
@@ -66,7 +66,7 @@
private static final Log log = LogFactory.getLog( ImportAction.class );
- private static final List<String> ALLOWED_CONTENT_TYPES = getList( "application/x-zip-compressed",
+ private static final List<String> ALLOWED_CONTENT_TYPES = Lists.newArrayList( "application/x-zip-compressed",
"application/zip", "application/x-gzip", "application/octet-stream",
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "text/xml" );