本文整理汇总了Java中org.cubeengine.dirigent.context.Arguments类的典型用法代码示例。如果您正苦于以下问题:Java Arguments类的具体用法?Java Arguments怎么用?Java Arguments使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Arguments类属于org.cubeengine.dirigent.context包,在下文中一共展示了Arguments类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parseDateFormatStyle
import org.cubeengine.dirigent.context.Arguments; //导入依赖的package包/类
/**
* Parses the default style of the {@link DateFormat} from context labels.
*
* @param args The arguments of the macro.
*
* @return The id of the style.
*/
private int parseDateFormatStyle(Arguments args)
{
if (args.has(SHORT_STYLE))
{
return DateFormat.SHORT;
}
else if (args.has(MEDIUM_STYLE))
{
return DateFormat.MEDIUM;
}
else if (args.has(LONG_STYLE))
{
return DateFormat.LONG;
}
else if (args.has(FULL_STYLE))
{
return DateFormat.FULL;
}
return DateFormat.DEFAULT;
}
示例2: parseFormatter
import org.cubeengine.dirigent.context.Arguments; //导入依赖的package包/类
/**
* Parses the {@link NumberFormat} to use from the context arguments.
*
* @param context The context.
* @param args The arguments of the macro.
*
* @return the {@link NumberFormat}.
*/
private NumberFormat parseFormatter(Context context, Arguments args)
{
final String format = args.get(FORMAT_PARAM_NAME);
final Locale locale = context.get(LOCALE);
if (format != null)
{
return new DecimalFormat(format, DecimalFormatSymbols.getInstance(locale));
}
final Mode mode = Mode.loadFromContext(args, this.defaultMode);
if (Mode.INTEGER.equals(mode))
{
return NumberFormat.getIntegerInstance(locale);
}
if (Mode.CURRENCY.equals(mode))
{
return NumberFormat.getCurrencyInstance(locale);
}
if (Mode.PERCENT.equals(mode))
{
return NumberFormat.getPercentInstance(locale);
}
return NumberFormat.getInstance(locale);
}
示例3: loadFromContext
import org.cubeengine.dirigent.context.Arguments; //导入依赖的package包/类
/**
* Loads the mode from the formatter context or returns the default mode if the context doesn't specify one.
*
* @param args The arguments of the macro.
* @param defaultMode The default mode.
*
* @return the loaded mode.
*/
private static Mode loadFromContext(Arguments args, Mode defaultMode)
{
if (args.has(INTEGER_MODE_FLAG))
{
return INTEGER;
}
if (args.has(CURRENCY_MODE_FLAG))
{
return CURRENCY;
}
if (args.has(PERCENT_MODE_FLAG))
{
return PERCENT;
}
return defaultMode;
}
示例4: checkFormat
import org.cubeengine.dirigent.context.Arguments; //导入依赖的package包/类
private void checkFormat(final String expected, final Object object, final Locale locale, final String flag)
{
final Arguments arguments;
if (flag == null)
{
arguments = Arguments.NONE;
}
else
{
arguments = toArgs(arg(flag));
}
final Component component = stringFormatter.format(object, createContext(locale), arguments);
Assert.assertTrue(component instanceof Text);
Assert.assertEquals(expected, ((Text)component).getText());
}
示例5: checkFormat
import org.cubeengine.dirigent.context.Arguments; //导入依赖的package包/类
private void checkFormat(final String expected, final Locale locale, final String argument)
{
final Arguments arguments;
if (argument == null)
{
arguments = Arguments.NONE;
}
else
{
arguments = toArgs(arg(argument));
}
final Component component = staticTextFormatter.format(createContext(locale), arguments);
Assert.assertTrue(component instanceof Text);
Assert.assertEquals(expected, ((Text)component).getText());
}
示例6: createArguments
import org.cubeengine.dirigent.context.Arguments; //导入依赖的package包/类
private Arguments createArguments(final String defaultStyle, final String dateStyle, final String timeStyle,
final String format)
{
final List<Object> arguments = new ArrayList<Object>();
if (defaultStyle != null)
{
arguments.add(arg(defaultStyle));
}
if (dateStyle != null)
{
arguments.add(arg(DateTimeFormatter.DATE_PARAM_NAME, dateStyle));
}
if (timeStyle != null)
{
arguments.add(arg(DateTimeFormatter.TIME_PARAM_NAME, timeStyle));
}
if (format != null)
{
arguments.add(arg(DateTimeFormatter.FORMAT_PARAM_NAME, format));
}
return toArgs(arguments.toArray());
}
示例7: toArgs
import org.cubeengine.dirigent.context.Arguments; //导入依赖的package包/类
public static Arguments toArgs(Object... args)
{
List<String> values = new ArrayList<String>();
Map<String, String> params = new HashMap<String, String>();
for (final Object arg : args)
{
if (arg instanceof String)
{
values.add((String)arg);
}
else
{
String[] pair = (String[])arg;
params.put(pair[0].toLowerCase(), pair[1]);
}
}
return Arguments.create(values, params);
}
示例8: testFormatWithPrio
import org.cubeengine.dirigent.context.Arguments; //导入依赖的package包/类
@Test
public void testFormatWithPrio() {
final TypeImpl typeImpl = new TypeImpl();
Formatter<Object> formatter = new PrioFormatter();
Component component = formatter.process(typeImpl, Contexts.EMPTY, Arguments.NONE);
Assert.assertTrue(component instanceof TextComponent);
Assert.assertEquals(typeImpl.getText(), ((TextComponent)component).getText());
component = formatter.process(new Type2()
{
@Override
public int getNumber()
{
return 34;
}
}, Contexts.EMPTY, Arguments.NONE);
Assert.assertTrue(component instanceof TextComponent);
Assert.assertEquals("34", ((TextComponent)component).getText());
}
示例9: parseArguments
import org.cubeengine.dirigent.context.Arguments; //导入依赖的package包/类
private static Arguments parseArguments(State s)
{
List<String> values = null;
Map<String, String> params = null;
while (is(s, SECTION_SEP))
{
// skip SECTION_SEP
++s.offset;
final String name = readUntil(s, PARAM_NAME_FOLLOW, false);
if (is(s, VALUE_SEP))
{
// skip VALUE_SEP
++s.offset;
if (name.isEmpty())
{
return null;
}
else
{
if (params == null)
{
params = new HashMap<String, String>(1);
}
params.put(name.toLowerCase(), readUntil(s, SECTION_FOLLOW, false));
}
}
else
{
if (values == null)
{
values = new ArrayList<String>(1);
}
values.add(name);
}
}
return Arguments.create(values, params);
}
示例10: parseObjectToString
import org.cubeengine.dirigent.context.Arguments; //导入依赖的package包/类
/**
* Parses the given object to a string depending on the context.
*
* @param object The object to parse.
* @param locale The locale to use.
*
* @return The object as a string.
*/
protected String parseObjectToString(Object object, Locale locale, Arguments args)
{
final String string = String.valueOf(object);
if (args.has(LOWERCASE_FLAG))
{
return string.toLowerCase(locale);
}
if (args.has(UPPERCASE_FLAG))
{
return string.toUpperCase(locale);
}
return string;
}
示例11: parseFormatter
import org.cubeengine.dirigent.context.Arguments; //导入依赖的package包/类
/**
* Parses the {@link DateFormat} to use from the context arguments.
*
* @param context The context.
* @param args The arguments of the macro.
*
* @return the {@link DateFormat}.
*/
private DateFormat parseFormatter(Context context, Arguments args)
{
final String format = args.get(FORMAT_PARAM_NAME);
final Locale locale = context.get(LOCALE);
if (format != null)
{
return new SimpleDateFormat(format, locale);
}
final int defaultFormatStyle = parseDateFormatStyle(args);
final int dateFormatStyle = parseDateFormatStyle(args.get(DATE_PARAM_NAME), defaultFormatStyle);
final int timeFormatStyle = parseDateFormatStyle(args.get(TIME_PARAM_NAME), defaultFormatStyle);
if (Mode.DATE_TIME.equals(mode))
{
return DateFormat.getDateTimeInstance(dateFormatStyle, timeFormatStyle, locale);
}
else if (Mode.DATE.equals(mode))
{
return DateFormat.getDateInstance(dateFormatStyle, locale);
}
else if (Mode.TIME.equals(mode))
{
return DateFormat.getTimeInstance(timeFormatStyle, locale);
}
return DateFormat.getInstance();
}
示例12: parseNumberToString
import org.cubeengine.dirigent.context.Arguments; //导入依赖的package包/类
/**
* Parses the given number to a string depending on the context.
*
* @param number The number to parse.
* @param context The context to use.
* @param args The arguments of the macro.
*
* @return The number as a string.
*/
protected String parseNumberToString(Number number, Context context, Arguments args)
{
final NumberFormat numberFormat = parseFormatter(context, args);
final Currency currency = context.get(Contexts.CURRENCY);
if (currency != null)
{
numberFormat.setCurrency(currency);
}
return numberFormat.format(number);
}
示例13: format
import org.cubeengine.dirigent.context.Arguments; //导入依赖的package包/类
@Override
protected Component format(final Object input, Context context, Arguments args)
{
final Class<?> inputClass = input.getClass();
final List<Formatter> candidates = new ArrayList<Formatter>();
for (Entry<Class<?>, Formatter> entry : formats.entrySet())
{
Class<?> formatterClass = entry.getKey();
if (inputClass == formatterClass)
{
// exact match will be used directly
return this.formats.get(formatterClass).format(input, context, args);
}
else if (formatterClass.isAssignableFrom(inputClass))
{
candidates.add(entry.getValue());
}
}
if (candidates.isEmpty())
{
return null;
}
Collections.sort(candidates, new Comparator<ReflectedFormatter.Formatter>()
{
@Override
public int compare(ReflectedFormatter.Formatter a, ReflectedFormatter.Formatter b)
{
// sort descending, so the highest priority value will be first.
return b.prio - a.prio;
}
});
return candidates.get(0).format(input, context, args);
}
示例14: applyPostProcessors
import org.cubeengine.dirigent.context.Arguments; //导入依赖的package包/类
/**
* Executes all attached {@link PostProcessor}s to process the specified {@link Component}.
*
* @param in The component to process.
* @param context The compose context.
* @param args The macro arguments.
*
* @return The processed component.
*/
private Component applyPostProcessors(Component in, Context context, Arguments args)
{
Component out = in;
for (final PostProcessor postProcessor : postProcessors)
{
out = postProcessor.process(out, context, args);
}
return out;
}
示例15: checkFormat
import org.cubeengine.dirigent.context.Arguments; //导入依赖的package包/类
private void checkFormat(final String expected, final Number number, final Locale locale)
{
final Component component = currencyFormatter.format(number, createContext(locale), Arguments.NONE);
Assert.assertTrue(component instanceof Text);
Assert.assertEquals(expected, ((Text)component).getText());
}