Skip to content

Commit

Permalink
feat: List support and typesafety for EnvironmentVariableList (#44)
Browse files Browse the repository at this point in the history
Signed-off-by: Jesse Gorzinski <17914061+ThePrez@users.noreply.github.com>
  • Loading branch information
ThePrez authored Apr 28, 2023
1 parent 64d3858 commit 4c152c1
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions src/main/java/com/ibm/as400/access/EnvironmentVariableList.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@
import java.beans.PropertyVetoException;
import java.io.IOException;
import java.io.Serializable;
import java.util.Collections;
import java.util.Enumeration;
import java.util.LinkedList;
import java.util.List;
import java.util.Properties;
import java.util.Vector;

Expand Down Expand Up @@ -113,7 +116,21 @@ public void addPropertyChangeListener(PropertyChangeListener listener)
@exception IOException If an error occurs while communicating with the system.
@exception ObjectDoesNotExistException If the object does not exist on the system.
**/
public Enumeration getEnvironmentVariables() throws AS400SecurityException, ErrorCompletingRequestException, InterruptedException, IOException, ObjectDoesNotExistException
public Enumeration<EnvironmentVariable> getEnvironmentVariables() throws AS400SecurityException, ErrorCompletingRequestException, InterruptedException, IOException, ObjectDoesNotExistException
{
return Collections.enumeration(getEnvironmentVariablesList());
}

/**
Returns an List that contains an EnvironmentVariable object for each environment variable on the system.
* @return List of environment variables
@exception AS400SecurityException If a security or authority error occurs.
@exception ErrorCompletingRequestException If an error occurs before the request is completed.
@exception InterruptedException If this thread is interrupted.
@exception IOException If an error occurs while communicating with the system.
@exception ObjectDoesNotExistException If the object does not exist on the system.
**/
public List<EnvironmentVariable> getEnvironmentVariablesList() throws AS400SecurityException, ErrorCompletingRequestException, InterruptedException, IOException, ObjectDoesNotExistException
{
if (Trace.traceOn_) Trace.log(Trace.DIAGNOSTIC, "Getting environment variables.");
if (spc_ == null)
Expand Down Expand Up @@ -155,11 +172,11 @@ public Enumeration getEnvironmentVariables() throws AS400SecurityException, Erro
// If ENOENT is returned, then there are no environment variables.
else if (rv == EnvironmentVariable.RV_ENOENT)
{
return new Vector().elements();
return new LinkedList<EnvironmentVariable>();
}

// Build up a Vector of EnvironmentVariable objects.
Vector list = new Vector();
// Build up a List of EnvironmentVariable objects.
List<EnvironmentVariable> list = new LinkedList<EnvironmentVariable>();
int offsetIntoListBuffer = 0;
int offsetIntoCcsidBuffer = 0;
byte[] listBufferBytes = parameters[0].getOutputData();
Expand All @@ -186,7 +203,7 @@ else if (rv == EnvironmentVariable.RV_ENOENT)
int ccsid = BinaryConverter.byteArrayToInt(ccsidBufferBytes, offsetIntoCcsidBuffer);

// Create the EnvironmentVariable object, add it to vector.
list.addElement(new EnvironmentVariable(system_, spc_, nameBytes, valueBytes, ccsid));
list.add(new EnvironmentVariable(system_, spc_, nameBytes, valueBytes, ccsid));

// Get ready for the next iteration.
offsetIntoListBuffer = nullPosition + 1;
Expand All @@ -195,7 +212,7 @@ else if (rv == EnvironmentVariable.RV_ENOENT)
// Until ending null terminator.
} while (listBufferBytes[offsetIntoListBuffer] != 0);

return list.elements();
return list;
}

/**
Expand Down

0 comments on commit 4c152c1

Please sign in to comment.