List of usage examples for org.apache.commons.lang ArrayUtils toPrimitive
public static boolean[] toPrimitive(Boolean[] array)
Converts an array of object Booleans to primitives.
From source file:edu.harvard.iq.dvn.ingest.statdataio.impl.plugins.spss.SPSSFileReader.java
int read_DataList(String dataListCommand) throws IOException { int readStatus = 0; // Read the first line (DATA LIST ...) to determine // the field separator: // This line should be "/"-terminated (?) dbgLog.fine("dataList command: " + dataListCommand); List<Integer> variableTypeList = new ArrayList<Integer>(); Set<Integer> decimalVariableSet = new HashSet<Integer>(); List<Integer> printFormatList = new ArrayList<Integer>(); // TODO: move Map<String, String> printFormatNameTable = new LinkedHashMap<String, String>(); // TODO: move String delimiterString = null; //String datalistRegex = "^data\\s+list\\s+list\\('(.)'\\)\\s+?/"; String datalistRegex = "^list\\s*\\('(.)'\\)"; Pattern datalistPattern = Pattern.compile(datalistRegex, java.util.regex.Pattern.CASE_INSENSITIVE); Matcher datalistMatcher = datalistPattern.matcher(dataListCommand); if (datalistMatcher.find()) { delimiterString = datalistMatcher.group(1); setDelimiterChar(delimiterString.charAt(0)); dbgLog.fine("found delimiter: " + delimiterString); } else {//from w w w .ja v a 2s .co m throw new IOException( "Invalid SPSS Command Syntax: " + "no delimiter specified in the DATA LIST command."); } // Cut off the remaining lines containing the variable definitions: int separatorIndex = dataListCommand.indexOf("/"); if (separatorIndex == -1) { throw new IOException("Invalid SPSS Command Syntax: " + "missing / delimiter on the DATA LIST line."); // No slash found after the first line of the Data List command. } dataListCommand = dataListCommand.substring(separatorIndex + 1); // Parse the variable section. For a delimited file this should be // a list of variable name + data type pairs. // "fortran" type definitions are assumed. dbgLog.fine("parsing " + dataListCommand + " for variable declarations."); int variableCounter = 0; String varName = null; String varType = null; String varDeclarationRegex = "^\\s*(\\S+)\\s+\\((\\S*)\\)"; Pattern varDeclarationPattern = Pattern.compile(varDeclarationRegex); Matcher varDeclarationMatcher = varDeclarationPattern.matcher(dataListCommand); String stringVarDeclarationRegex = "^[aA]([0-9]+)"; Pattern stringVarDeclarationPattern = Pattern.compile(stringVarDeclarationRegex); String numVarDeclarationRegex = "^[fF]([0-9]+)\\.*([0-9]*)"; Pattern numVarDeclarationPattern = Pattern.compile(numVarDeclarationRegex); int endOfMatches = 0; while (varDeclarationMatcher.find()) { varName = varDeclarationMatcher.group(1); varType = varDeclarationMatcher.group(2); endOfMatches = varDeclarationMatcher.end(); dataListCommand = dataListCommand.substring(endOfMatches); varDeclarationMatcher.reset(dataListCommand); dbgLog.fine("found variable " + varName + ", type " + varType); if (varType == null || varType.equals("")) { throw new IOException( "Invalid variable declaration in DATA LIST command: no type specified for variable " + varName + "."); } variableNameList.add(varName); // unfVariableTypes list holds extended type definitions for the // UNF calculation; // we need to be able to differentiate between Integers and // real numbers, in addition to the "numeric" and "string" values. varType = varType.toUpperCase(); if (varType.startsWith("A")) { // String: Matcher stringVarDeclarationMatcher = stringVarDeclarationPattern.matcher(varType); if (stringVarDeclarationMatcher.find()) { variableTypeList.add(new Integer(stringVarDeclarationMatcher.group(1))); } else { // set to default if the string size is not explicitely // specified: variableTypeList.add(1); } formatCategoryTable.put(varName, SPSSConstants.FORMAT_CATEGORY_TABLE.get("A")); unfVariableTypes.put(varName, -1); printFormatList.add(1); //printFormatNameTable.put(varName, "A"); } else if (varType.startsWith("F")) { // "minimal" format value is 0 -- numeric variableTypeList.add(0); formatCategoryTable.put(varName, SPSSConstants.FORMAT_CATEGORY_TABLE.get("F")); if (varType.equals("F")) { // abbreviated numeric type definition; // defaults to f10.0 // for the purposes of the UNF calculations this is an integer: unfVariableTypes.put(varName, 0); printFormatList.add(5); //printFormatNameTable.put(varName, "F10.0"); } else { Matcher numVarDeclarationMatcher = numVarDeclarationPattern.matcher(varType); if (numVarDeclarationMatcher.find()) { Integer numLength = new Integer(numVarDeclarationMatcher.group(1)); Integer numDecimal = 0; String optionalToken = numVarDeclarationMatcher.group(2); if (optionalToken != null && !optionalToken.equals("")) { numDecimal = new Integer(optionalToken); if ((int) numDecimal > 0) { unfVariableTypes.put(varName, 1); decimalVariableSet.add(variableCounter); printFormatNameTable.put(varName, "F" + numLength + "." + numDecimal); } } printFormatList.add(5); // TODO: verify (should it be 0 instead?) } else { // This does not look like a valid numeric type // definition. throw new IOException("Invalid variable declaration in the DATA LIST command: " + "Illegal or unsupported numeric type definition for variable " + varName); } } } else if (varType.matches("^[1-9]$")) { // Another allowed SPSS abbreviation: // type (N) where N is [1-9] means a numeric decimal with // N decimal positions: variableTypeList.add(0); formatCategoryTable.put(varName, SPSSConstants.FORMAT_CATEGORY_TABLE.get("F")); Integer numDecimal = new Integer(varType); unfVariableTypes.put(varName, 1); decimalVariableSet.add(variableCounter); printFormatList.add(5); // TODO: verify (should it be 0 instead?) printFormatNameTable.put(varName, "F10." + numDecimal); // Check for various date and time formats that we support: } else if (SPSSConstants.FORMAT_CATEGORY_TABLE.get(varType) != null) { //if ( SPSSConstants.FORMAT_CATEGORY_TABLE.get(varType).equals("date") // || SPSSConstants.FORMAT_CATEGORY_TABLE.get(varType).equals("time") // || varType.equals("WKDAY") // || varType.equals("MONTH")) { if (varType.equalsIgnoreCase("DATE") || varType.equalsIgnoreCase("DATETIME")) { variableTypeList.add(1); formatCategoryTable.put(varName, SPSSConstants.FORMAT_CATEGORY_TABLE.get(varType)); unfVariableTypes.put(varName, -1); //printFormatList.add(); // TODO: confirm that this isn't needed. printFormatNameTable.put(varName, varType); } else { throw new IOException("Invalid variable declaration in DATA LIST command: " + "unsupported variable type definition for variable " + varName + "."); } } else { // invalid/unrecognized variable type definition. throw new IOException("Invalid variable declaration in DATA LIST command: " + "unknown or illegal type definition for variable " + varName + "."); } variableCounter++; } //dataListCommand = dataListCommand.substring(endOfMatches); // check to see if we've parsed the entire DATA LIST section: if (!dataListCommand.matches("^[ \t\n\r]*$")) { throw new IOException("Illegal control card syntax: " + "this portion of the DATA LIST command could not be parsed: " + dataListCommand); } smd.getFileInformation().put("varQnty", variableCounter); setVarQnty(variableCounter); dbgLog.fine("varQnty=" + getVarQnty()); smd.setVariableName(variableNameList.toArray(new String[variableNameList.size()])); // "minimal" variable types: SPSS type binary definition: // 0 means numeric, >0 means string. smd.setVariableTypeMinimal( ArrayUtils.toPrimitive(variableTypeList.toArray(new Integer[variableTypeList.size()]))); // This is how the "discrete" and "continuous" numeric values are // distinguished in the data set metadata: smd.setDecimalVariables(decimalVariableSet); //TODO: smd.getFileInformation().put("caseWeightVariableName", caseWeightVariableName); dbgLog.info("<<<<<<"); dbgLog.info("printFormatList = " + printFormatList); dbgLog.info("printFormatNameTable = " + printFormatNameTable); dbgLog.info("formatCategoryTable = " + formatCategoryTable); dbgLog.info(">>>>>>"); smd.setVariableFormat(printFormatList); smd.setVariableFormatName(printFormatNameTable); smd.setVariableFormatCategory(formatCategoryTable); //TODO: verify return variableCounter; }
From source file:fr.inria.oak.paxquery.algebra.test.parser.LogicalPlanParser.java
final public ApplyConstruct ApplyConstructDEF() throws ParseException { ApplyConstruct apply;//from w w w . j a v a 2 s . co m Token before; Token after; Token tempEach; int column; ApplyConstruct tempApply; List<String> each = new ArrayList<String>(); List<Integer> fields = new ArrayList<Integer>(); List<ApplyConstruct> nested = new ArrayList<ApplyConstruct>(); jj_consume_token(LSBRACKET); before = jj_consume_token(STR); jj_consume_token(COMMA); after = jj_consume_token(STR); jj_consume_token(COMMA); if (jj_2_37(10)) { tempEach = jj_consume_token(STR); each.add(StringEscapeUtils.unescapeJava(tempEach.image.substring(1, tempEach.image.length() - 1))); } else { ; } label_5: while (true) { if (jj_2_38(10)) { ; } else { break label_5; } jj_consume_token(LPAREN); column = ColumnDEF(); fields.add(column); jj_consume_token(RPAREN); if (jj_2_39(10)) { tempApply = ApplyConstructDEF(); nested.add(tempApply); } else { ; } tempEach = jj_consume_token(STR); each.add(StringEscapeUtils.unescapeJava(tempEach.image.substring(1, tempEach.image.length() - 1))); } jj_consume_token(RSBRACKET); { if (true) return new ApplyConstruct( StringEscapeUtils.unescapeJava(before.image.substring(1, before.image.length() - 1)), each.toArray(new String[each.size()]), StringEscapeUtils.unescapeJava(after.image.substring(1, after.image.length() - 1)), ArrayUtils.toPrimitive(fields.toArray(new Integer[fields.size()])), nested.toArray(new ApplyConstruct[nested.size()])); } throw new Error("Missing return statement in function"); }
From source file:com.flexive.war.beans.admin.main.AccountBean.java
/** * Creates a new user from the beans data. * * @return the next jsf page to render/*w w w .ja va 2 s . c om*/ */ public String createUser() { boolean hasError = false; // Param check if (password == null) { password = ""; } // Passwords must match if (!password.equals(passwordConfirm)) { new FxFacesMsgErr("User.err.passwordsDontMatch").addToContext(); hasError = true; } // Mandator select and check final UserTicket ticket = FxContext.getUserTicket(); long mandatorId = ticket.isGlobalSupervisor() ? account.getMandatorId() : ticket.getMandatorId(); if (mandatorId < 0) { FxFacesMsgErr msg = new FxFacesMsgErr("User.err.mandatorMissing"); msg.setId("mandator"); msg.addToContext(); hasError = true; } // If we have an error abort if (hasError) { return "accountCreate"; } // Create the new account itself try { setAccountIdFilter(getAccountEngine().create(account, password)); account = new AccountEditBean(getAccountEngine().load(this.accountIdFilter)); new FxFacesMsgInfo("User.nfo.saved", account.getName()).addToContext(); } catch (Exception exc) { new FxFacesMsgErr(exc).addToContext(); return "accountCreate"; } // Assign the given groups to the account try { getAccountEngine().setGroups(this.accountIdFilter, ArrayUtils.toPrimitive(this.groups)); } catch (Exception exc) { new FxFacesMsgErr(exc).addToContext(); } // Assign the given roles to the account try { getAccountEngine().setRoles(this.accountIdFilter, getRoles()); } catch (Exception exc) { new FxFacesMsgErr(exc).addToContext(); } listCache.clear(); resetFilter(); return "accountOverview"; }
From source file:aldenjava.opticalmapping.data.data.DataNode.java
/** * // w w w . j av a 2s . c om * @param degeneracy */ public void degenerate(int degeneracy) { if (degeneracy < 0) throw new IllegalArgumentException("Negative degeneracy is not accepted " + degeneracy); if (degeneracy == 0) // Nothing needed to be done return; if (getTotalSignal() <= 1) // Nothing needed to be done return; List<Long> newRefpList = new ArrayList<Long>(); long sum = 0; int element = 0; long prev = -1; for (int i = 0; i < refp.length; i++) { if (prev != -1) { if (refp[i] - prev > degeneracy) { newRefpList.add((long) (sum / element)); sum = 0; element = 0; } } sum += refp[i]; element++; prev = refp[i]; } newRefpList.add((long) (sum / element)); refp = ArrayUtils.toPrimitive(newRefpList.toArray(new Long[newRefpList.size()])); }
From source file:com.vmware.identity.idm.server.config.directory.DirectoryConfigStore.java
@Override public void setAuthnTypesForProvider(String tenantName, String providerName, boolean password, boolean windows, boolean certificate, boolean rsaSecureID) throws Exception { HashSet<Integer> authnTypes = new HashSet<Integer>(); if (password) { authnTypes.add(DirectoryConfigStore.FLAG_AUTHN_TYPE_ALLOW_PASSWORD); }/*from w w w. j a v a 2 s.c o m*/ if (windows) { authnTypes.add(DirectoryConfigStore.FLAG_AUTHN_TYPE_ALLOW_WINDOWS); } if (certificate) { authnTypes.add(DirectoryConfigStore.FLAG_AUTHN_TYPE_ALLOW_TLS_CERTIFICATE); } if (rsaSecureID) { authnTypes.add(DirectoryConfigStore.FLAG_AUTHN_TYPE_ALLOW_RSA_SECUREID); } if (authnTypes.size() == 0) { authnTypes.add(DirectoryConfigStore.FLAG_AUTHN_TYPE_ALLOW_NONE); } int[] authTypesArray = ArrayUtils.toPrimitive(authnTypes.toArray(new Integer[authnTypes.size()])); this.setProviderProperty(tenantName, providerName, IdentityProviderLdapObject.PROPERTY_AUTHN_TYPES, ServerUtils.getLdapValue(authTypesArray)); }
From source file:be.ugent.maf.cellmissy.gui.controller.analysis.singlecell.AngleDirectController.java
/** * * @param singleCellConditionDataHolder//www .j av a2s . c om * @return */ private List<XYSeriesCollection> getCompassTADataset( SingleCellConditionDataHolder singleCellConditionDataHolder) { List<XYSeriesCollection> list = new ArrayList<>(); singleCellConditionDataHolder.getSingleCellWellDataHolders().stream() .forEach((singleCellWellDataHolder) -> { double[] angles = ArrayUtils.toPrimitive( AnalysisUtils.excludeNullValues(singleCellWellDataHolder.getTurningAnglesVector())); double[] displacements = ArrayUtils.toPrimitive(AnalysisUtils .excludeNullValues(singleCellWellDataHolder.getInstantaneousDisplacementsVector())); list.add(getCompassDatasetForAWell(singleCellWellDataHolder, angles, displacements)); }); return list; }
From source file:de.Keyle.MyPet.skill.skills.implementation.Beacon.java
@Override public TagCompound save() { TagCompound nbtTagCompound = new TagCompound(); nbtTagCompound.getCompoundData().put("Buffs", new TagIntArray(ArrayUtils.toPrimitive(selectedBuffs.toArray(new Integer[selectedBuffs.size()])))); nbtTagCompound.getCompoundData().put("Active", new TagByte(this.active)); nbtTagCompound.getCompoundData().put("Reciever", new TagString(this.reciever.name())); return nbtTagCompound; }
From source file:be.ugent.maf.cellmissy.gui.controller.analysis.singlecell.AngleDirectController.java
/** * * @param singleCellConditionDataHolder/*from ww w . j av a 2 s. c o m*/ * @return */ private List<XYSeriesCollection> getCompassTrackTADatasets( SingleCellConditionDataHolder singleCellConditionDataHolder) { List<XYSeriesCollection> list = new ArrayList<>(); singleCellConditionDataHolder.getSingleCellWellDataHolders().stream() .forEach((singleCellWellDataHolder) -> { double[] angles = ArrayUtils.toPrimitive(AnalysisUtils .excludeNullValues(singleCellWellDataHolder.getMedianTurningAnglesVector())); double[] displacements = ArrayUtils.toPrimitive(AnalysisUtils .excludeNullValues(singleCellWellDataHolder.getEuclideanDistancesVector())); list.add(getCompassDatasetForAWell(singleCellWellDataHolder, angles, displacements)); }); return list; }
From source file:be.ugent.maf.cellmissy.gui.controller.analysis.singlecell.AngleDirectController.java
/** * For a single well, generate an histogram dataset. * * @param data/*from w ww . j a va2s.co m*/ * @param seriesKey * @param mapTo360 * @return an HistogramDataset */ private HistogramDataset getHistogramDatasetForAWell(String seriesKey, Double[] data, int bins, HistogramType type, boolean mapTo360) { HistogramDataset dataset = new HistogramDataset(); dataset.setType(type); double[] toPrimitive = ArrayUtils.toPrimitive(AnalysisUtils.excludeNullValues(data)); double[] toAdd; if (!mapTo360) { toAdd = toPrimitive; } else { double[] mappedData = new double[toPrimitive.length]; for (int i = 0; i < toPrimitive.length; i++) { if (toPrimitive[i] > 0) { mappedData[i] = toPrimitive[i]; } else { mappedData[i] = toPrimitive[i] + 360; } } toAdd = mappedData; } dataset.addSeries(seriesKey, toAdd, bins); return dataset; }
From source file:aldenjava.opticalmapping.data.mappingresult.OptMapResultNode.java
public static int[] getMapSignal(List<OptMapResultNode> resultList) { Set<Integer> set = new HashSet<Integer>(); for (OptMapResultNode result : resultList) { for (int i : result.getMapSignal()) set.add(i);//w w w . ja v a 2s. c o m } List<Integer> list = new ArrayList<Integer>(set); Collections.sort(list); return ArrayUtils.toPrimitive(list.toArray(new Integer[list.size()])); }