Java Code Examples for org.apache.commons.lang.ArrayUtils#add()

The following examples show how to use org.apache.commons.lang.ArrayUtils#add() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ConfigValidatorImpl.java    From freehealth-connector with GNU Affero General Public License v3.0 6 votes vote down vote up
private boolean validate() {
   this.unfoundProps = new Object[0];
   Iterator i$ = this.expectedProps.iterator();

   while(i$.hasNext()) {
      String prop = (String)i$.next();
      boolean validProp = this.config.containsKey(prop);
      boolean validMatchProp = this.config.containsKey(prop + ".1");
      if (validProp || validMatchProp) {
         validProp = true;
      }

      if (!validProp) {
         LOG.warn("Could not find property:" + prop);
         this.unfoundProps = ArrayUtils.add(this.unfoundProps, prop);
      }
   }

   return ArrayUtils.isEmpty(this.unfoundProps);
}
 
Example 2
Source File: ValidatorHelper.java    From freehealth-connector with GNU Affero General Public License v3.0 6 votes vote down vote up
protected static ValidatorHandler createValidatorForSchemaFiles(String... schemaFiles) throws TechnicalConnectorException {
   SchemaFactory schemaFactory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");

   try {
      Source[] sources = new Source[0];

      for(int i = 0; i < schemaFiles.length; ++i) {
         String schemaFile = schemaFiles[i];
         InputStream in = SchemaValidatorHandler.class.getResourceAsStream(schemaFile);
         if (in == null) {
            throw new TechnicalConnectorException(TechnicalConnectorExceptionValues.ERROR_XML_INVALID, new Object[]{"Unable to find schemaFile " + schemaFile});
         }

         if (schemaFiles.length == 1) {
            sources = (Source[])((Source[])ArrayUtils.add(sources, new StreamSource(SchemaValidatorHandler.class.getResource(schemaFile).toExternalForm())));
         } else {
            Source source = new StreamSource(in);
            sources = (Source[])((Source[])ArrayUtils.add(sources, source));
         }
      }

      return schemaFactory.newSchema(sources).newValidatorHandler();
   } catch (Exception var7) {
      throw handleException(var7);
   }
}
 
Example 3
Source File: ConfigValidatorImpl.java    From freehealth-connector with GNU Affero General Public License v3.0 6 votes vote down vote up
private boolean validate() {
   this.unfoundProps = new Object[0];
   Iterator i$ = this.expectedProps.iterator();

   while(i$.hasNext()) {
      String prop = (String)i$.next();
      boolean validProp = this.config.containsKey(prop);
      boolean validMatchProp = this.config.containsKey(prop + ".1");
      if (validProp || validMatchProp) {
         validProp = true;
      }

      if (!validProp) {
         LOG.warn("Could not find property:" + prop);
         this.unfoundProps = ArrayUtils.add(this.unfoundProps, prop);
      }
   }

   return ArrayUtils.isEmpty(this.unfoundProps);
}
 
Example 4
Source File: AuthenticationCertificateRegistrationServiceImpl.java    From freehealth-connector with GNU Affero General Public License v3.0 6 votes vote down vote up
public Result<X509Certificate[]> poll(String requestId) throws TechnicalConnectorException {
   X509Certificate[] cert = new X509Certificate[0];
   GetCertificateRequest request = new GetCertificateRequest();
   request.setRequestId(requestId);
   Result<GetCertificateResponse> resp = RaUtils.invokeCertRa(request, "urn:be:fgov:ehealth:etee:certra:getcertificate", GetCertificateResponse.class);
   if (!resp.getStatus().equals(Status.OK)) {
      return resp.getStatus().equals(Status.PENDING) ? new Result(resp.getTime()) : new Result("Unable to obtain certificate", resp.getCause());
   } else {
      cert = (X509Certificate[])((X509Certificate[])ArrayUtils.add(cert, CertificateUtils.toX509Certificate(((GetCertificateResponse)resp.getResult()).getCertificate())));

      byte[] cacert;
      for(Iterator i$ = ((GetCertificateResponse)resp.getResult()).getCaCertificates().iterator(); i$.hasNext(); cert = (X509Certificate[])((X509Certificate[])ArrayUtils.add(cert, CertificateUtils.toX509Certificate(cacert)))) {
         cacert = (byte[])i$.next();
      }

      return new Result(cert);
   }
}
 
Example 5
Source File: AuthenticationCertificateRegistrationServiceImpl.java    From freehealth-connector with GNU Affero General Public License v3.0 6 votes vote down vote up
public Result<X509Certificate[]> poll(String requestId) throws TechnicalConnectorException {
   X509Certificate[] cert = new X509Certificate[0];
   GetCertificateRequest request = new GetCertificateRequest();
   request.setRequestId(requestId);
   Result<GetCertificateResponse> resp = RaUtils.invokeCertRa(request, "urn:be:fgov:ehealth:etee:certra:getcertificate", GetCertificateResponse.class);
   if (!resp.getStatus().equals(Status.OK)) {
      return resp.getStatus().equals(Status.PENDING) ? new Result(resp.getTime()) : new Result("Unable to obtain certificate", resp.getCause());
   } else {
      cert = (X509Certificate[])((X509Certificate[])ArrayUtils.add(cert, CertificateUtils.toX509Certificate(((GetCertificateResponse)resp.getResult()).getCertificate())));

      byte[] cacert;
      for(Iterator i$ = ((GetCertificateResponse)resp.getResult()).getCaCertificates().iterator(); i$.hasNext(); cert = (X509Certificate[])((X509Certificate[])ArrayUtils.add(cert, CertificateUtils.toX509Certificate(cacert)))) {
         cacert = (byte[])i$.next();
      }

      return new Result(cert);
   }
}
 
Example 6
Source File: FrameBlock.java    From systemds with Apache License 2.0 5 votes vote down vote up
/**
 * Append a column of value type LONG as the last column of
 * the data frame. The given array is wrapped but not copied
 * and hence might be updated in the future.
 *
 * @param col array of longs
 */
public void appendColumn(long[] col) {
	ensureColumnCompatibility(col.length);
	String[] colnames = getColumnNames(); //before schema modification
	_schema = (ValueType[]) ArrayUtils.add(_schema, ValueType.INT64);
	_colnames = (String[]) ArrayUtils.add(colnames, createColName(_schema.length));
	_coldata = (_coldata==null) ? new Array[]{new LongArray(col)} :
		(Array[]) ArrayUtils.add(_coldata, new LongArray(col));
	_numRows = col.length;
}
 
Example 7
Source File: FrameBlock.java    From systemds with Apache License 2.0 5 votes vote down vote up
/**
 * Append a column of value type DOUBLE as the last column of
 * the data frame. The given array is wrapped but not copied
 * and hence might be updated in the future.
 *
 * @param col array of doubles
 */
public void appendColumn(double[] col) {
	ensureColumnCompatibility(col.length);
	String[] colnames = getColumnNames(); //before schema modification
	_schema = (ValueType[]) ArrayUtils.add(_schema, ValueType.FP64);
	_colnames = (String[]) ArrayUtils.add(colnames, createColName(_schema.length));
	_coldata = (_coldata==null) ? new Array[]{new DoubleArray(col)} :
		(Array[]) ArrayUtils.add(_coldata, new DoubleArray(col));
	_numRows = col.length;
}
 
Example 8
Source File: FrameBlock.java    From systemds with Apache License 2.0 5 votes vote down vote up
/**
 * Append a column of value type INT as the last column of 
 * the data frame. The given array is wrapped but not copied 
 * and hence might be updated in the future.
 * 
 * @param col array of longs
 */
public void appendColumn(int[] col) {
	ensureColumnCompatibility(col.length);
	String[] colnames = getColumnNames(); //before schema modification
	_schema = (ValueType[]) ArrayUtils.add(_schema, ValueType.INT32);
	_colnames = (String[]) ArrayUtils.add(colnames, createColName(_schema.length));
	_coldata = (_coldata==null) ? new Array[]{new IntegerArray(col)} :
		(Array[]) ArrayUtils.add(_coldata, new IntegerArray(col));
	_numRows = col.length;
}
 
Example 9
Source File: WriteSPInstruction.java    From systemds with Apache License 2.0 5 votes vote down vote up
@Override
public LineageItem[] getLineageItems(ExecutionContext ec) {
	LineageItem[] ret = LineageItemUtils.getLineage(ec, input1, input2, input3, input4);
	if (formatProperties != null && formatProperties.getDescription() != null && !formatProperties.getDescription().isEmpty())
		ret = (LineageItem[])ArrayUtils.add(ret, new LineageItem(formatProperties.getDescription()));
	return new LineageItem[]{new LineageItem(input1.getName(), getOpcode(), ret)};
}
 
Example 10
Source File: FrameBlock.java    From systemds with Apache License 2.0 5 votes vote down vote up
/**
 * Append a column of value type DOUBLE as the last column of
 * the data frame. The given array is wrapped but not copied
 * and hence might be updated in the future.
 *
 * @param col array of doubles
 */
public void appendColumn(double[] col) {
	ensureColumnCompatibility(col.length);
	String[] colnames = getColumnNames(); //before schema modification
	_schema = (ValueType[]) ArrayUtils.add(_schema, ValueType.FP64);
	_colnames = (String[]) ArrayUtils.add(colnames, createColName(_schema.length));
	_coldata = (_coldata==null) ? new Array[]{new DoubleArray(col)} :
		(Array[]) ArrayUtils.add(_coldata, new DoubleArray(col));
	_numRows = col.length;
}
 
Example 11
Source File: ConfigurationModuleVersion.java    From freehealth-connector with GNU Affero General Public License v3.0 5 votes vote down vote up
public void getJarFromCP() {
   try {
      Enumeration resEnum = Thread.currentThread().getContextClassLoader().getResources("META-INF/MANIFEST.MF");
      String[] cpElements = ArrayUtils.EMPTY_STRING_ARRAY;

      while(resEnum.hasMoreElements()) {
         URL url = (URL)resEnum.nextElement();
         StringBuilder sb = new StringBuilder("[CP Content] ");
         String substringAfterLast = StringUtils.substringAfterLast(StringUtils.substringBefore(url.getPath(), "!"), "/");
         if (!"MANIFEST.MF".equals(substringAfterLast)) {
            sb.append(substringAfterLast);
            cpElements = (String[])((String[])ArrayUtils.add(cpElements, sb.toString()));
         }
      }

      Arrays.sort(cpElements);
      String[] arr$ = cpElements;
      int len$ = cpElements.length;

      for(int i$ = 0; i$ < len$; ++i$) {
         String cpElement = arr$[i$];
         LOG.debug(cpElement);
      }
   } catch (IOException var7) {
      LOG.error(var7.getMessage(), var7);
   }

}
 
Example 12
Source File: FrameBlock.java    From systemds with Apache License 2.0 5 votes vote down vote up
/**
 * Append a column of value type INT as the last column of 
 * the data frame. The given array is wrapped but not copied 
 * and hence might be updated in the future.
 * 
 * @param col array of longs
 */
public void appendColumn(int[] col) {
	ensureColumnCompatibility(col.length);
	String[] colnames = getColumnNames(); //before schema modification
	_schema = (ValueType[]) ArrayUtils.add(_schema, ValueType.INT32);
	_colnames = (String[]) ArrayUtils.add(colnames, createColName(_schema.length));
	_coldata = (_coldata==null) ? new Array[]{new IntegerArray(col)} :
		(Array[]) ArrayUtils.add(_coldata, new IntegerArray(col));
	_numRows = col.length;
}
 
Example 13
Source File: STSServiceImpl.java    From freehealth-connector with GNU Affero General Public License v3.0 5 votes vote down vote up
private String[] extractTextContent(NodeList nodelist) {
   String[] result = ArrayUtils.EMPTY_STRING_ARRAY;

   for(int i = 0; i < nodelist.getLength(); ++i) {
      Element el = (Element)nodelist.item(i);
      result = (String[])((String[])ArrayUtils.add(result, el.getTextContent()));
   }

   return result;
}
 
Example 14
Source File: MonetaDropwizardApplication.java    From moneta with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
	String[] localArgs = args;
	if (!containsConfiguration(args)) {
		// Add default config if nothing specified
		localArgs = (String[]) ArrayUtils.add(args, "/moneta-config.yaml");
	}
	new MonetaDropwizardApplication().run(localArgs);
}
 
Example 15
Source File: ConfigurationModuleVersion.java    From freehealth-connector with GNU Affero General Public License v3.0 5 votes vote down vote up
public void getJarFromCP() {
   try {
      Enumeration resEnum = Thread.currentThread().getContextClassLoader().getResources("META-INF/MANIFEST.MF");
      String[] cpElements = ArrayUtils.EMPTY_STRING_ARRAY;

      while(resEnum.hasMoreElements()) {
         URL url = (URL)resEnum.nextElement();
         StringBuilder sb = new StringBuilder("[CP Content] ");
         String substringAfterLast = StringUtils.substringAfterLast(StringUtils.substringBefore(url.getPath(), "!"), "/");
         if (!"MANIFEST.MF".equals(substringAfterLast)) {
            sb.append(substringAfterLast);
            cpElements = (String[])((String[])ArrayUtils.add(cpElements, sb.toString()));
         }
      }

      Arrays.sort(cpElements);
      String[] arr$ = cpElements;
      int len$ = cpElements.length;

      for(int i$ = 0; i$ < len$; ++i$) {
         String cpElement = arr$[i$];
         LOG.debug(cpElement);
      }
   } catch (IOException var7) {
      LOG.error(var7.getMessage(), var7);
   }

}
 
Example 16
Source File: Nominal2Date.java    From rapidminer-studio with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public OperatorVersion[] getIncompatibleVersionChanges() {
	return (OperatorVersion[]) ArrayUtils.add(super.getIncompatibleVersionChanges(), BEFORE_TIME_READ_FIX);
}
 
Example 17
Source File: DashboardControll.java    From rebuild with GNU General Public License v3.0 4 votes vote down vote up
@RequestMapping("/chart-list")
public void chartList(HttpServletRequest request, HttpServletResponse response) throws IOException {
	ID user = getRequestUser(request);
	String type = request.getParameter("type");

	Object[][] charts = null;
	if ("builtin".equalsIgnoreCase(type)) {
		charts = new Object[0][];
	} else {
	    ID useBizz = user;
	    String sql = "select chartId,title,chartType,modifiedOn,belongEntity from ChartConfig where (1=1) and createdBy = ? order by modifiedOn desc";
		if (UserHelper.isAdmin(user)) {
               sql = sql.replace("createdBy = ", "createdBy.roleId = ");
               useBizz = RoleService.ADMIN_ROLE;
		}

		if ("entity".equalsIgnoreCase(type)) {
		    String entity = request.getParameter("entity");
		    Entity entityMeta = MetadataHelper.getEntity(entity);
		    String entitySql = String.format("belongEntity = '%s'", StringEscapeUtils.escapeSql(entity));
		    if (entityMeta.getMasterEntity() != null) {
                   entitySql += String.format(" or belongEntity = '%s'", entityMeta.getMasterEntity().getName());
               } else if (entityMeta.getSlaveEntity() != null) {
                   entitySql += String.format(" or belongEntity = '%s'", entityMeta.getSlaveEntity().getName());
               }

		    sql = sql.replace("1=1", entitySql);
           }

           charts = Application.createQueryNoFilter(sql).setParameter(1, useBizz).array();
		for (Object[] o : charts) {
		    o[3] = Moment.moment((Date) o[3]).fromNow();
		    o[4] = EasyMeta.getLabel(MetadataHelper.getEntity((String) o[4]));
           }
	}

	// 内置图表
       if (!"entity".equalsIgnoreCase(type)) {
           for (BuiltinChart b : ChartsFactory.getBuiltinCharts()) {
               Object[] c = new Object[]{ b.getChartId(), b.getChartTitle(), b.getChartType(), b.getChartDesc() };
               charts = (Object[][]) ArrayUtils.add(charts, c);
           }
       }

	writeSuccess(response, charts);
}
 
Example 18
Source File: ZookeeperConfigurer.java    From spring-zookeeper with Apache License 2.0 4 votes vote down vote up
@Override
public void setLocation(Resource location) {
    zkLocation = (ZookeeperResource) location;
    super.setLocations((Resource[]) ArrayUtils.add(localLocations, zkLocation));
}
 
Example 19
Source File: AbstractParallelTreeLearner.java    From rapidminer-studio with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public OperatorVersion[] getIncompatibleVersionChanges() {
	return (OperatorVersion[]) ArrayUtils.add(super.getIncompatibleVersionChanges(),
			FASTER_REGRESSION);
}
 
Example 20
Source File: CubeDesc.java    From kylin-on-parquet-v2 with Apache License 2.0 4 votes vote down vote up
private void initDerivedMap(TblColRef[] hostCols, DeriveType type, JoinDesc join, TblColRef[] derivedCols,
        String[] extra) {
    if (hostCols.length == 0 || derivedCols.length == 0)
        throw new IllegalStateException("host/derived columns must not be empty");

    // Although FK derives PK automatically, user unaware of this can declare PK as derived dimension explicitly.
    // In that case, derivedCols[] will contain a FK which is transformed from the PK by initDimensionColRef().
    // Must drop FK from derivedCols[] before continue.
    for (int i = 0; i < derivedCols.length; i++) {
        if (ArrayUtils.contains(hostCols, derivedCols[i])) {
            derivedCols = (TblColRef[]) ArrayUtils.remove(derivedCols, i);
            if (extra != null)
                extra = (String[]) ArrayUtils.remove(extra, i);
            i--;
        }
    }

    if (derivedCols.length == 0)
        return;

    for (int i = 0; i < derivedCols.length; i++) {
        TblColRef derivedCol = derivedCols[i];
        boolean isOneToOne = type == DeriveType.PK_FK || ArrayUtils.contains(hostCols, derivedCol)
                || (extra != null && extra[i].contains("1-1"));
        derivedToHostMap.put(derivedCol, new DeriveInfo(type, join, hostCols, isOneToOne));
    }

    Array<TblColRef> hostColArray = new Array<TblColRef>(hostCols);
    List<DeriveInfo> infoList = hostToDerivedMap.get(hostColArray);
    if (infoList == null) {
        infoList = new ArrayList<DeriveInfo>();
        hostToDerivedMap.put(hostColArray, infoList);
    }

    // Merged duplicated derived column
    List<TblColRef> whatsLeft = new ArrayList<>();
    for (TblColRef derCol : derivedCols) {
        boolean merged = false;
        for (DeriveInfo existing : infoList) {
            if (existing.type == type && existing.join.getPKSide().equals(join.getPKSide())) {
                if (ArrayUtils.contains(existing.columns, derCol)) {
                    merged = true;
                    break;
                }
                if (type == DeriveType.LOOKUP) {
                    existing.columns = (TblColRef[]) ArrayUtils.add(existing.columns, derCol);
                    merged = true;
                    break;
                }
            }
        }
        if (!merged)
            whatsLeft.add(derCol);
    }
    if (whatsLeft.size() > 0) {
        infoList.add(new DeriveInfo(type, join, whatsLeft.toArray(new TblColRef[whatsLeft.size()]),
                false));
    }
}