001: /**
002: * Objective Database Abstraction Layer (ODAL)
003: * Copyright (c) 2004, The ODAL Development Group
004: * All rights reserved.
005: * For definition of the ODAL Development Group please refer to LICENCE.txt file
006: *
007: * Distributable under LGPL license.
008: * See terms of license at gnu.org.
009: */package com.completex.objective.components.persistency;
010:
011: import java.util.ArrayList;
012:
013: /**
014: * Parameter collection
015: *
016: * @author Gennady Krizhevsky
017: * @see Parameter
018: */
019: public class Parameters extends AbstractParameters {
020:
021: public Parameters() {
022: }
023:
024: /**
025: * @see AbstractParameters#AbstractParameters(int)
026: */
027: public Parameters(int capacity) {
028: super (capacity);
029: }
030:
031: /**
032: * Constructs Parameters from array of values.
033: * If the array element is of Parameter type it is simply added,
034: * ff not then new parameter with null column type gets created and added to this collection.
035: *
036: * @param parameters
037: */
038: public Parameters(Object[] parameters) {
039: if (parameters == null) {
040: this .parameters = new ArrayList();
041: } else {
042: this .parameters = new ArrayList(parameters.length);
043: for (int i = 0; i < parameters.length; i++) {
044: add(parameters[i]);
045: }
046: }
047: }
048:
049: /**
050: * Constructs new parameters collection from Parameter []
051: *
052: * @param parameters Parameter []
053: */
054: public Parameters(Parameter[] parameters) {
055: super (parameters);
056: }
057:
058: /**
059: * @see AbstractParameters#AbstractParameters(AbstractParameters)
060: */
061: public Parameters(Parameters parameters) {
062: super (parameters);
063: }
064:
065: /**
066: * @see AbstractParameters#addAll(AbstractParameters)
067: */
068: public void addAll(Parameters argParameters) {
069: super .addAll(argParameters);
070: }
071:
072: /**
073: * Appends all of the parameters in the specified argParameters to the end of
074: * this collection
075: *
076: * @param argParameters the parameters to be inserted into this collection.
077: */
078: public void addAll(Object[] argParameters) {
079: if (argParameters != null) {
080: for (int i = 0; i < argParameters.length; i++) {
081: add(argParameters[i]);
082: }
083: }
084: }
085:
086: /**
087: * Inserts all of the elements in the specified Collection into this
088: * collection, starting at the specified position. Shifts the element
089: * currently at that position (if any) and any subsequent elements to
090: * the right (increases their indices).
091: *
092: * @param index index at which to insert first element
093: * from the specified collection.
094: * @param argParameters the parameters to be inserted into this collection.
095: */
096: public void addAll(int index, Parameters argParameters) {
097: parameters.addAll(index, argParameters.parameters);
098: }
099:
100: /**
101: * <p> Appends value to end of this collection.
102: *
103: * @param type type column type of the field this parameter corresponds to
104: * @param value value of this parameter or instance of Parameter class.
105: * @return added Parameter
106: * @throws OdalRuntimePersistencyException
107: * if the value is already of Parameter type and type != null
108: */
109: public Parameter add(ColumnType type, Object value) {
110: if (type == null) {
111: return add(value);
112: } else {
113: assertValueNotParameter(value);
114: return add0(type, value);
115: }
116: }
117:
118: /**
119: * <p> Appends value to parameter collection. If value is of Parameter class - adds it,
120: * otherwise - creates new Parameter with null type and adds it to the end of this collection.
121: *
122: * @param value value of this parameter.
123: * @return added Parameter or value if it is of Parameter class
124: */
125: public Parameter add(Object value) {
126: Parameter parameter;
127: if (value instanceof Parameter) {
128: parameters.add(value);
129: parameter = (Parameter) value;
130: } else {
131: parameter = add0(null, value);
132: }
133: return parameter;
134: }
135:
136: /**
137: * <p> Appends value to end of this collection.
138: *
139: * @param type type column type of the field this parameter corresponds to
140: * @param value value of this parameter.
141: * @return added Parameter
142: */
143: protected Parameter add0(ColumnType type, Object value) {
144: Parameter parameter = createParameter(type, value);
145: parameters.add(parameter);
146: return parameter;
147: }
148:
149: /**
150: * Factory method
151: *
152: * @param type type column type of the field this parameter corresponds to
153: * @param value value of this parameter.
154: * @return new Parameter
155: */
156: protected Parameter createParameter(ColumnType type, Object value) {
157: return new Parameter(type, value);
158: }
159:
160: public String toString() {
161: return super.toString();
162: }
163:
164: }
|