本文整理汇总了Java中java.text.Format类的典型用法代码示例。如果您正苦于以下问题:Java Format类的具体用法?Java Format怎么用?Java Format使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Format类属于java.text包,在下文中一共展示了Format类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getFormat
import java.text.Format; //导入依赖的package包/类
/**
* Returns format's pattern.
*
* @return format's pattern.
*/
public String getFormat() {
if (format != null) return format;
String fmt = null;
if (formatter instanceof MaskFormatter) {
fmt = ((MaskFormatter)formatter).getMask();
} else if (formatter instanceof InternationalFormatter) {
Format f = ((InternationalFormatter)formatter).getFormat();
if (f instanceof DecimalFormat) {
fmt = ((DecimalFormat)f).toPattern();
} else if (f instanceof SimpleDateFormat) {
fmt = ((SimpleDateFormat)f).toPattern();
}
}
return fmt;
}
示例2: getValueString
import java.text.Format; //导入依赖的package包/类
protected String getValueString(Object value, int row, Format format) {
if (value == null) return "-"; // NOI18N
StringBuilder s = new StringBuilder();
s.append("("); // NOI18N
if (maxValue == 0) {
s.append(NAN);
} else {
double number = ((Number)value).doubleValue();
if (number == 0) {
if (renderingDiff) s.append('+'); // NOI18N
s.append(NUL);
} else {
number = number / maxValue;
if (renderingDiff && number > 0) s.append('+'); // NOI18N
s.append(format.format(number));
}
}
s.append(")"); // NOI18N
return s.toString();
}
示例3: mbushPunetoret
import java.text.Format; //导入依赖的package包/类
public void mbushPunetoret(){
try {
String sql = "select * from Punetoret";
Connection conn = DriverManager.getConnection(CON_STR, "test", "test");
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(sql);
ObservableList<TabelaPunetoret> data = FXCollections.observableArrayList();
Format format = new SimpleDateFormat("dd/MM/yyyy");
while (rs.next()){
String s = format.format(rs.getDate("regjistrimi"));
data.add(new TabelaPunetoret(rs.getInt("id"), rs.getString("emri"),
rs.getString("mbiemri"), rs.getString("komuna"), rs.getString("pozita"),
s, rs.getFloat("paga")));
}
table.setItems(data);
conn.close();
}catch (Exception ex){ex.printStackTrace();}
}
示例4: formatWithTimeZone
import java.text.Format; //导入依赖的package包/类
protected String formatWithTimeZone(
String template,
Object[] arguments,
Locale locale,
TimeZone timezone)
{
MessageFormat mf = new MessageFormat(" ");
mf.setLocale(locale);
mf.applyPattern(template);
if (!timezone.equals(TimeZone.getDefault()))
{
Format[] formats = mf.getFormats();
for (int i = 0; i < formats.length; i++)
{
if (formats[i] instanceof DateFormat)
{
DateFormat temp = (DateFormat) formats[i];
temp.setTimeZone(timezone);
mf.setFormat(i,temp);
}
}
}
return mf.format(arguments);
}
示例5: findAllByName
import java.text.Format; //导入依赖的package包/类
/**
* Find the repositories matching to the given criteria.Look into name only.
*
* @param criteria
* the search criteria.
* @param node
* the node to be tested with given parameters.
* @return project name.
*/
@GET
@Path("{node}/{criteria}")
@Consumes(MediaType.APPLICATION_JSON)
public List<NamedBean<String>> findAllByName(@PathParam("node") final String node, @PathParam("criteria") final String criteria) {
final Map<String, String> parameters = pvResource.getNodeParameters(node);
final CurlRequest request = new CurlRequest(HttpMethod.GET, StringUtils.appendIfMissing(parameters.get(parameterUrl), "/"), null);
request.setSaveResponse(true);
newCurlProcessor(parameters).process(request);
// Prepare the context, an ordered set of projects
final Format format = new NormalizeFormat();
final String formatCriteria = format.format(criteria);
// Limit the result
return inMemoryPagination.newPage(
Arrays.stream(StringUtils.splitByWholeSeparator(StringUtils.defaultString(request.getResponse()), "<a href=\"")).skip(1)
.filter(s -> format.format(s).contains(formatCriteria))
.map(s -> StringUtils.removeEnd(s.substring(0, Math.max(0, s.indexOf('\"'))), "/"))
.filter(((Predicate<String>) String::isEmpty).negate()).map(id -> new NamedBean<>(id, id)).collect(Collectors.toList()),
PageRequest.of(0, 10)).getContent();
}
示例6: getCpu
import java.text.Format; //导入依赖的package包/类
/**
* du can be relatively expensive - we will cache almost always timers will
* be reset in case of operation
*/
@RequestMapping ( "/getCpu" )
public ObjectNode getCpu (
@RequestParam ( value = "filter" , defaultValue = "yes" , required = false ) String compressedFormat,
HttpServletResponse response )
throws IOException {
logger.debug( "compressedFormat: {}", compressedFormat );
response.setContentType( MediaType.APPLICATION_JSON_VALUE );
ObjectNode serviceMetricsJson = osManager.getServiceMetrics( compressedFormat.equals( "yes" ) );
Format tsFormater = new SimpleDateFormat( "HH.mm.ss" );
// JsonNode rootNode = jacksonMapper.valueToTree(commandMap);
((ObjectNode) serviceMetricsJson).put( "timestamp", tsFormater.format( new Date() ) );
return serviceMetricsJson;
}
示例7: filtro
import java.text.Format; //导入依赖的package包/类
private void filtro(){
try {
String sql;
if (!txtPuna.getText().isEmpty())
sql = "select * from Punet where konsumatori = '" + e.getText() + "' and lower(lloji) like lower('%" + txtPuna.getText() + "%')";
else
sql = "select * from Punet where konsumatori = '" + e.getText() + "'";
Connection conn = DriverManager.getConnection(CON_STR, "test", "test");
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(sql);
ObservableList<punetTbl> data = FXCollections.observableArrayList();
Format format = new SimpleDateFormat("dd/MM/yyyy");
String s = "";
while (rs.next()){
s = format.format(rs.getDate("data"));
data.add(new punetTbl(rs.getInt("id"), rs.getString("lloji"),
s, rs.getFloat("qmimi"), rs.getString("pershkrimi"), rs.getString("kryer"), rs.getString("makina")));
}
table.setItems(data);
conn.close();
}catch (Exception ex){
ex.printStackTrace();
}
}
示例8: getFormatByArgumentName
import java.text.Format; //导入依赖的package包/类
/**
* {@icu} Returns the first top-level format associated with the given argument name.
* For more details, see {@link #setFormatByArgumentName(String, Format)}.
* @param argumentName The name of the desired argument.
* @return the Format associated with the name, or null if there isn't one.
* @stable ICU 4.8
*/
public Format getFormatByArgumentName(String argumentName) {
if (cachedFormatters == null) {
return null;
}
int argNumber = MessagePattern.validateArgumentName(argumentName);
if (argNumber < MessagePattern.ARG_NAME_NOT_NUMBER) {
return null;
}
for (int partIndex = 0; (partIndex = nextTopLevelArgStart(partIndex)) >= 0;) {
if (argNameMatches(partIndex + 1, argumentName, argNumber)) {
return cachedFormatters.get(partIndex);
}
}
return null;
}
示例9: mbush
import java.text.Format; //导入依赖的package包/类
public void mbush(String emri){
Thread t = new Thread(new Runnable() {
@Override
public void run() {
try {
String sql = "select * from Punet where punetori = '" + emri + "' order by id asc";
Connection conn = DriverManager.getConnection(CON_STR, "test", "test");
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(sql);
ObservableList<TabelaTeDhenatPunetore> data = FXCollections.observableArrayList();
Format format = new SimpleDateFormat("dd/MM/yyyy");
String s = "";
while (rs.next()) {
s = format.format(rs.getDate("data"));
data.add(new TabelaTeDhenatPunetore(rs.getInt("id"), rs.getString("lloji"), s,
rs.getFloat("qmimi"), rs.getString("konsumatori"), rs.getString("pershkrimi"), rs.getString("kryer"), rs.getString("makina")));
}
rs.close();
stmt.close();
conn.close();
table.setItems(data);
}catch (Exception ex){ex.printStackTrace();}
}
});
t.start();
}
示例10: getCalendarField
import java.text.Format; //导入依赖的package包/类
/**
* Returns the calendarField under the start of the selection, or -1 if
* there is no valid calendar field under the selection (or the spinner
* isn't editing dates.
*/
private int getCalendarField(JSpinner spinner)
{
JComponent editor = spinner.getEditor();
if( editor instanceof JSpinner.DateEditor )
{
JSpinner.DateEditor dateEditor = (JSpinner.DateEditor) editor;
JFormattedTextField ftf = dateEditor.getTextField();
int start = ftf.getSelectionStart();
JFormattedTextField.AbstractFormatter formatter = ftf.getFormatter();
if( formatter instanceof InternationalFormatter )
{
Format.Field[] fields = ((InternationalFormatter) formatter).getFields(start);
for( int counter = 0; counter < fields.length; counter++ )
{
if( fields[counter] instanceof DateFormat.Field )
{
int calendarField;
if( fields[counter] == DateFormat.Field.HOUR1 )
{
calendarField = Calendar.HOUR;
}
else
{
calendarField = ((DateFormat.Field) fields[counter]).getCalendarField();
}
if( calendarField != -1 )
{
return calendarField;
}
}
}
}
}
return -1;
}
示例11: getFormat
import java.text.Format; //导入依赖的package包/类
/**
* Get a custom format from a format description.
*
* @param desc String
* @return Format
*/
private Format getFormat(String desc) {
if (registry != null) {
String name = desc;
String args = null;
int i = desc.indexOf(START_FMT);
if (i > 0) {
name = desc.substring(0, i).trim();
args = desc.substring(i + 1).trim();
}
FormatFactory factory = (FormatFactory) registry.get(name);
if (factory != null) {
return factory.getFormat(name, args, getLocale());
}
}
return null;
}
示例12: findAll
import java.text.Format; //导入依赖的package包/类
/**
* Call a Fortify REST service to fetch items by their name.<br>
* NOTE : process manager will be shut down.
*
* @param node
* node to query.
* @param url
* query URL.
* @param criteria
* Optional name to match.
* @return Projects matching to the given criteria.
*/
private Collection<FortifyProject> findAll(final String node, final String url, final String criteria)
throws IOException {
// Check the user can log-in to Fortify
final Collection<Map<String, Object>> data = getFortifyResource(this.pvResource.getNodeParameters(node),
url);
final Format format = new NormalizeFormat();
final String formatCriteria = format.format(StringUtils.trimToEmpty(criteria));
// Filter by criteria on the project name
final Map<Integer, FortifyProject> result = new TreeMap<>();
data.stream().filter(item -> (format.format(item.get("name"))).contains(formatCriteria)).forEach(item -> {
final FortifyProject entry = toProject(item);
result.put(entry.getId(), entry);
});
return result.values();
}
示例13: writeData
import java.text.Format; //导入依赖的package包/类
/**
* Write issue data
*/
private void writeData(final JiraChangeItem change, final String key, final Writer writer, final Format df, final Format idf) throws IOException {
// Write static data
writer.write(change.getId().toString());
writer.write(';');
writer.write(key);
writer.write(';');
writer.write(ObjectUtils.defaultIfNull(change.getAuthor(), change.getReporter()));
writer.write(';');
writer.write(ObjectUtils.defaultIfNull(change.getFromStatus(), "").toString());
writer.write(';');
writer.write(String.valueOf(change.getToStatus()));
writer.write(';');
writer.write(idf.format(ObjectUtils.defaultIfNull(statusText.get(change.getFromStatus()), "")));
writer.write(';');
writer.write(idf.format(statusText.get(change.getToStatus())));
writer.write(';');
writer.write(df.format(change.getCreated()));
writer.write(';');
writer.write(String.valueOf(change.getCreated().getTime()));
}
示例14: writeNodeActivities
import java.text.Format; //导入依赖的package包/类
/**
* Write user's activities
*/
protected void writeNodeActivities(final Map<String, Activity> activities, final Writer writer, final Format df) throws IOException {
for (final INamableBean<String> node : computations.getNodes()) {
writer.write(';');
// Last connection, if available
final Activity activity = activities.get(node.getId());
if (activity != null) {
// There is an activity for this user and this node
writer.write(df.format(activity.getLastConnection()));
}
}
}
示例15: test_toFormat_parseObject_StringParsePosition_invalidPosition_tooBig
import java.text.Format; //导入依赖的package包/类
@Test
public void test_toFormat_parseObject_StringParsePosition_invalidPosition_tooBig() throws Exception {
// SimpleDateFormat has this behavior
DateTimeFormatter dtf = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
ParsePosition pos = new ParsePosition(6);
Format test = dtf.toFormat();
assertNull(test.parseObject("ONE30", pos));
assertTrue(pos.getErrorIndex() >= 0);
}