/** * Get the field type of a Field instance. * * @param field the field instance we want the type for. * @return the type of the {@code field} in question. */ private static FieldType fieldTypeOf(Field field, Flag flag) { if (field.getType().isAssignableFrom(Long.TYPE) || field.getType().isAssignableFrom(Long.class)) { return FieldType.LONG; } if (field.getType().isAssignableFrom(Boolean.TYPE) || field.getType().isAssignableFrom(Boolean.class)) { return FieldType.BOOLEAN; } if (field.getType().isAssignableFrom(String.class)) { return FieldType.STRING; } if (field.getType().isAssignableFrom(Integer.TYPE) || field.getType().isAssignableFrom(Integer.class)) { return FieldType.INTEGER; } if (flag.options() != NoOption.class && field.getType().isAssignableFrom(flag.options())) { return FieldType.ENUM; } return FieldType.UNKNOWN; }
public void demonstrateFlag() { // #flag final Flag f0 = Flag.create(); final Flag f1 = f0.switchOn(); System.out.println(f1.enabled()); // #flag }
public static boolean isPlotFlagTrue(final Plot plot, final String strFlag) { if (plot.owner == null) { return false; } final Flag flag = getPlotFlagRaw(plot, strFlag); return !(flag == null || !((Boolean) flag.getValue())); }
public static Flag construct(String name, Boolean value) { Flag result = new Flag(); result.type = Boolean.class; result.name = name; result.defaultValue = value; return result; }
public void addFlag(Flag flag) { if (this.numFlagsInaccurate == null) { this.numFlagsInaccurate = 0; } if (this.numFlagsInappropriate == null) { this.numFlagsInappropriate = 0; } if (this.numFlagsSpam == null) { this.numFlagsSpam = 0; } if (this.numFlagsTotal == null) { this.numFlagsTotal = 0; } switch (flag.getType()) { case Flag.INACCURATE: this.numFlagsInaccurate++; break; case Flag.INAPPROPRIATE: this.numFlagsInappropriate++; break; case Flag.SPAM: this.numFlagsSpam++; break; } this.numFlagsTotal++; this.flags.add(flag.getKey()); }
/** * Displays a button on each attached monitor, and returns the * * <p>GraphicsDevice object associated with that monitor. * * @param scrns a list of GraphicsDevices on which to display buttons * @return the GraphicsDevice selected. */ private GraphicsDevice pickScreen(GraphicsDevice scrns[]) { flag.clear(); int count = 0; PickMe pickers[] = new PickMe[scrns.length]; for (int i = 0; i < scrns.length; i++) { if (scrns[i].isFullScreenSupported()) { count++; } pickers[i] = new PickMe(scrns[i]); } flag.waitForFlag(); for (int i = 0; i < pickers.length; i++) { if (pickers[i] != null) { pickers[i].dispose(); } } return pickedDevice; }
@Override public void writeTo(StreamOutput out) throws IOException { super.writeTo(out); if (out.getVersion().before(Version.V_1_4_0)) { // term vector used to read & write the index twice, here and in the parent class out.writeString(index); } out.writeString(type); out.writeString(id); if (out.getVersion().onOrAfter(Version.V_1_4_0)) { out.writeBoolean(doc != null); if (doc != null) { out.writeBytesReference(doc); } } out.writeOptionalString(routing); out.writeOptionalString(preference); long longFlags = 0; for (Flag flag : flagsEnum) { longFlags |= (1 << flag.ordinal()); } out.writeVLong(longFlags); if (selectedFields != null) { out.writeVInt(selectedFields.size()); for (String selectedField : selectedFields) { out.writeString(selectedField); } } else { out.writeVInt(0); } }
@Override public void readFrom(StreamInput in) throws IOException { super.readFrom(in); if (in.getVersion().before(Version.V_1_4_0)) { // term vector used to read & write the index twice, here and in the parent class in.readString(); } type = in.readString(); id = in.readString(); if (in.getVersion().onOrAfter(Version.V_1_4_0)) { if (in.readBoolean()) { doc = in.readBytesReference(); } } routing = in.readOptionalString(); preference = in.readOptionalString(); long flags = in.readVLong(); flagsEnum.clear(); for (Flag flag : Flag.values()) { if ((flags & (1 << flag.ordinal())) != 0) { flagsEnum.add(flag); } } int numSelectedFields = in.readVInt(); if (numSelectedFields > 0) { selectedFields = new HashSet<>(); for (int i = 0; i < numSelectedFields; i++) { selectedFields.add(in.readString()); } } }
/** * Private helper method to add an option. Will check that an option with the same name has not * previously been added. * * @param type * @param flag * @param field * @param option * @param c * @throws IllegalArgumentException */ private void addOption(FieldType type, Flag flag, Field field, OptionSpec<?> option, Class<?> c) throws IllegalArgumentException { if (options.containsKey(flag.name())) { throw new IllegalArgumentException( "Flag named " + flag.name() + " is defined more than once."); } options.put(flag.name(), new OptionHolder(type, flag, field, option, c)); }
protected static final Flag andTwoFlags(Flag a, Flag b) { if (a.getClass() != b.getClass()) { throw new IllegalArgumentException( "Both arguments need to be an instances of the same concrete Flags class"); } return Plumbing.flagFor(a.getClass(), a.ordinal & b.ordinal); }
/** * Get the legacy flag. * * @param flagString * @return null if not found */ public static StateFlag getLegacyFlag(String flagString) { for (Flag<?> flag : flagsList) { if (flag instanceof StateFlag && flagString.equals(String.valueOf(flag.getLegacyCode()))) { return (StateFlag) flag; } } return null; }
public static Set<Flag> removeFlag(final Set<Flag> flags, final String r) { final HashSet<Flag> newflags = new HashSet<>(); for (final Flag flag : flags) { if (!flag.getKey().equalsIgnoreCase(r)) { newflags.add(flag); } } return newflags; }
public static Flag[] removeFlag(final Flag[] flags, final String r) { final Flag[] f = new Flag[flags.length - 1]; int index = 0; for (final Flag flag : flags) { if (!flag.getKey().equals(r)) { f[index++] = flag; } } return f; }
public static boolean isBooleanFlag( final Plot plot, final String key, final boolean defaultValue) { final Flag flag = FlagManager.getPlotFlagRaw(plot, key); if (flag == null) { return defaultValue; } final Object value = flag.getValue(); if (value instanceof Boolean) { return (boolean) value; } return defaultValue; }
@Test public void foreach_A$VoidFunction1() throws Exception { final Flag flag = new Flag(); int value = 1; Some<Integer> target = new Some<Integer>(value); target.foreach( new VoidF1<Integer>() { public void apply(Integer arg) { flag.toggle(); } }); assertTrue(flag.getValue()); }
public static void setClusterFlags(final PlotCluster cluster, final Set<Flag> flags) { if (flags != null && !flags.isEmpty()) { cluster.settings.flags.clear(); for (final Flag flag : flags) { cluster.settings.flags.put(flag.getKey(), flag); } } else if (cluster.settings.flags.isEmpty()) { return; } else { cluster.settings.flags.clear(); } DBFunc.setFlags(cluster, cluster.settings.flags.values()); }
public static String toString(Collection<Flag> flags) { final StringBuilder flag_string = new StringBuilder(); int i = 0; for (final Flag flag : flags) { if (i != 0) { flag_string.append(","); } flag_string.append( flag.getKey() + ":" + flag.getValueString().replaceAll(":", "\u00AF").replaceAll(",", "\u00B4")); i++; } return flag_string.toString(); }
public GeneOrthologyEntry(String line) { String[] a = line.split("\\s"); geneName = a[0]; s288cCoords = parseCoordsString(a[1]); sigmaCoords = parseCoordsString(a[2]); try { identity = Double.parseDouble(a[3]); } catch (NumberFormatException e) { identity = null; } flags = new HashSet<Flag>(); orfCoords = null; if (a.length > 4) { String[] fa = a[4].split(","); for (int i = 0; i < fa.length; i++) { try { if (fa[i].length() > 0) { flags.add(Flag.valueOf(fa[i])); } else { flags.add(Flag.UNKNOWN); } } catch (IllegalArgumentException e) { System.err.println(String.format("Unknown FLAG: \"%s\"", fa[i])); flags.add(Flag.UNKNOWN); } } if (a.length > 5) { orfCoords = parseCoordsString(a[5]); } } }
/** * Sets the flags for the tap stream. These flags decide what kind of tap stream will be received. * * @param f The flags to use for this tap stream. */ public void setFlags(Flag f) { if (flags.length != FLAGS_FIELD_LENGTH) flags = new byte[FLAGS_FIELD_LENGTH]; if (!f.hasFlag(getFlags())) { Util.valueToField(flags, 0, FLAGS_FIELD_LENGTH, (long) f.flag); encode(); } }
/** * Utility function to determine whether a Flags instance has the bit embodied by <code>setting * </code> set. An example of this in action is: * * <pre> * WindowState s; * ... * * if (s.contains(WindowState.STICKY)) { * // get a cloth to clean up the mess * } * </pre> * * You can only use this on instances of the same class! */ public final boolean contains(Flag setting) { if (this.getClass() != setting.getClass()) { throw new IllegalArgumentException("Argument needs to be an instance of " + this.getClass()); } return (this.ordinal & setting.ordinal) != 0; }
private SafeHtml createArgumentLabel(ArgumentEditor argEditor) { SafeHtmlBuilder labelText = new SafeHtmlBuilder(); Boolean isRequired = argEditor.requiredEditor().getValue(); if ((isRequired != null) && isRequired) { // If the field is required, it needs to be marked as such. labelText.append(appearance.getRequiredFieldLabel()); } // JDS Remove the trailing colon. The FieldLabels will apply it automatically. String label = Strings.nullToEmpty(argEditor.labelEditor().getValue()); SafeHtml safeHtmlLabel = SafeHtmlUtils.fromString(label.replaceFirst(":$", "")); ArgumentType argumentType = argEditor.typeEditor().getValue(); if (Info.equals(argumentType)) { labelText.append(appearance.sanitizeHtml(label)); } else { if (Flag.equals(argumentType)) { labelText.append(new SafeHtmlBuilder().appendHtmlConstant(" ").toSafeHtml()); } String id = argEditor.idEditor().getValue(); String description = argEditor.descriptionEditor().getValue(); if (Strings.isNullOrEmpty(description) || EMPTY_GROUP_ARG_ID.equals(id)) { labelText.append(safeHtmlLabel); } else { labelText.append(appearance.getContextualHelpLabel(safeHtmlLabel, description)); } } return labelText.toSafeHtml(); }
public Deque<Action> processGameData(String gameData) { Deque<Action> actions = rw.parseAndUpdatePlayerCharacter(gameData); log.fine(actions.toString()); Flag flag = null; for (Entry<Flag, Boolean> entry : player.getFlags().entrySet()) { if (entry.getKey() != Flag.LOGGEDIN) { if (entry.getValue()) { flag = entry.getKey(); log.log(Level.INFO, "detected\t{0}", flag); player.setFlag(flag, false); actions.addAll(flag.getActionsForState()); } } } return actions; }
public static void setPlotFlags(final Plot origin, final Set<Flag> flags) { for (Plot plot : origin.getConnectedPlots()) { if (flags != null && !flags.isEmpty()) { plot.getFlags().clear(); for (final Flag flag : flags) { plot.getFlags().put(flag.getKey(), flag); } } else if (plot.getFlags().isEmpty()) { return; } else { plot.getFlags().clear(); } plot.reEnter(); DBFunc.setFlags(plot, plot.getFlags().values()); } }
public static boolean addPlotFlagAbs(final Plot plot, final Flag flag) { final boolean result = EventUtil.manager.callFlagAdd(flag, plot); if (!result) { return false; } plot.getFlags().put(flag.getKey(), flag); return true; }
public static HashMap<String, Flag> parseFlags(final List<String> flagstrings) { final HashMap<String, Flag> map = new HashMap<>(); for (final String key : flagstrings) { final String[] split; if (key.contains(";")) { split = key.split(";"); } else { split = key.split(":"); } Flag flag; if (split.length == 1) { flag = new Flag(getFlag(split[0], true), ""); } else { flag = new Flag(getFlag(split[0], true), split[1]); } map.put(flag.getKey(), flag); } return map; }
/** * Add a flag to a plot * * @param origin * @param flag */ public static boolean addPlotFlag(final Plot origin, final Flag flag) { final boolean result = EventUtil.manager.callFlagAdd(flag, origin); if (!result) { return false; } for (Plot plot : origin.getConnectedPlots()) { plot.getFlags().put(flag.getKey(), flag); plot.reEnter(); DBFunc.setFlags(plot, plot.getFlags().values()); } return true; }
/** Converts the header's flags into a String */ public String printFlags() { StringBuilder sb = new StringBuilder(); for (int i = 0; i < 16; i++) { if (validFlag(i) && getFlag(i)) { sb.append(Flag.valueOf(i).getName()); // sb.append(Flags.string(i)); sb.append(" "); } } return sb.toString(); }
@Override public ListenableFuture<Set<Flag>> addOrRemoveFlags( Folder folder, int imapUid, Set<Flag> flags, boolean add) { Preconditions.checkState( mailClientHandler.isLoggedIn(), "Can't execute command because client is not logged in"); Preconditions.checkState( !mailClientHandler.idleRequested.get(), "Can't execute command while idling (are you watching a folder?)"); checkCurrentFolder(folder); SettableFuture<Set<Flag>> valueFuture = SettableFuture.create(); String args = imapUid + " " + (add ? "+" : "-") + Flag.toImap(flags); send(Command.STORE_FLAGS, args, valueFuture); return valueFuture; }
public boolean convert(World world, int x, int y, int z, Flag flag) { if (world == null) return false; int layerPos = 0; for (Layer layer : layers) { int rowPos = 0; for (Row row : layer.rows) { for (int depth = 0; depth < row.sections.length(); depth++) { char type = row.sections.charAt(depth); if (type == '*') continue; if (type == ' ') { if (flag.isIgnoring()) world.setBlockToAir(new BlockPos(x + rowPos, y + layerPos, z + depth)); continue; } BlockState blockState = comparisonMap.get(Character.valueOf(type)); if (blockState == null) return false; switch (flag) { case AIR: if (world.isAirBlock(new BlockPos(x + rowPos, y + layerPos, z + depth))) world.setBlockState( new BlockPos(x + rowPos, y + layerPos, z + depth), BlockStates.get(blockState.type).getDefaultState()); break; case IGNORE: world.setBlockState( new BlockPos(x + rowPos, y + layerPos, z + depth), BlockStates.get(blockState.type).getDefaultState()); break; default: break; } } rowPos++; } layerPos++; } return true; }
private Flags loadOpts(Object o, boolean instanced) { final Field[] declaredFields; Class<?> c = null; if (instanced) { declaredFields = o.getClass().getDeclaredFields(); } else { c = ((Class<?>) o); declaredFields = c.getDeclaredFields(); } for (Field field : declaredFields) { Flag flag = field.getAnnotation(Flag.class); // Check if we found a flag annotation for this field. if (null == flag) { continue; } // Flag fields must be static if you are initializing the flags through a Class instance. if (!instanced && !Modifier.isStatic(field.getModifiers())) { throw new IllegalArgumentException( "Field " + field.toGenericString() + " is not static. Flag fields " + "must be static when initializing through a Class instance."); } String name = flag.name(); String description = flag.description(); // Determine the type of field FieldType type = fieldTypeOf(field, flag); switch (type) { case INTEGER: OptionSpec<Integer> intOption; if (flag.required()) { intOption = optionParser.accepts(name, description).withRequiredArg().ofType(Integer.class); } else { intOption = optionParser.accepts(name, description).withOptionalArg().ofType(Integer.class); } if (instanced) { addInstancedOption(type, flag, field, intOption, o); } else { addOption(type, flag, field, intOption, c); } break; case STRING: OptionSpec<String> stringOption; if (flag.required()) { stringOption = optionParser.accepts(name, description).withRequiredArg().ofType(String.class); } else { stringOption = optionParser.accepts(name, description).withOptionalArg().ofType(String.class); } if (instanced) { addInstancedOption(type, flag, field, stringOption, o); } else { addOption(type, flag, field, stringOption, c); } break; case BOOLEAN: OptionSpec<Boolean> booleanOption; if (flag.required()) { booleanOption = optionParser.accepts(name, description).withOptionalArg().ofType(Boolean.class); } else { booleanOption = optionParser.accepts(name, description).withOptionalArg().ofType(Boolean.class); } if (instanced) { addInstancedOption(type, flag, field, booleanOption, o); } else { addOption(type, flag, field, booleanOption, c); } break; case LONG: OptionSpec<Long> longOption; if (flag.required()) { longOption = optionParser.accepts(name, description).withRequiredArg().ofType(Long.class); } else { longOption = optionParser.accepts(name, description).withOptionalArg().ofType(Long.class); } if (instanced) { addInstancedOption(type, flag, field, longOption, o); } else { addOption(type, flag, field, longOption, c); } break; case ENUM: Class<? extends Enum<?>> enumClass = flag.options(); Object[] enumConstants = enumClass.getEnumConstants(); if (enumConstants == null) { throw new IllegalArgumentException( "Field " + field.toGenericString() + " is not an enum type."); } for (Object object : enumConstants) { addEnumOption(enumClass, object.toString()); } OptionSpec<?> enumOption; if (flag.required()) { enumOption = optionParser.accepts(name, description).withRequiredArg().ofType(enumClass); } else { enumOption = optionParser.accepts(name, description).withOptionalArg().ofType(enumClass); } if (instanced) { addInstancedOption(type, flag, field, enumOption, o); } else { addOption(type, flag, field, enumOption, c); } break; case UNKNOWN: default: throw new IllegalArgumentException( "Field " + field.toGenericString() + " is not of a supported type."); } } return this; }