List of usage examples for org.apache.commons.lang3.math NumberUtils isNumber
public static boolean isNumber(final String str)
Checks whether the String a valid Java number.
Valid numbers include hexadecimal marked with the 0x
or 0X
qualifier, octal numbers, scientific notation and numbers marked with a type qualifier (e.g.
From source file:org.kuali.kra.protocol.workflow.ProtocolOnlineReviewDerivedRoleTypeServiceImpl.java
/** * This method returns members for a given application role * @see org.kuali.rice.kns.kim.role.DerivedRoleTypeServiceBase#getRoleMembersFromDerivedRole(java.lang.String, java.lang.String, org.kuali.rice.core.util.AttributeSet) */// w w w . ja v a 2 s. com @Override public List<RoleMembership> getRoleMembersFromDerivedRole(String namespaceCode, String roleName, Map<String, String> qualification) { validateRequiredAttributesAgainstReceived(qualification); List<RoleMembership> members = new ArrayList<RoleMembership>(); String qualificationSubmissionId = qualification.get("submissionId"); String qualificationReviewId = qualification.get("protocolOnlineReviewId"); String protocolLeadUnitNumber = qualification.get("protocolLeadUnitNumber"); //If the protocol has been submitted for review, get members with the appropriate role if (NumberUtils.isNumber(qualificationSubmissionId) && NumberUtils.isNumber(qualificationReviewId)) { Long submissionId = Long.parseLong(qualificationSubmissionId); Long reviewId = Long.parseLong(qualificationReviewId); for (ProtocolOnlineReviewBase pReview : getProtocolOnlineReviewService() .getProtocolReviews(submissionId)) { if (!pReview.getProtocolReviewer().getNonEmployeeFlag() && reviewId.equals(pReview.getProtocolOnlineReviewId())) { pReview.refresh(); members.add(RoleMembership.Builder.create(null, null, pReview.getProtocolReviewer().getPersonId(), MemberType.PRINCIPAL, null).build()); } } //Per KCIRB-1376: Add IRB Admins as review comment approvers if they have a role qualifier that matches the protocol lead unit List<RoleMembership> adminMembers = getIRBAdmins(protocolLeadUnitNumber); for (RoleMembership member : adminMembers) { members.add(RoleMembership.Builder.create(null, null, member.getMemberId(), member.getType(), null) .build()); } } return members; }
From source file:org.libreplan.web.planner.limiting.allocation.LimitingAllocationRow.java
private int toNumber(String str) { if (NumberUtils.isNumber(str)) { int result = NumberUtils.toInt(str); return (result >= 1 && result <= 10) ? result : 1; }/*from www.j a v a 2 s. com*/ return 1; }
From source file:org.o3project.optsdn.don.frame.NeFrame.java
/** * Get property color./*from www . j a v a2 s. c om*/ * * @param keyR R Property Key * @param keyG G Property Key * @param keyB B Property Key * @param keyA A Property Key * @param defaultColor The Default Color * @return The Property Color */ private Color getPropertyColor(String keyR, String keyG, String keyB, String keyA, Color defaultColor) { String propertyR = Config.getProperty(keyR); String propertyG = Config.getProperty(keyG); String propertyB = Config.getProperty(keyB); String propertyA = Config.getProperty(keyA); if (NumberUtils.isNumber(propertyR) && NumberUtils.isNumber(propertyG) && NumberUtils.isNumber(propertyB) && NumberUtils.isNumber(propertyA)) { return new Color(Integer.valueOf(propertyR), Integer.valueOf(propertyG), Integer.valueOf(propertyB), Integer.valueOf(propertyA)); } else { return defaultColor; } }
From source file:org.ocsoft.rosetto.parsers.rosetto.RosettoElementParser.java
/** * ??Rosetto??????.<br>//from ww w. j a va2s. c o m * ??????????ActionCall??????????. */ @Override public RosettoValue parseElement(String element) { //null?Values.NULL if (element == null) return Values.NULL; //?????? element = ParseUtils.removeDoubleQuate(element); //?????????????? if (element.startsWith("[") && element.endsWith("]")) { //???????? return parseActionCall(element); } else if (element.startsWith("(") && element.endsWith(")")) { //?????? return parseList(element); } else if (element.startsWith("{") && element.endsWith("}")) { //?????? return parseMacro(element); } //???????????? if (element.startsWith("@")) { //@????? return new ActionCall("getlocal", element.substring(1)); } else if (element.startsWith("$")) { //$?????? return new ActionCall("getglobal", element.substring(1)); } //??????????? if (NumberUtils.isNumber(element)) { if (element.contains(".")) { return new DoubleValue(NumberUtils.toDouble(element)); } else { return new IntValue(NumberUtils.toLong(element)); } } //bool??????????? if (element.equals("true")) { return BoolValue.TRUE; } else if (element.equals("false")) { return BoolValue.FALSE; } //????????? return new StringValue(element); }
From source file:org.onesun.sdi.core.metadata.Metadata.java
public void compact() { if (map.size() == 0) { return;// w ww . j a va 2 s.c o m } Set<String> compactKeySet = new HashSet<String>(); Set<String> removalKeySet = new HashSet<String>(); // Pass 1 : process each key and find out if there is an unwanted object; any node name that begins with a number need not be persisted. for (String key : map.keySet()) { String pk = key.replace("*", "").replace("@", ""); // remove special characters (used by processing logic) String[] tokens = pk.split("/"); // Split by Path character String token = (tokens != null && tokens.length > 0) ? tokens[tokens.length - 1] : null; if (token != null) { boolean status = NumberUtils.isNumber(token); if (status == true) { if (tokens.length > 1) { compactKeySet.add(tokens[0]); removalKeySet.add(key); } else if (tokens.length == 0) { removalKeySet.add(key); } } } } // Pass 2 : Process compactKeySet and removalKeySet if (compactKeySet.size() > 0) { for (String key : compactKeySet) { map.put(key + "*", map.get(key)); map.remove(key); } } if (removalKeySet.size() > 0) { for (String key : removalKeySet) { map.remove(key); } } }
From source file:org.opencb.opencga.catalog.utils.BioformatDetector.java
public static File.Bioformat detect(URI uri, File.Format format, File.Compression compression) { String path = uri.getPath();// w w w .j ava 2 s.c om Path source = Paths.get(uri); String mimeType; try { switch (format) { case VCF: case GVCF: case BCF: return File.Bioformat.VARIANT; case TBI: break; case SAM: case BAM: case CRAM: return File.Bioformat.ALIGNMENT; case BAI: return File.Bioformat.NONE; //TODO: Alignment? case FASTQ: return File.Bioformat.SEQUENCE; case PED: return File.Bioformat.PEDIGREE; case TAB_SEPARATED_VALUES: break; case COMMA_SEPARATED_VALUES: break; case PROTOCOL_BUFFER: break; case PLAIN: break; case JSON: case AVRO: String file; if (compression != File.Compression.NONE) { file = com.google.common.io.Files.getNameWithoutExtension(uri.getPath()); //Remove compression extension file = com.google.common.io.Files.getNameWithoutExtension(file); //Remove format extension } else { file = com.google.common.io.Files.getNameWithoutExtension(uri.getPath()); //Remove format extension } if (file.endsWith("variants")) { return File.Bioformat.VARIANT; } else if (file.endsWith("alignments")) { return File.Bioformat.ALIGNMENT; } break; case PARQUET: break; case IMAGE: case BINARY: case EXECUTABLE: case UNKNOWN: case XML: return File.Bioformat.NONE; default: break; } // for (Map.Entry<File.Bioformat, Pattern> entry : bioformatMap.entrySet()) { // if (entry.getValue().matcher(path).matches()) { // return entry.getKey(); // } // } mimeType = Files.probeContentType(source); if (path.endsWith(".nw")) { return File.Bioformat.OTHER_NEWICK; } if (mimeType == null || !mimeType.equalsIgnoreCase("text/plain") || path.endsWith(".redirection") || path.endsWith(".Rout") || path.endsWith("cel_files.txt") || !path.endsWith(".txt")) { return File.Bioformat.NONE; } FileInputStream fstream = new FileInputStream(path); BufferedReader br = new BufferedReader(new InputStreamReader(fstream)); String strLine; int numberOfLines = 20; int i = 0; boolean names = false; while ((strLine = br.readLine()) != null) { if (strLine.equalsIgnoreCase("")) { continue; } if (i == numberOfLines) { break; } if (strLine.startsWith("#")) { if (strLine.startsWith("#NAMES")) { names = true; } else { continue; } } else { String[] fields = strLine.split("\t"); if (fields.length > 2) { if (names && NumberUtils.isNumber(fields[1])) { return File.Bioformat.DATAMATRIX_EXPRESSION; } } else if (fields.length == 1) { if (fields[0].split(" ").length == 1 && !NumberUtils.isNumber(fields[0])) { return File.Bioformat.IDLIST; } } else if (fields.length == 2) { if (!fields[0].contains(" ") && NumberUtils.isNumber(fields[1])) { return File.Bioformat.IDLIST_RANKED; } } } i++; } br.close(); } catch (IOException e) { e.printStackTrace(); } return File.Bioformat.NONE; }
From source file:org.opendaylight.ovsdb.southbound.transactions.md.OvsdbBridgeUpdateCommandTest.java
@SuppressWarnings("unchecked") @Test// ww w . ja v a2 s .c om public void testSetOpenFlowNodeRef() throws Exception { PowerMockito.mockStatic(SouthboundMapper.class); when(ovsdbBridgeUpdateCommand.getUpdates()).thenReturn(mock(TableUpdates.class)); when(ovsdbBridgeUpdateCommand.getDbSchema()).thenReturn(mock(DatabaseSchema.class)); PowerMockito.mockStatic(TyperUtils.class); Map<UUID, Controller> updatedControllerRows = new HashMap<>(); when(TyperUtils.extractRowsUpdated(eq(Controller.class), any(TableUpdates.class), any(DatabaseSchema.class))).thenReturn(updatedControllerRows); List<ControllerEntry> controllerEntryList = new ArrayList<>(); ControllerEntry controllerEntry = mock(ControllerEntry.class); controllerEntryList.add(controllerEntry); when(SouthboundMapper.createControllerEntries(any(Bridge.class), any(Map.class))) .thenReturn(controllerEntryList); when(controllerEntry.isIsConnected()).thenReturn(true); Uri uri = mock(Uri.class); when(controllerEntry.getTarget()).thenReturn(uri); when(uri.getValue()).thenReturn("tcp:192.168.12.56:6633"); IpAddress bridgeControllerIpAddress = mock(IpAddress.class); PowerMockito.mockStatic(InetAddresses.class); when(InetAddresses.isInetAddress("192.168.12.56")).thenReturn(true); PowerMockito.whenNew(IpAddress.class).withAnyArguments().thenReturn(bridgeControllerIpAddress); PowerMockito.mockStatic(NumberUtils.class); when(NumberUtils.isNumber("6633")).thenReturn(true); PortNumber bridgeControllerPortNumber = mock(PortNumber.class); PowerMockito.whenNew(PortNumber.class).withAnyArguments().thenReturn(bridgeControllerPortNumber); PowerMockito.mockStatic(NetworkInterface.class); Enumeration<NetworkInterface> networkInterfaces = mock(Enumeration.class); when(NetworkInterface.getNetworkInterfaces()).thenReturn(networkInterfaces); when(networkInterfaces.hasMoreElements()).thenReturn(true, false); NetworkInterface networkInterface = PowerMockito.mock(NetworkInterface.class); when(networkInterfaces.nextElement()).thenReturn(networkInterface); Enumeration<InetAddress> networkInterfaceAddresses = mock(Enumeration.class); when(networkInterface.getInetAddresses()).thenReturn(networkInterfaceAddresses); when(networkInterfaceAddresses.hasMoreElements()).thenReturn(true, false); InetAddress networkInterfaceAddress = PowerMockito.mock(InetAddress.class); when(networkInterfaceAddresses.nextElement()).thenReturn(networkInterfaceAddress); Ipv4Address ipv4Address = mock(Ipv4Address.class); when(bridgeControllerIpAddress.getIpv4Address()).thenReturn(ipv4Address); when(ipv4Address.getValue()).thenReturn("127.0.0.1"); when(networkInterfaceAddress.getHostAddress()).thenReturn("127.0.0.1"); assertEquals(bridgeControllerIpAddress.getIpv4Address().getValue(), networkInterfaceAddress.getHostAddress()); OvsdbConnectionInstance ovsdbConnectionInstance = mock(OvsdbConnectionInstance.class); when(ovsdbBridgeUpdateCommand.getOvsdbConnectionInstance()).thenReturn(ovsdbConnectionInstance); when(ovsdbConnectionInstance.getInstanceIdentifier()).thenReturn(mock(InstanceIdentifier.class)); OvsdbBridgeAugmentationBuilder ovsdbBridgeAugmentationBuilder = mock(OvsdbBridgeAugmentationBuilder.class); Bridge bridge = mock(Bridge.class); when(ovsdbBridgeAugmentationBuilder.setBridgeOpenflowNodeRef(any(InstanceIdentifier.class))) .thenReturn(ovsdbBridgeAugmentationBuilder); Whitebox.invokeMethod(ovsdbBridgeUpdateCommand, "setOpenFlowNodeRef", ovsdbBridgeAugmentationBuilder, bridge); verify(controllerEntry, times(2)).isIsConnected(); verify(ovsdbBridgeAugmentationBuilder).setBridgeOpenflowNodeRef(any(InstanceIdentifier.class)); }
From source file:org.qifu.controller.SystemProgramAction.java
private void checkFields(DefaultControllerJsonResultObj<SysProgVO> result, SysProgVO sysProg, String sysOid, String iconOid, String w, String h) throws ControllerException, Exception { this.getCheckControllerFieldHandler(result) .testField("progSystemOid", (this.noSelect(sysOid)), "Please select system!") .testField("progId", sysProg, "@org.apache.commons.lang3.StringUtils@isBlank(progId)", "Id is blank!") .testField("progId", (this.noSelect(sysProg.getProgId())), "Please change Id value!") // PROG-ID ? "all" .testField("progId", (!SimpleUtils.checkBeTrueOf_azAZ09( super.defaultString(sysProg.getProgId()).replaceAll("-", "").replaceAll("_", ""))), "Id only normal character!") .testField("name", sysProg, "@org.apache.commons.lang3.StringUtils@isBlank(name)", "Name is blank!") .testField("url", ((MenuItemType.ITEM.equals(sysProg.getItemType()) && StringUtils.isBlank(sysProg.getUrl()))), "URL is blank!") .testField("itemType", (this.noSelect(sysProg.getItemType())), "Please select item-type!") .testField("iconOid", (this.noSelect(iconOid)), "Please select icon!") .testField("dialogWidth", ((YES.equals(sysProg.getIsDialog()) && !NumberUtils.isNumber(w))), "Please input dialog width!") .testField("dialogHeight", ((YES.equals(sysProg.getIsDialog()) && !NumberUtils.isNumber(h))), "Please input dialog height!") .throwMessage();/*from w ww . ja va 2 s. c o m*/ }
From source file:org.starnub.starnubserver.resources.connections.Players.java
/** * Recommended: For Plugin Developers & Anyone else. * <p>//from w ww . j a v a 2 s .c o m * Uses: This method is used to pull a player record using any type of * parameter. (Packet, Uuid, IP, NAME, clientCTX, Starbound ID, StarNub ID) * <p> * @param playerIdentifier Object that represent a player and it can take many forms * @return Player which represents the player that was retrieved by the provided playerIdentifier */ public PlayerSession getOnlinePlayerByAnyIdentifier(Object playerIdentifier) { if (playerIdentifier instanceof PlayerSession) { return (PlayerSession) playerIdentifier; } if (playerIdentifier instanceof Packet) { return playerByPacket((Packet) playerIdentifier); } if (playerIdentifier instanceof String) { String identifierString = (String) playerIdentifier; if (identifierString.length() <= 4 && NumberUtils.isNumber(identifierString)) { return playerByStarboundClientID(Integer.parseInt(identifierString)); } if (isStarNubId(identifierString)) { return playerByStarNubClientID(Integer.parseInt(identifierString.replaceAll("[sS]", ""))); } if (StringUtils.countMatches(identifierString, "-") == 4) { return playerByUUID(UUID.fromString(identifierString)); } if (StringUtils.countMatches(identifierString, ".") == 3) { try { return playerByIP(InetAddress.getByName(identifierString)); } catch (UnknownHostException e) { return null; } } return playerByName(identifierString); } if (playerIdentifier instanceof ChannelHandlerContext) { return playerByCTX((ChannelHandlerContext) playerIdentifier); } if (playerIdentifier instanceof Integer) { return playerByStarboundClientID((int) playerIdentifier); } if (playerIdentifier instanceof UUID) { return playerByUUID((UUID) playerIdentifier); } if (playerIdentifier instanceof InetAddress) { return playerByIP((InetAddress) playerIdentifier); } return null; }
From source file:org.starnub.starnubserver.resources.connections.Players.java
/** * Recommended: For connections use with StarNub. * <p>//ww w .j a v a 2 s . co m * Uses: This method is used to check is a string represents a starnubserver id. * <p> * @param s String representing the StarNub Id * @return boolean if is a starnubserver id or not */ public static boolean isStarNubId(String s) { if (!s.endsWith("s") && !s.endsWith("S")) { return false; } s = s.replaceAll("[sS]", ""); return NumberUtils.isNumber(s); }