List of usage examples for org.apache.commons.lang3 StringUtils isNumeric
public static boolean isNumeric(final CharSequence cs)
Checks if the CharSequence contains only Unicode digits.
From source file:io.stallion.dataAccess.db.SqlMigrationAction.java
public List<SqlMigration> getUserMigrations() { List<SqlMigration> migrations = list(); File sqlDirectory = new File(settings().getTargetFolder() + "/sql"); if (!sqlDirectory.isDirectory()) { Log.finer("Sql directory does not exist {0}", sqlDirectory.getAbsoluteFile()); return migrations; }// www . j a v a 2 s .c om Log.finer("Find sql files in {0}", sqlDirectory.getAbsolutePath()); for (File file : sqlDirectory.listFiles()) { Log.finer("Scan file" + file.getAbsolutePath()); if (!set("js", "sql").contains(FilenameUtils.getExtension(file.getAbsolutePath()))) { Log.finer("Extension is not .js or .sql {0}", file.getAbsolutePath()); continue; } if (file.getName().startsWith(".") || file.getName().startsWith("#")) { Log.finer("File name starts with invalid character {0}", file.getName()); continue; } if (!file.getName().contains("." + DB.instance().getDbImplementation().getName().toLowerCase() + ".")) { Log.finer("File name does not contain the name of the current database engine: \".{0}.\"", DB.instance().getDbImplementation().getName().toLowerCase()); continue; } if (!file.getName().contains("-")) { Log.finer("File name does not have version part {0}", file.getName()); continue; } String versionString = StringUtils.stripStart(StringUtils.split(file.getName(), "-")[0], "0"); if (!StringUtils.isNumeric(versionString)) { Log.finer("File name does not have numeric version part {0}", file.getName()); continue; } Log.info("Load SQL file for migration: {0}", file.getName()); migrations.add(new SqlMigration() .setVersionNumber(Integer.parseInt(StringUtils.stripStart(versionString, "0"))).setAppName("") .setFilename(file.getName()).setSource(FileUtils.readAllText(file))); } migrations.sort(new PropertyComparator<>("versionNumber")); return migrations; }
From source file:com.nps.micro.view.TestsSectionFragment.java
@Override protected View buildRootView(LayoutInflater inflater, ViewGroup container) { View rootView = inflater.inflate(layout, container, false); runButton = (Button) rootView.findViewById(R.id.runButton); runButton.setOnClickListener(new OnClickListener() { @Override//from w w w . jav a 2 s .co m public void onClick(View v) { prepareScenarios(); } }); repeatsInput = (EditText) rootView.findViewById(R.id.repeatsInput); repeatsInput.setText(String.valueOf(model.getRepeats())); repeatsInput.addTextChangedListener(new TextWatcher() { @Override public void afterTextChanged(Editable s) { String val = s.toString(); if (!val.isEmpty() && StringUtils.isNumeric(val)) { model.setRepeats(Integer.valueOf(s.toString())); } } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } }); repeatsButton = (Button) rootView.findViewById(R.id.setRepeatsButton); repeatsButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); builder.setTitle(R.string.repeats).setItems(R.array.repeats_array, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { repeatsInput.setText(getResources().getStringArray(R.array.repeats_array)[which]); dialog.dismiss(); } }); AlertDialog alert = builder.create(); alert.show(); } }); outSizeInput = (EditText) rootView.findViewById(R.id.packetOutSizeInput); outSizeInput.setText(String.valueOf(model.getStreamOutSize())); outSizeInput.addTextChangedListener(new TextWatcher() { @Override public void afterTextChanged(Editable s) { String val = s.toString(); if (!val.isEmpty() && StringUtils.isNumeric(val)) { model.setStreamOutSize(Short.valueOf(s.toString())); } } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } }); outSizeButton = (Button) rootView.findViewById(R.id.setOutSizeButton); outSizeButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); builder.setTitle(R.string.out_size).setItems(R.array.out_size_array, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { outSizeInput.setText(getResources().getStringArray(R.array.out_size_array)[which]); dialog.dismiss(); } }); AlertDialog alert = builder.create(); alert.show(); } }); inSizeInput = (EditText) rootView.findViewById(R.id.packetInSizeInput); inSizeInput.setText(String.valueOf(model.getStreamInSizes()[0])); inSizeInput.addTextChangedListener(new TextWatcher() { @Override public void afterTextChanged(Editable s) { String[] vals = s.toString().split(" "); List<Short> intVals = new ArrayList<Short>(); for (String val : vals) { try { intVals.add(Short.valueOf(val)); } catch (NumberFormatException e) { // TODO Auto-generated catch block } } short[] array = new short[intVals.size()]; for (int i = 0; i < intVals.size(); i++) array[i] = intVals.get(i); model.setStreamInSize(array); } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } }); inSizeButton = (Button) rootView.findViewById(R.id.setInSizeButton); inSizeButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); builder.setTitle(R.string.in_size).setItems(R.array.in_size_array, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { inSizeInput.setText(getResources().getStringArray(R.array.in_size_array)[which]); dialog.dismiss(); } }); AlertDialog alert = builder.create(); alert.show(); } }); radioStorageGroup = (RadioGroup) rootView.findViewById(R.id.storageRadioGroup); externalStorageRadio = (RadioButton) rootView.findViewById(R.id.externalStorageRadio); internalStorageRadio = (RadioButton) rootView.findViewById(R.id.internalStorageRadio); switch (model.getStorageType()) { case EXTERNAL: externalStorageRadio.setChecked(true); break; case INTERNAL: internalStorageRadio.setChecked(true); break; } externalStorageRadio.setEnabled(model.isSaveStreams() || model.isSaveLogs()); internalStorageRadio.setEnabled(model.isSaveStreams() || model.isSaveLogs()); radioStorageGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, int checkedId) { switch (checkedId) { case R.id.internalStorageRadio: model.setStorageType(Storage.Type.INTERNAL); break; case R.id.externalStorageRadio: model.setStorageType(Storage.Type.EXTERNAL); break; } } }); saveLogsCheckBox = (CheckBox) rootView.findViewById(R.id.saveLogsCheckBox); saveLogsCheckBox.setChecked(model.isSaveLogs()); saveLogsCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { model.setSaveLogs(isChecked); externalStorageRadio.setEnabled(model.isSaveStreams() || model.isSaveLogs()); internalStorageRadio.setEnabled(model.isSaveStreams() || model.isSaveLogs()); } }); streamBufferSizeInput = (EditText) rootView.findViewById(R.id.bufferSizeEditText); streamBufferSizeInput.setText(String.valueOf(model.getStreamBufferSize())); streamBufferSizeInput.addTextChangedListener(new TextWatcher() { @Override public void afterTextChanged(Editable s) { String val = s.toString(); if (!val.isEmpty() && StringUtils.isNumeric(val)) { model.setStreamBufferSize(Integer.valueOf(s.toString())); } } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } }); memoryUnitSpinner = (Spinner) rootView.findViewById(R.id.memoryUnitSpinner); memoryUnitSpinner.setSelection(model.getStreamBufferUnit().getIndex()); memoryUnitSpinner.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) { model.setStreamBufferUnit(MemoryUnit.fromIndex(pos)); } @Override public void onNothingSelected(AdapterView<?> parent) { // do nothing } }); saveStreamCheckBox = (CheckBox) rootView.findViewById(R.id.saveStreamDataCheckbox); saveStreamCheckBox.setChecked(model.isSaveStreams()); streamBufferSizeInput.setEnabled(saveStreamCheckBox.isChecked()); memoryUnitSpinner.setEnabled(saveStreamCheckBox.isChecked()); streamQueueSize = (EditText) rootView.findViewById(R.id.streamQueueSize); streamQueueSize.setText(String.valueOf(model.getStreamQueueSize())); streamQueueSize.addTextChangedListener(new TextWatcher() { @Override public void afterTextChanged(Editable s) { String val = s.toString(); if (!val.isEmpty() && StringUtils.isNumeric(val)) { model.setStreamQueueSize(Integer.valueOf(s.toString())); } } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } }); streamQueueSize.setEnabled(model.isSaveStreams() && !model.isAutoStreamQueueSize()); radioQueueGroup = (RadioGroup) rootView.findViewById(R.id.queueRadioGroup); autoStreamQueueSizeRadio = (RadioButton) rootView.findViewById(R.id.autoBufferRadio); manualStreamQueueSizeRadio = (RadioButton) rootView.findViewById(R.id.manualBufferRadio); if (model.isAutoStreamQueueSize()) { autoStreamQueueSizeRadio.setChecked(true); } else { manualStreamQueueSizeRadio.setChecked(true); } autoStreamQueueSizeRadio.setEnabled(model.isSaveStreams()); manualStreamQueueSizeRadio.setEnabled(model.isSaveStreams()); radioQueueGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, int checkedId) { switch (checkedId) { case R.id.autoBufferRadio: model.setAutoStreamQueueSize(true); streamQueueSize.setEnabled(false); break; case R.id.manualBufferRadio: model.setAutoStreamQueueSize(false); streamQueueSize.setEnabled(true); break; } } }); saveStreamCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { model.setSaveStreams(isChecked); externalStorageRadio.setEnabled(model.isSaveStreams() || model.isSaveLogs()); internalStorageRadio.setEnabled(model.isSaveStreams() || model.isSaveLogs()); streamBufferSizeInput.setEnabled(isChecked); memoryUnitSpinner.setEnabled(isChecked); autoStreamQueueSizeRadio.setEnabled(model.isSaveStreams()); manualStreamQueueSizeRadio.setEnabled(model.isSaveStreams()); streamQueueSize.setEnabled(model.isSaveStreams() && !model.isAutoStreamQueueSize()); } }); simulateEditText = (EditText) rootView.findViewById(R.id.simulateComputationsEditText); simulateEditText.setText(String.valueOf(model.getSimulateComputations())); simulateEditText.addTextChangedListener(new TextWatcher() { @Override public void onTextChanged(CharSequence s, int start, int before, int count) { model.setSimulateComputations(Short.valueOf(s.toString())); } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void afterTextChanged(Editable s) { } }); normalPriorityCheckBox = (CheckBox) rootView.findViewById(R.id.normalPriorityCheckbox); normalPriorityCheckBox.setChecked(model.isNormalThreadPriority()); normalPriorityCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { model.setNormalThreadPriority(isChecked); } }); hiPriorityAndroidCheckBox = (CheckBox) rootView.findViewById(R.id.hiAndroidPriorityCheckbox); hiPriorityAndroidCheckBox.setChecked(model.isHiAndroidThreadPriority()); hiPriorityAndroidCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { model.setHiAndroidThreadPriority(isChecked); } }); hiPriorityJavaCheckBox = (CheckBox) rootView.findViewById(R.id.hiJavaPriorityCheckbox); hiPriorityJavaCheckBox.setChecked(model.isHiJavaThreadPriority()); hiPriorityJavaCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { model.setHiJavaThreadPriority(isChecked); } }); extendedDevicesCombination = (CheckBox) rootView.findViewById(R.id.extendedDevicesCheckBox); extendedDevicesCombination.setChecked(model.isExtendedDevicesCombination()); extendedDevicesCombination.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { model.setExtendedDevicesCombination(isChecked); } }); fastHub = (CheckBox) rootView.findViewById(R.id.fastHubCheckBox); fastHub.setChecked(model.isFastHub()); fastHub.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { model.setFastHub(isChecked); } }); autoEnableGraphCheckBox = (CheckBox) rootView.findViewById(R.id.autoEnableGraphCheckBox); autoEnableGraphCheckBox.setChecked(model.isAutoEnableGraph()); autoEnableGraphCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { model.setAutoEnableGraph(isChecked); } }); createSequenceChooser(rootView); createDeviceChooser(rootView, runButton); updateStatus(rootView); return rootView; }
From source file:hk.newsRecommender.Classify.java
public static void genNaiveBayesModel(Configuration conf, int labelIndex, String trainFile, String trainSeqFile, boolean hasHeader) { CSVReader reader = null;/* ww w. ja va 2 s . c o m*/ try { FileSystem fs = FileSystem.get(conf); if (fs.exists(new Path(trainSeqFile))) fs.delete(new Path(trainSeqFile), true); SequenceFile.Writer writer = SequenceFile.createWriter(fs, conf, new Path(trainSeqFile), Text.class, VectorWritable.class); FileSystem fsopen = FileSystem.get(conf); FSDataInputStream in = fsopen.open(new Path(trainFile)); reader = new CSVReader(new InputStreamReader(in)); String[] header = null; if (hasHeader) header = reader.readNext(); String[] line = null; Long l = 0L; while ((line = reader.readNext()) != null) { if (labelIndex > line.length) break; l++; List<String> tmpList = Lists.newArrayList(line); String label = tmpList.get(labelIndex); if (!strLabelList.contains(label)) strLabelList.add(label); // Text key = new Text("/" + label + "/" + l); Text key = new Text("/" + label + "/"); tmpList.remove(labelIndex); VectorWritable vectorWritable = new VectorWritable(); Vector vector = new RandomAccessSparseVector(tmpList.size(), tmpList.size());//??? for (int i = 0; i < tmpList.size(); i++) { String tmpStr = tmpList.get(i); if (StringUtils.isNumeric(tmpStr)) vector.set(i, Double.parseDouble(tmpStr)); else vector.set(i, parseStrCell(tmpStr)); } vectorWritable.set(vector); writer.append(key, vectorWritable); } writer.close(); } catch (IOException e) { e.printStackTrace(); } }
From source file:com.aol.one.patch.DefaultPatcher.java
/** * object corresponding to path key at descendantIndex *///ww w . ja v a 2 s . c o m private Object getDescendantObject(Object objectToPatch, PathTokens pathTokens, int descendantIndex) throws PatchException, IllegalAccessException, InvocationTargetException { if (pathTokens == null || pathTokens.isEmpty()) { throw new PatchRuntimeException(ErrorCodes.ERR_INVALID_PATH_TOKENS_OBJ); } if (descendantIndex < -1 || descendantIndex >= pathTokens.size()) { throw new PatchRuntimeException(ErrorCodes.ERR_INVALID_DESCENDANT_INDEX, Integer.toString(descendantIndex)); } if (descendantIndex == -1) { return objectToPatch; } int index = 0; Object parentObject = objectToPatch; Object descendantObject = null; while (index <= descendantIndex) { String token = pathTokens.get(index); if (parentObject == null) { throw new PatchException(ErrorCodes.ERR_INVALID_PARENT_PATH_OBJ, "unable to retrieve descendant object from null parent while processing token: " + token); } descendantObject = null; if (parentObject instanceof Patchable) { Patchable tmp = (Patchable) parentObject; descendantObject = tmp.getPatchObjectByKey(token); } // if token is numeric, action to apply depends on previous descendant object if (descendantObject == null && StringUtils.isNumeric(token)) { if (parentObject instanceof java.util.List) { List tmpList = (List) parentObject; descendantObject = tmpList.get(Integer.parseInt(token)); } else if (parentObject instanceof java.util.Map) { Map tmpMap = (Map) parentObject; descendantObject = tmpMap.get(token); } } // last effort if (descendantObject == null) { descendantObject = invokeAccessorMethod(parentObject, token); } parentObject = descendantObject; index++; } return descendantObject; }
From source file:com.bekwam.examples.javafx.oldscores2.ScoresDialogController.java
@FXML public void updateMath1995() { if (logger.isDebugEnabled()) { logger.debug("[UPD 1995]"); }//from w w w . j av a 2 s . c om if (dao == null) { throw new IllegalArgumentException( "dao has not been set; call setRecenteredDAO() before calling this method"); } String recenteredScore_s = txtMathScoreRecentered.getText(); if (StringUtils.isNumeric(recenteredScore_s)) { Integer scoreRecentered = NumberUtils.toInt(recenteredScore_s); if (withinRange(scoreRecentered)) { if (needsRound(scoreRecentered)) { scoreRecentered = round(scoreRecentered); txtMathScoreRecentered.setText(String.valueOf(scoreRecentered)); } resetErrMsgs(); Integer score1995 = dao.lookup1995MathScore(scoreRecentered); txtMathScore1995.setText(String.valueOf(score1995)); } else { errMsgMathRecentered.setVisible(true); } } else { errMsgMathRecentered.setVisible(true); } }
From source file:com.nuvolect.securesuite.data.SqlIncSync.java
/** * Return text string with the last time the device was updated as an outgoing companion. * @return/*from ww w . j a va 2 s . c o m*/ */ public String getOutgoingUpdate() { /** * Previous versions saved an entire formatted time, current only stores time * as a String long. It formatted for use on demand. */ String s = Cryp.get(CConst.LAST_OUTGOING_UPDATE, "0"); if (StringUtils.isNumeric(s)) { String time = TimeUtil.friendlyTimeMDYM(Long.valueOf(s)); s = "Outgoing update: " + time; } return s; }
From source file:com.hortonworks.streamline.streams.security.service.SecurityCatalogResource.java
@PUT @Path("/roles/{roleNameOrId}/users") @Timed// w ww .java2 s. c om public Response addOrUpdateRoleUsers(@PathParam("roleNameOrId") String roleNameOrId, Set<String> userNamesOrIds, @Context SecurityContext securityContext) { SecurityUtil.checkRole(authorizer, securityContext, ROLE_SECURITY_ADMIN); Long roleId = StringUtils.isNumeric(roleNameOrId) ? Long.parseLong(roleNameOrId) : getIdFromRoleName(roleNameOrId); Set<Long> userIds = new HashSet<>(); for (String userNameOrId : userNamesOrIds) { if (StringUtils.isNumeric(userNameOrId)) { userIds.add(Long.parseLong(userNameOrId)); } else { userIds.add(catalogService.getUser(userNameOrId).getId()); } } return addOrUpdateRoleUsers(roleId, userIds); }
From source file:com.kynomics.control.HalterController.java
public void validateNumeric(FacesContext context, UIComponent uiComponent, Object value) throws ValidatorException { if (!StringUtils.isNumeric((String) value)) { HtmlInputText htmlInputText = (HtmlInputText) uiComponent; FacesMessage facesMessage = new FacesMessage(htmlInputText.getLabel() + ": nur Zahlen erlaubt"); throw new ValidatorException(facesMessage); }/*from w ww . ja v a 2 s .c om*/ }
From source file:com.willwinder.ugs.nbp.core.windows.StateTopComponent.java
private void executeNumber(char word, JTextField value) { if (!StringUtils.isNumeric(value.getText())) { value.setText("0"); GUIHelpers.displayErrorDialog("Provide numeric input."); return;//from www . j av a2 s . com } if (backend.isIdle()) { try { backend.sendGcodeCommand(word + value.getText()); } catch (Exception ex) { GUIHelpers.displayErrorDialog(ex.getLocalizedMessage()); } } }
From source file:controllers.PullRequestApp.java
private static Project getSelectedProject(Project project, String projectId, boolean isToProject) { Project selectedProject = project;// w ww . j a va 2s .com if (isToProject && project.isForkedFromOrigin() && project.originalProject.menuSetting.code && project.originalProject.menuSetting.pullRequest) { selectedProject = project.originalProject; } if (StringUtils.isNumeric(projectId)) { selectedProject = Project.find.byId(Long.parseLong(projectId)); } return selectedProject; }