List of usage examples for org.apache.commons.lang ArrayUtils INDEX_NOT_FOUND
int INDEX_NOT_FOUND
To view the source code for org.apache.commons.lang ArrayUtils INDEX_NOT_FOUND.
Click Source Link
-1
. From source file:com.jaspersoft.studio.property.descriptor.returnvalue.EditableInputReturnValueDialog.java
/** * Initialize the from and to control with the passed container and attach * the modify listeners to them// w w w . ja v a 2s.c o m */ @Override protected void initializeVariables() { if (rvContainer.getToVariable() != null) { int index = ArrayUtils.indexOf(toVariables, rvContainer.getToVariable()); if (index == ArrayUtils.INDEX_NOT_FOUND) index = 0; toVariable.select(index); } else { toVariable.select(0); } if (rvContainer.getFromVariable() != null) { int index = ArrayUtils.indexOf(fromVariables, rvContainer.getFromVariable()); if (index == ArrayUtils.INDEX_NOT_FOUND) index = 0; fromVariableCombo.select(index); } else { fromVariableCombo.select(0); } toVariable.addModifyListener(widgetModified); fromVariableCombo.addModifyListener(widgetModified); }
From source file:it.jnrpe.net.JNRPEProtocolPacket.java
/** * @return The string representation of the buffer. *///from w w w .ja v a2s . c o m protected String getPacketString() { byte[] buffer = getBuffer(); int zeroIndex = ArrayUtils.indexOf(buffer, (byte) 0); if (zeroIndex == ArrayUtils.INDEX_NOT_FOUND) { return new String(buffer, charset); } else { return new String(buffer, 0, zeroIndex, charset); } }
From source file:com.jaspersoft.studio.property.descriptor.returnvalue.InputReturnValueDialog.java
/** * Initialize the from and to control with the passed container and attach * the modify listeners to them/*ww w . j a v a 2 s. com*/ */ protected void initializeVariables() { if (rvContainer.getToVariable() != null) { int index = ArrayUtils.indexOf(toVariables, rvContainer.getToVariable()); if (index == ArrayUtils.INDEX_NOT_FOUND) index = 0; toVariable.select(index); } else { toVariable.select(0); } if (rvContainer.getFromVariable() != null) { fromVariable.setText(rvContainer.getFromVariable()); } toVariable.addModifyListener(widgetModified); fromVariable.addModifyListener(widgetModified); }
From source file:com.aionemu.gameserver.services.toypet.PetFeedCalculator.java
public static PetFeedResult getReward(int fullCount, PetRewards rewardGroup, PetFeedProgress progress, int playerLevel) { if (progress.getHungryLevel() != PetHungryLevel.FULL || rewardGroup.getResults().size() == 0) { return null; }//from w ww .ja va2 s. c o m int pointsIndex = ArrayUtils.indexOf(fullCounts, (short) fullCount); if (pointsIndex == ArrayUtils.INDEX_NOT_FOUND) { return null; } if (progress.isLovedFeeded()) { // for cash feed if (rewardGroup.getResults().size() == 1) { return rewardGroup.getResults().get(0); } List<PetFeedResult> validRewards = new ArrayList<PetFeedResult>(); int maxLevel = 0; for (PetFeedResult result : rewardGroup.getResults()) { int resultLevel = DataManager.ITEM_DATA.getItemTemplate(result.getItem()).getLevel(); if (resultLevel > playerLevel) { continue; } if (resultLevel > maxLevel) { maxLevel = resultLevel; validRewards.clear(); } validRewards.add(result); } if (validRewards.size() == 0) { return null; } if (validRewards.size() == 1) { return validRewards.get(0); } return validRewards.get(Rnd.get(validRewards.size())); } int rewardIndex = 0; int totalRewards = rewardGroup.getResults().size(); for (int row = 1; row < pointValues.length; row++) { int[] points = pointValues[row]; if (points[pointsIndex] <= progress.getTotalPoints()) { rewardIndex = Math.round((float) totalRewards / (pointValues.length - 1) * row) - 1; } } // Fix rounding discrepancy if (rewardIndex < 0) { rewardIndex = 0; } else if (rewardIndex > rewardGroup.getResults().size() - 1) { rewardIndex = rewardGroup.getResults().size() - 1; } return rewardGroup.getResults().get(rewardIndex); }
From source file:application.ReviewDocumentIndexer.java
private void setArgs(String[] args) throws RuntimeException { // Parse and process command line arguments for (String arg : args) { arg = arg.toLowerCase();/*from w w w .ja v a 2 s. c o m*/ } if (args.length == 1 || ArrayUtils.contains(args, "--help")) throw new RuntimeException("Command line syntax error"); if (ArrayUtils.contains(args, "--new")) { min_reviewid = 0; new_index = true; } else if (ArrayUtils.contains(args, "--resume")) { try { restoreState(); min_reviewid = theReviewId.get(); } catch (IOException e) { AppLogger.error.log(Level.SEVERE, "Cannot restore indexer state. Some files are missing or are unreadable."); } } else if (ArrayUtils.contains(args, "--update")) { try { restoreState(); min_reviewid = 0; } catch (IOException e) { AppLogger.error.log(Level.SEVERE, "Cannot restore indexer state. Some files are missing or are unreadable."); } } else if (ArrayUtils.contains(args, "--restore")) { try { restoreIndex(); restoreState(); min_reviewid = theReviewId.get(); } catch (IOException e) { AppLogger.error.log(Level.SEVERE, "Cannot restore index from backup. Some files are missing or are unreadable."); } } else throw new RuntimeException("Command line syntax error"); int pos = -1; try { if ((pos = ArrayUtils.indexOf(args, "--stop-after")) != ArrayUtils.INDEX_NOT_FOUND) { stop_after = min_reviewid + Integer.parseInt(args[pos + 1]); } if ((pos = ArrayUtils.indexOf(args, "--pause-every")) != ArrayUtils.INDEX_NOT_FOUND) { pause_every = Integer.parseInt(args[pos + 1]); } } catch (ArrayIndexOutOfBoundsException e) { throw new RuntimeException("Command line syntax error"); } }
From source file:com.jaspersoft.studio.property.descriptor.returnvalue.InputReturnValueDialog.java
@Override protected Control createDialogArea(Composite parent) { Composite container = new Composite(parent, SWT.NONE); container.setLayout(new GridLayout(2, false)); container.setLayoutData(new GridData(GridData.FILL_BOTH)); createFromVariable(container);// w ww. java2 s.co m createToVariable(container); Label calculationLabel = new Label(container, SWT.NONE); calculationLabel.setText(Messages.RVPropertyPage_calculation_type); calculation = new Combo(container, SWT.READ_ONLY); calculation.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); calculation.setItems(calculationValues); Label incrementLabel = new Label(container, SWT.NONE); incrementLabel.setText(Messages.RVPropertyPage_incrementer_factory_class); Composite incrementContainer = new Composite(container, SWT.NONE); GridLayout incrementContainerLayout = new GridLayout(2, false); incrementContainerLayout.horizontalSpacing = 0; incrementContainerLayout.verticalSpacing = 0; incrementContainerLayout.marginWidth = 0; incrementContainerLayout.marginHeight = 0; incrementContainer.setLayout(incrementContainerLayout); incrementContainer.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); incrementText = new Text(incrementContainer, SWT.BORDER); incrementText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); Button incrementButton = new Button(incrementContainer, SWT.NONE); incrementButton.setText("..."); //$NON-NLS-1$ incrementButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { SelectionDialog dialog; try { dialog = JavaUI.createTypeDialog(getShell(), new ProgressMonitorDialog(getShell()), getIncrementContext(), IJavaElementSearchConstants.CONSIDER_CLASSES_AND_INTERFACES, false); dialog.setTitle(Messages.ClassTypeCellEditor_open_type); dialog.setMessage(Messages.ClassTypeCellEditor_dialog_message); if (dialog.open() == Window.OK) { if (dialog.getResult() != null && dialog.getResult().length > 0) { IType bt = (IType) dialog.getResult()[0]; incrementText.setText(bt.getFullyQualifiedName()); } } } catch (JavaModelException e1) { e1.printStackTrace(); } } }); //INITIALIZE THE WIDGET WITH THE CONTENT OF THE CONTAINER IF IT IS VALID if (rvContainer.getCalculation() != null) { int index = ArrayUtils.indexOf(CalculationEnum.values(), rvContainer.getCalculation()); if (index == ArrayUtils.INDEX_NOT_FOUND) index = 0; calculation.select(index); } if (rvContainer.getIncrementerFactoryClassName() != null) incrementText.setText(rvContainer.getIncrementerFactoryClassName()); //ADD THE MODIFY LISTENER AT THE END TO AVOID THAT IT'S CALLED DURING THE INITIALIZATION initializeVariables(); incrementText.addModifyListener(widgetModified); calculation.addModifyListener(widgetModified); updateContainer(); return container; }
From source file:fr.inria.atlanmod.neoemf.graph.blueprints.datastore.estores.impl.DirectWriteBlueprintsResourceEStoreImpl.java
@Override public int indexOf(InternalEObject object, EStructuralFeature feature, Object value) { if (feature instanceof EAttribute) { return ArrayUtils.indexOf(toArray(object, feature), value); } else if (feature instanceof EReference) { if (value == null) { return ArrayUtils.INDEX_NOT_FOUND; }/*from w w w . ja v a 2s . c om*/ Vertex inVertex = graph.getVertex(object); Vertex outVertex = graph.getVertex((EObject) value); Iterator<Edge> iterator = outVertex.getEdges(Direction.IN, feature.getName()).iterator(); while (iterator.hasNext()) { Edge e = iterator.next(); if (e.getVertex(Direction.OUT).equals(inVertex)) { return e.getProperty(POSITION); } } return ArrayUtils.INDEX_NOT_FOUND; } else { throw new IllegalArgumentException(feature.toString()); } }
From source file:fr.inria.atlanmod.neoemf.graph.blueprints.datastore.estores.impl.DirectWriteBlueprintsResourceEStoreImpl.java
@Override public int lastIndexOf(InternalEObject object, EStructuralFeature feature, Object value) { if (feature instanceof EAttribute) { return ArrayUtils.lastIndexOf(toArray(object, feature), value); } else if (feature instanceof EReference) { if (value == null) { return ArrayUtils.INDEX_NOT_FOUND; }//from w ww .ja v a 2s . c o m Vertex inVertex = graph.getVertex(object); Vertex outVertex = graph.getVertex((EObject) value); Iterator<Edge> iterator = outVertex.getEdges(Direction.IN, feature.getName()).iterator(); Edge lastPositionEdge = null; while (iterator.hasNext()) { Edge e = iterator.next(); if (e.getVertex(Direction.OUT).equals(inVertex)) { if (lastPositionEdge == null || ((int) e.getProperty(POSITION)) > (int) lastPositionEdge.getProperty(POSITION)) { lastPositionEdge = e; } } } return (lastPositionEdge == null ? ArrayUtils.INDEX_NOT_FOUND : (int) lastPositionEdge.getProperty(POSITION)); } else { throw new IllegalArgumentException(feature.toString()); } }
From source file:adalid.core.EntityAtlas.java
@SuppressWarnings("deprecation") void initialiseFields(Class<?> clazz) { track("initialiseFields", _declaringArtifact, clazz.getSimpleName()); Class<?> c;//from w w w .jav a 2 s. c o m int d, r; String name; String key; String pattern = "there are several fields for operation {0}"; String message; Class<?> type; Class<?> decl; Class<?> operationClass; Field operationField; int modifiers; boolean restricted; Object o; int depth = _declaringArtifact.depth(); int round = _declaringArtifact.round(); Class<?>[] classes = new Class<?>[] { Property.class, Key.class, Tab.class, View.class, Instance.class, NamedValue.class, Expression.class, Transition.class, Operation.class, Trigger.class }; Class<?> dac = _declaringArtifact.getClass(); Class<?> top = Entity.class; int i = ArrayUtils.indexOf(classes, clazz); if (i != ArrayUtils.INDEX_NOT_FOUND) { c = classes[i]; for (Field field : XS1.getFields(dac, top)) { field.setAccessible(true); logger.trace(field); name = field.getName(); type = field.getType(); decl = field.getDeclaringClass(); if (!c.isAssignableFrom(type)) { continue; } if (c.equals(Expression.class) && Property.class.isAssignableFrom(type)) { continue; } // TODO: extension handling if (field.isAnnotationPresent(Extension.class) && Entity.class.isAssignableFrom(type)) { // if (!dac.equals(decl) || !dac.isAssignableFrom(type)) { // continue; // } continue; } modifiers = type.getModifiers(); if (NamedValue.class.isAssignableFrom(type) || Expression.class.isAssignableFrom(type)) { restricted = false; } else { restricted = type.isInterface() || Modifier.isAbstract(modifiers); } restricted = restricted || !Modifier.isPublic(modifiers); if (restricted) { continue; } modifiers = field.getModifiers(); restricted = Modifier.isPrivate(modifiers); if (restricted) { continue; } restricted = Modifier.isStatic(modifiers) || Modifier.isFinal(modifiers); if (restricted) { continue; } if (Operation.class.isAssignableFrom(type)) { key = type.getSimpleName(); operationClass = _operationClasses.get(key); if (operationClass != null) { operationField = _operationFields.get(key); if (operationField == null) { _operationFields.put(key, field); } else { message = MessageFormat.format(pattern, operationClass.getName()); logger.warn(message); TLC.getProject().getParser().increaseWarningCount(); } } } String errmsg = "failed to create a new instance of field \"" + field + "\" at " + _declaringArtifact; try { o = field.get(_declaringArtifact); if (o == null) { logger.debug(message(type, name, o, depth, round)); o = XS1.initialiseField(_declaringArtifact, field); if (o == null) { logger.debug(message(type, name, o, depth, round)); // throw new RuntimeException(message(type, name, o, depth, round)); } else { logger.debug(message(type, name, o, depth, round)); field.set(_declaringArtifact, o); } } } catch (IllegalArgumentException | IllegalAccessException ex) { throw new InstantiationRuntimeException(errmsg, ex); } } } }
From source file:adalid.core.Operation.java
void initialiseFields(Class<?> clazz) { Class<?> c;/* w w w . j ava2 s . c o m*/ int d, r; String name; Class<?> type; int modifiers; boolean restricted; Object o; int depth = depth(); int round = round(); Class<?>[] classes = new Class<?>[] { Parameter.class, Expression.class }; Class<?> dac = getClass(); Class<?> top = Operation.class; int i = ArrayUtils.indexOf(classes, clazz); if (i != ArrayUtils.INDEX_NOT_FOUND) { c = classes[i]; for (Field field : XS1.getFields(dac, top)) { field.setAccessible(true); logger.trace(field); name = field.getName(); type = field.getType(); if (!c.isAssignableFrom(type)) { continue; } modifiers = type.getModifiers(); if (type.isInterface() && Expression.class.isAssignableFrom(type)) { restricted = false; } else { restricted = Modifier.isAbstract(modifiers); } restricted = restricted || !Modifier.isPublic(modifiers); if (restricted) { continue; } modifiers = field.getModifiers(); restricted = Modifier.isStatic(modifiers) || Modifier.isFinal(modifiers); if (restricted) { continue; } String errmsg = "failed to create a new instance of field \"" + field + "\" at " + this; try { o = field.get(this); if (o == null) { logger.debug(message(type, name, o, depth, round)); o = XS1.initialiseField(this, field); if (o == null) { logger.debug(message(type, name, o, depth, round)); // throw new RuntimeException(message(type, name, o, depth, round)); } else { logger.debug(message(type, name, o, depth, round)); field.set(this, o); } } } catch (IllegalArgumentException | IllegalAccessException ex) { throw new InstantiationRuntimeException(errmsg, ex); } } } }