List of usage examples for org.apache.commons.lang BooleanUtils toInteger
public static int toInteger(boolean bool)
Converts a boolean to an int using the convention that zero
is false
.
BooleanUtils.toInteger(true) = 1 BooleanUtils.toInteger(false) = 0
From source file:com.redhat.rhn.frontend.xmlrpc.apitest.TestHandler.java
/** * Check whether the xmlrpc server env is hosted or not. * * @return 1 if system is a satellite./*from w w w. ja v a 2 s.co m*/ */ public int envIsSatellite() { return BooleanUtils.toInteger(true); }
From source file:com.tesora.dve.common.catalog.Collations.java
public Collations(String name, String characterSetName, int id, boolean isDefault, boolean isCompiled, long sortlen) { this.name = name; this.characterSetName = characterSetName; this.id = id; this.isDefault = BooleanUtils.toInteger(isDefault); this.isCompiled = BooleanUtils.toInteger(isCompiled); this.sortlen = sortlen; }
From source file:com.tesora.dve.upgrade.versions.AddCollation.java
@Override public void upgrade(DBHelper helper, InformationCallback stdout) throws PEException { super.upgrade(helper, stdout); try {/*from w w w . j a v a2s . c om*/ List<Object> params = new ArrayList<Object>(); helper.prepare( "insert into collations (id, name, character_set_name, is_default, is_compiled, sortlen) values (?,?,?,?,?,?)"); for (String collationName : MysqlNativeCollationCatalog.DEFAULT_CATALOG .getCollationsCatalogEntriesByName()) { NativeCollation nc = MysqlNativeCollationCatalog.DEFAULT_CATALOG.findCollationByName(collationName); params.clear(); params.add(nc.getId()); params.add(nc.getName()); params.add(nc.getCharacterSetName()); params.add(BooleanUtils.toInteger(nc.isDefault())); params.add(BooleanUtils.toInteger(nc.isCompiled())); params.add(nc.getSortLen()); helper.executePrepared(params); } } catch (SQLException sqle) { throw new PEException("Unable to insert collation values: " + sqle.getMessage()); } }
From source file:com.swordlord.gozer.datatypeformat.DataTypeHelper.java
/** * Return compatible class for typedValue based on untypedValueClass * /* w ww .jav a 2 s .com*/ * @param untypedValueClass * @param typedValue * @return */ public static Object fromDataType(Class<?> untypedValueClass, Object typedValue) { Log LOG = LogFactory.getLog(DataTypeHelper.class); if (typedValue == null) { return null; } if (untypedValueClass == null) { return typedValue; } if (ClassUtils.isAssignable(typedValue.getClass(), untypedValueClass)) { return typedValue; } String strTypedValue = null; boolean isStringTypedValue = typedValue instanceof String; Number numTypedValue = null; boolean isNumberTypedValue = typedValue instanceof Number; Boolean boolTypedValue = null; boolean isBooleanTypedValue = typedValue instanceof Boolean; Date dateTypedValue = null; boolean isDateTypedValue = typedValue instanceof Date; if (isStringTypedValue) { strTypedValue = (String) typedValue; } if (isNumberTypedValue) { numTypedValue = (Number) typedValue; } if (isBooleanTypedValue) { boolTypedValue = (Boolean) typedValue; } if (isDateTypedValue) { dateTypedValue = (Date) typedValue; } Object v = null; if (String.class.equals(untypedValueClass)) { v = ObjectUtils.toString(typedValue); } else if (BigDecimal.class.equals(untypedValueClass)) { if (isStringTypedValue) { v = NumberUtils.createBigDecimal(strTypedValue); } else if (isNumberTypedValue) { v = new BigDecimal(numTypedValue.doubleValue()); } else if (isBooleanTypedValue) { v = new BigDecimal(BooleanUtils.toInteger(boolTypedValue.booleanValue())); } else if (isDateTypedValue) { v = new BigDecimal(dateTypedValue.getTime()); } } else if (Boolean.class.equals(untypedValueClass)) { if (isStringTypedValue) { v = BooleanUtils.toBooleanObject(strTypedValue); } else if (isNumberTypedValue) { v = BooleanUtils.toBooleanObject(numTypedValue.intValue()); } else if (isDateTypedValue) { v = BooleanUtils.toBooleanObject((int) dateTypedValue.getTime()); } } else if (Byte.class.equals(untypedValueClass)) { if (isStringTypedValue) { v = Byte.valueOf(strTypedValue); } else if (isNumberTypedValue) { v = new Byte(numTypedValue.byteValue()); } else if (isBooleanTypedValue) { v = new Byte((byte) BooleanUtils.toInteger(boolTypedValue.booleanValue())); } else if (isDateTypedValue) { v = new Byte((byte) dateTypedValue.getTime()); } } else if (byte[].class.equals(untypedValueClass)) { if (isStringTypedValue) { v = strTypedValue.getBytes(); } } else if (Double.class.equals(untypedValueClass)) { if (isStringTypedValue) { v = NumberUtils.createDouble(strTypedValue); } else if (isNumberTypedValue) { v = new Double(numTypedValue.doubleValue()); } else if (isBooleanTypedValue) { v = new Double(BooleanUtils.toInteger(boolTypedValue.booleanValue())); } else if (isDateTypedValue) { v = new Double(dateTypedValue.getTime()); } } else if (Float.class.equals(untypedValueClass)) { if (isStringTypedValue) { v = NumberUtils.createFloat(strTypedValue); } else if (isNumberTypedValue) { v = new Float(numTypedValue.floatValue()); } else if (isBooleanTypedValue) { v = new Float(BooleanUtils.toInteger(boolTypedValue.booleanValue())); } else if (isDateTypedValue) { v = new Float(dateTypedValue.getTime()); } } else if (Short.class.equals(untypedValueClass)) { if (isStringTypedValue) { v = NumberUtils.createInteger(strTypedValue); } else if (isNumberTypedValue) { v = new Integer(numTypedValue.intValue()); } else if (isBooleanTypedValue) { v = BooleanUtils.toIntegerObject(boolTypedValue.booleanValue()); } else if (isDateTypedValue) { v = new Integer((int) dateTypedValue.getTime()); } } else if (Integer.class.equals(untypedValueClass)) { if (isStringTypedValue) { v = NumberUtils.createInteger(strTypedValue); } else if (isNumberTypedValue) { v = new Integer(numTypedValue.intValue()); } else if (isBooleanTypedValue) { v = BooleanUtils.toIntegerObject(boolTypedValue.booleanValue()); } else if (isDateTypedValue) { v = new Integer((int) dateTypedValue.getTime()); } } else if (Long.class.equals(untypedValueClass)) { if (isStringTypedValue) { v = NumberUtils.createLong(strTypedValue); } else if (isNumberTypedValue) { v = new Long(numTypedValue.longValue()); } else if (isBooleanTypedValue) { v = new Long(BooleanUtils.toInteger(boolTypedValue.booleanValue())); } else if (isDateTypedValue) { v = new Long(dateTypedValue.getTime()); } } else if (java.sql.Date.class.equals(untypedValueClass)) { if (isNumberTypedValue) { v = new java.sql.Date(numTypedValue.longValue()); } else if (isDateTypedValue) { v = new java.sql.Date(dateTypedValue.getTime()); } } else if (java.sql.Time.class.equals(untypedValueClass)) { if (isNumberTypedValue) { v = new java.sql.Time(numTypedValue.longValue()); } else if (isDateTypedValue) { v = new java.sql.Time(dateTypedValue.getTime()); } } else if (java.sql.Timestamp.class.equals(untypedValueClass)) { if (isNumberTypedValue) { v = new java.sql.Timestamp(numTypedValue.longValue()); } else if (isDateTypedValue) { v = new java.sql.Timestamp(dateTypedValue.getTime()); } } else if (Date.class.equals(untypedValueClass)) { if (isNumberTypedValue) { v = new Date(numTypedValue.longValue()); } else if (isStringTypedValue) { try { v = DateFormat.getDateInstance().parse(strTypedValue); } catch (ParseException e) { LOG.error("Unable to parse the date : " + strTypedValue); LOG.debug(e.getMessage()); } } } return v; }
From source file:jp.primecloud.auto.process.zabbix.ZabbixProcessClient.java
public String updateHost(String hostid, String hostname, String fqdn, List<Hostgroup> hostgroups, Boolean status, Boolean userIp, String ip, String proxyHostid) { HostUpdateParam param = new HostUpdateParam(); param.setHostid(hostid);/*from w ww . j ava 2 s .c om*/ param.setHost(hostname); param.setGroups(hostgroups); param.setDns(fqdn); param.setPort(10050); if (status != null) { param.setStatus(status ? 0 : 1);// ???0????1 } if (userIp != null) { param.setUseip(BooleanUtils.toInteger(userIp));// DNS???0?IP???1 param.setIp(StringUtils.isEmpty(ip) ? "0.0.0.0" : ip); } if (StringUtils.isNotEmpty(proxyHostid)) { param.setProxyHostid(proxyHostid); } List<String> hostids = zabbixClient.host().update(param); hostid = hostids.get(0); if (log.isInfoEnabled()) { List<String> groupids = new ArrayList<String>(); if (hostgroups != null) { for (Hostgroup hostgroup : hostgroups) { groupids.add(hostgroup.getGroupid()); } } log.info(MessageUtils.getMessage("IPROCESS-100312", hostid, fqdn, groupids, status)); } return hostid; }
From source file:com.zimbra.cs.gal.GalSearchControl.java
private String getLdapSearchResultToken(SearchGalResult result, String initialString) { StringBuilder buf;//ww w . jav a 2 s . co m if (StringUtils.isEmpty(initialString)) { buf = new StringBuilder(); } else { buf = new StringBuilder(initialString); buf.append("_"); } buf.append(result.getLdapTimeStamp()).append("_").append(result.getLdapMatchCount()).append("_") .append(BooleanUtils.toInteger(result.getHadMore())); buf.append("_").append(result.getToken()); return buf.toString(); }
From source file:com.tesora.dve.tools.aitemplatebuilder.AiTemplateBuilder.java
private void identifyCandidateModels(final Collection<TableStats> tables, final boolean isRowWidthWeightingEnabled) throws Exception { final SortedSet<Long> sortedCardinalities = new TreeSet<Long>(); final SortedSet<Long> uniqueOperationFrequencies = new TreeSet<Long>(); for (final TableStats table : tables) { sortedCardinalities.add(table.getPredictedFutureSize(isRowWidthWeightingEnabled)); uniqueOperationFrequencies.add(table.getWriteStatementCount()); }//from w w w . j ava 2 s. c o m for (final TableStats table : tables) { final TemplateModelItem baseModel = findBaseModel(table); if (baseModel != null) { table.setTableDistributionModel(baseModel); table.setDistributionModelFreezed(true); logTableDistributionModel(table, MessageSeverity.ALERT); } else { final double sortsWeight = BooleanUtils.toInteger(this.enableUsingSorts); final double writesWeight = BooleanUtils.toInteger(isUsingWrites(table, this.enableUsingWrites)); final ImmutableMap<FlvName, Double> ruleWeights = ImmutableMap.<FlvName, Double>of( FuzzyTableDistributionModel.Variables.SORTS_FLV_NAME, sortsWeight, FuzzyTableDistributionModel.Variables.WRITES_FLV_NAME, writesWeight); final List<FuzzyTableDistributionModel> modelsSortedByScore = FuzzyLinguisticVariable .evaluateDistributionModels(ruleWeights, new Broadcast(table, uniqueOperationFrequencies, sortedCardinalities, isRowWidthWeightingEnabled), new Range(table, uniqueOperationFrequencies, sortedCardinalities, isRowWidthWeightingEnabled)); table.setTableDistributionModel( Collections.max(modelsSortedByScore, FuzzyLinguisticVariable.getScoreComparator())); log(table.toString().concat(": ").concat(StringUtils.join(modelsSortedByScore, ", "))); } } }
From source file:com.redhat.rhn.frontend.xmlrpc.channel.software.ChannelSoftwareHandler.java
/** * Returns whether the channel may be subscribed to by the given user. * @param loggedInUser The current user/*from w w w . j a va 2 s .co m*/ * @param channelLabel The label for the channel in question * @param login The login for the user in question * @return whether the channel may be subscribed to by the given user. * @throws FaultException thrown if * - The loggedInUser doesn't have permission to perform this action * - The login, sessionKey, or channelLabel is invalid * * @xmlrpc.doc Returns whether the channel may be subscribed to by the given user. * @xmlrpc.param #session_key() * @xmlrpc.param #param_desc("string", "channelLabel", "label of the channel") * @xmlrpc.param #param_desc("string", "login", "login of the target user") * @xmlrpc.returntype int - 1 if subscribable, 0 if not */ public int isUserSubscribable(User loggedInUser, String channelLabel, String login) throws FaultException { User target = XmlRpcUserHelper.getInstance().lookupTargetUser(loggedInUser, login); Channel channel = lookupChannelByLabel(loggedInUser.getOrg(), channelLabel); //Verify permissions if (!(UserManager.verifyChannelAdmin(loggedInUser, channel) || loggedInUser.hasRole(RoleFactory.CHANNEL_ADMIN))) { throw new PermissionCheckFailureException(); } boolean flag = ChannelManager.verifyChannelSubscribe(target, channel.getId()); return BooleanUtils.toInteger(flag); }
From source file:com.redhat.rhn.frontend.xmlrpc.channel.software.ChannelSoftwareHandler.java
/** * Returns whether the channel may be managed by the given user. * @param loggedInUser The current user/*from ww w. j a v a2 s.c o m*/ * @param channelLabel The label for the channel in question * @param login The login for the user in question * @return whether the channel may be managed by the given user. * @throws FaultException thrown if * - The loggedInUser doesn't have permission to perform this action * - The login, sessionKey, or channelLabel is invalid * * @xmlrpc.doc Returns whether the channel may be managed by the given user. * @xmlrpc.param #session_key() * @xmlrpc.param #param_desc("string", "channelLabel", "label of the channel") * @xmlrpc.param #param_desc("string", "login", "login of the target user") * @xmlrpc.returntype int - 1 if manageable, 0 if not */ public int isUserManageable(User loggedInUser, String channelLabel, String login) throws FaultException { User target = XmlRpcUserHelper.getInstance().lookupTargetUser(loggedInUser, login); Channel channel = lookupChannelByLabel(loggedInUser.getOrg(), channelLabel); if (!channel.isCustom()) { throw new InvalidChannelException("Manageable flag is relevant for custom channels only."); } //Verify permissions if (!(UserManager.verifyChannelAdmin(loggedInUser, channel) || loggedInUser.hasRole(RoleFactory.CHANNEL_ADMIN))) { throw new PermissionCheckFailureException(); } boolean flag = ChannelManager.verifyChannelManage(target, channel.getId()); return BooleanUtils.toInteger(flag); }
From source file:org.apache.kylin.metadata.datatype.BooleanSerializer.java
@Override public Long valueOf(String str) { if (str == null) return Long.valueOf(0L); else//from ww w .ja v a 2 s . c o m return Long.valueOf(BooleanUtils.toInteger(ArrayUtils.contains(TRUE_VALUE_SET, str.toLowerCase()))); }