下面列出了java.util.Properties#toString ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private InfrastructureParameter getRandomInfraParamForType(String type, int randomIndex) {
switch (type) {
case osPramKey:
return new InfrastructureParameter(osParamVals.get(randomIndex),
osPramKey, "", true);
case jdkParamKey:
return new InfrastructureParameter(jdkParamVals.get(randomIndex),
jdkParamKey, "", true);
case dbEngineParamKey:
default:
Properties props = new Properties();
props.setProperty(dbEngineVersionPropKey, dbEngineVersionPropVal);
return new InfrastructureParameter(dbParamVals.get(randomIndex),
dbEngineParamKey, props.toString(), true);
}
}
public SimplePropertiesCredentials(final Properties accountProperties) {
if (accountProperties == null) {
throw new IllegalArgumentException("AccountProperties should never be null");
}
//
if (accountProperties.getProperty("accessKey") == null || accountProperties.getProperty("secretKey") == null) {
throw new IllegalArgumentException(
"The specified properties (" + accountProperties.toString()
+ ") doesn't contain the expected properties 'accessKey' " + "and 'secretKey'.");
}
final String accessKey = accountProperties.getProperty("accessKey");
final String secretKey = accountProperties.getProperty("secretKey");
awsCredentials = new BasicAWSCredentials(accessKey, secretKey);
}
@Override
public void lmsCommit(final String olatSahsId, final Properties scoScores) {
// only write score info when node is configured to do so
if (isAssessable) {
// do a sum-of-scores over all sco scores
float score = 0f;
for (final Iterator it_score = scoScores.values().iterator(); it_score.hasNext();) {
final String aScore = (String) it_score.next();
final float ascore = Float.parseFloat(aScore);
score += ascore;
}
final float cutval = scormNode.getCutValueConfiguration().floatValue();
final boolean passed = (score >= cutval);
final ScoreEvaluation sceval = new ScoreEvaluation(new Float(score), Boolean.valueOf(passed));
final boolean incrementAttempts = false;
scormNode.updateUserScoreEvaluation(sceval, userCourseEnv, identity, incrementAttempts);
userCourseEnv.getScoreAccounting().scoreInfoChanged(scormNode, sceval);
if (log.isDebugEnabled()) {
final String msg = "for scorm node:" + scormNode.getIdent() + " (" + scormNode.getShortTitle() + ") a lmsCommit for scoId " + olatSahsId
+ " occured, total sum = " + score + ", cutvalue =" + cutval + ", passed: " + passed + ", all scores now = " + scoScores.toString();
log.debug(msg);
}
}
}
@Override
public void lmsCommit(final String olatSahsId, final Properties scoScores) {
// only write score info when node is configured to do so
if (isAssessable) {
// do a sum-of-scores over all sco scores
float score = 0f;
for (final Iterator it_score = scoScores.values().iterator(); it_score.hasNext();) {
final String aScore = (String) it_score.next();
final float ascore = Float.parseFloat(aScore);
score += ascore;
}
final float cutval = scormNode.getCutValueConfiguration().floatValue();
final boolean passed = (score >= cutval);
final ScoreEvaluation sceval = new ScoreEvaluation(new Float(score), Boolean.valueOf(passed));
final boolean incrementAttempts = false;
scormNode.updateUserScoreEvaluation(sceval, userCourseEnv, identity, incrementAttempts);
userCourseEnv.getScoreAccounting().scoreInfoChanged(scormNode, sceval);
if (log.isDebugEnabled()) {
final String msg = "for scorm node:" + scormNode.getIdent() + " (" + scormNode.getShortTitle() + ") a lmsCommit for scoId " + olatSahsId
+ " occured, total sum = " + score + ", cutvalue =" + cutval + ", passed: " + passed + ", all scores now = " + scoScores.toString();
log.debug(msg);
}
}
}
/**
* Parse cassandra column family name from table properties.
*
* @param tbl table properties
* @return cassandra column family name
* @throws SerDeException error parsing column family name
*/
protected String getCassandraColumnFamily(Properties tbl) throws SerDeException {
String result = tbl.getProperty(CASSANDRA_CF_NAME);
if (result == null) {
result = tbl
.getProperty(org.apache.hadoop.hive.metastore.api.Constants.META_TABLE_NAME);
if (result == null) {
throw new SerDeException("CassandraColumnFamily not defined" + tbl.toString());
}
if (result.indexOf(".") != -1) {
result = result.substring(result.indexOf(".") + 1);
}
}
return result;
}
@Override
public String getAsText() {
Properties value = (Properties) getValue();
if (value == null || value.isEmpty()) {
return NbBundle.getMessage(PropertiesEditor.class,
"NoPropertiesSet"); //NOI18N
} else {
return value.toString();
}
}
public UtilResourceBundle(Properties properties, Locale locale, UtilResourceBundle parent) {
this.properties = properties;
this.locale = locale;
setParent(parent);
String hashString = properties.toString();
if (parent != null) {
hashString += parent.properties;
}
this.hashCode = hashString.hashCode();
}
private Session getSession(String _host, String _port, String _timeout, boolean _auth, String _returnPath, SendType _sendType) {
Properties props = new Properties();
String propPrefix = "mail.smtp";
if (_sendType == SendType.SSL) {
propPrefix += "s";
}
props.put(propPrefix + ".host", _host);
props.put(propPrefix + ".port", _port);
props.put(propPrefix + ".timeout", _timeout);
if (_sendType == SendType.TLS) {
props.put(propPrefix + ".starttls.enable", "true");
props.put(propPrefix + ".starttls.required", "true");
}
if (domain.length() != 0) {
props.put(propPrefix + ".localhost", domain);
}
if (_auth) {
props.put(propPrefix + ".auth", "true");
}
if (_returnPath != null) { // fix for bug #2986
props.put(propPrefix + ".from", _returnPath);
}
String key = props.toString();
Session session = (Session) sessions.get(key);
// -- if session doesn't already exist, create one
if (session == null) {
session = Session.getInstance(props);
sessions.put(key, session);
}
return session;
}
public String getProperties() {
Properties properties = new Properties();
properties.putAll(connectProperties);
if (properties.containsKey("password")) {
properties.put("password", "******");
}
return properties.toString();
}
/**
* Construct a task from {@code Properties}. This method is used on the
* receiving side. That is, it is used to construct a {@code Task} from an
* HttpRequest sent from the App Engine task queue. {@code properties} must
* contain a property named {@link #TASK_TYPE_PARAMETER}. In addition it must
* contain the properties specified by the concrete subclass of this class
* corresponding to the task type.
*/
public static Task fromProperties(String taskName, Properties properties) {
String taskTypeString = properties.getProperty(TASK_TYPE_PARAMETER);
if (null == taskTypeString) {
throw new IllegalArgumentException(TASK_TYPE_PARAMETER + " property is missing: "
+ properties.toString());
}
Type type = Type.valueOf(taskTypeString);
return type.createInstance(taskName, properties);
}
/**
* Create a proxied user, taking all parameters, including which user to proxy
* from provided Properties.
*/
public static UserGroupInformation getProxiedUser(Properties prop,
Logger log, Configuration conf) throws IOException {
String toProxy = verifySecureProperty(prop, TO_PROXY, log);
UserGroupInformation user = getProxiedUser(toProxy, prop, log, conf);
if (user == null)
throw new IOException(
"Proxy as any user in unsecured grid is not supported!"
+ prop.toString());
log.info("created proxy user for " + user.getUserName() + user.toString());
return user;
}
/**
* WL#411 - Generated columns.
*
* Test for new syntax and support in DatabaseMetaData.getColumns().
*
* New syntax for CREATE TABLE, introduced in MySQL 5.7.6:
* -col_name data_type [GENERATED ALWAYS] AS (expression) [VIRTUAL | STORED] [UNIQUE [KEY]] [COMMENT comment] [[NOT] NULL] [[PRIMARY] KEY]
*/
public void testGeneratedColumns() throws Exception {
if (!versionMeetsMinimum(5, 7, 6)) {
return;
}
// Test GENERATED columns syntax.
createTable("pythagorean_triple", "(side_a DOUBLE NULL, side_b DOUBLE NULL, "
+ "side_c_vir DOUBLE AS (SQRT(side_a * side_a + side_b * side_b)) VIRTUAL UNIQUE KEY COMMENT 'hypotenuse - virtual', "
+ "side_c_sto DOUBLE GENERATED ALWAYS AS (SQRT(POW(side_a, 2) + POW(side_b, 2))) STORED UNIQUE KEY COMMENT 'hypotenuse - stored' NOT NULL "
+ "PRIMARY KEY)");
// Test data for generated columns.
assertEquals(1, this.stmt.executeUpdate("INSERT INTO pythagorean_triple (side_a, side_b) VALUES (3, 4)"));
this.rs = this.stmt.executeQuery("SELECT * FROM pythagorean_triple");
assertTrue(this.rs.next());
assertEquals(3d, this.rs.getDouble(1));
assertEquals(4d, this.rs.getDouble(2));
assertEquals(5d, this.rs.getDouble(3));
assertEquals(5d, this.rs.getDouble(4));
assertEquals(3d, this.rs.getDouble("side_a"));
assertEquals(4d, this.rs.getDouble("side_b"));
assertEquals(5d, this.rs.getDouble("side_c_sto"));
assertEquals(5d, this.rs.getDouble("side_c_vir"));
assertFalse(this.rs.next());
Properties props = new Properties();
props.setProperty(PropertyKey.nullCatalogMeansCurrent.getKeyName(), "true");
for (String useIS : new String[] { "false", "true" }) {
Connection testConn = null;
props.setProperty(PropertyKey.useInformationSchema.getKeyName(), useIS);
testConn = getConnectionWithProps(props);
DatabaseMetaData dbmd = testConn.getMetaData();
String test = "Case [" + props.toString() + "]";
// Test columns metadata.
this.rs = dbmd.getColumns(null, null, "pythagorean_triple", "%");
assertTrue(test, this.rs.next());
assertEquals(test, "side_a", this.rs.getString("COLUMN_NAME"));
assertEquals(test, "YES", this.rs.getString("IS_NULLABLE"));
assertEquals(test, "NO", this.rs.getString("IS_AUTOINCREMENT"));
assertEquals(test, "NO", this.rs.getString("IS_GENERATEDCOLUMN"));
assertTrue(test, this.rs.next());
assertEquals(test, "side_b", this.rs.getString("COLUMN_NAME"));
assertEquals(test, "YES", this.rs.getString("IS_NULLABLE"));
assertEquals(test, "NO", this.rs.getString("IS_AUTOINCREMENT"));
assertEquals(test, "NO", this.rs.getString("IS_GENERATEDCOLUMN"));
assertTrue(test, this.rs.next());
assertEquals(test, "side_c_vir", this.rs.getString("COLUMN_NAME"));
assertEquals(test, "YES", this.rs.getString("IS_NULLABLE"));
assertEquals(test, "NO", this.rs.getString("IS_AUTOINCREMENT"));
assertEquals(test, "YES", this.rs.getString("IS_GENERATEDCOLUMN"));
assertTrue(test, this.rs.next());
assertEquals(test, "side_c_sto", this.rs.getString("COLUMN_NAME"));
assertEquals(test, "NO", this.rs.getString("IS_NULLABLE"));
assertEquals(test, "NO", this.rs.getString("IS_AUTOINCREMENT"));
assertEquals(test, "YES", this.rs.getString("IS_GENERATEDCOLUMN"));
assertFalse(test, this.rs.next());
// Test primary keys metadata.
this.rs = dbmd.getPrimaryKeys(null, null, "pythagorean_triple");
assertTrue(test, this.rs.next());
assertEquals(test, "side_c_sto", this.rs.getString("COLUMN_NAME"));
assertEquals(test, "PRIMARY", this.rs.getString("PK_NAME"));
assertFalse(test, this.rs.next());
// Test indexes metadata.
this.rs = dbmd.getIndexInfo(null, null, "pythagorean_triple", false, true);
assertTrue(test, this.rs.next());
assertEquals(test, "PRIMARY", this.rs.getString("INDEX_NAME"));
assertEquals(test, "side_c_sto", this.rs.getString("COLUMN_NAME"));
assertTrue(test, this.rs.next());
assertEquals(test, "side_c_sto", this.rs.getString("INDEX_NAME"));
assertEquals(test, "side_c_sto", this.rs.getString("COLUMN_NAME"));
assertTrue(test, this.rs.next());
assertEquals(test, "side_c_vir", this.rs.getString("INDEX_NAME"));
assertEquals(test, "side_c_vir", this.rs.getString("COLUMN_NAME"));
assertFalse(test, this.rs.next());
testConn.close();
}
}