Java Code Examples for java.util.LinkedList#peek()

The following examples show how to use java.util.LinkedList#peek() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Paragraph.java    From ofdrw with Apache License 2.0 6 votes vote down vote up
/**
 * 处理占位符
 *
 * @param seq 段落中的span队列
 */
private void processPlaceholder(LinkedList<Span> seq) {
    if (seq == null || seq.isEmpty()) {
        return;
    }
    Span firstSpan = seq.peek();

    if (firstSpan instanceof PlaceholderSpan) {
        // 已经存在段落缩进并且设置的段落缩进为0,那么删除该占位符
        if (firstLineIndent == null || firstLineIndent == 0) {
            seq.pop();
        } else {
            // 重设占位符的宽度
            ((PlaceholderSpan) firstSpan).setHoldChars(firstLineIndent);
        }
        return;
    }
    // 不需要加入占位符
    if (firstLineIndent == null || firstLineIndent == 0) {
        return;
    }
    // 如果第一个不是占位符,并且占位符数目大于0 那么创建新的占位符,并且加入渲染队列
    seq.push(new PlaceholderSpan(firstLineIndent, firstSpan.getFontSize()));

}
 
Example 2
Source File: DefaultExecutableFactory.java    From neoscada with Eclipse Public License 1.0 6 votes vote down vote up
private Method gatherMethods ( final Class<?> clazz, final String methodName )
{
    final LinkedList<Method> methods = new LinkedList<> ();
    for ( final Method m : clazz.getMethods () )
    {
        if ( m.getName ().equals ( methodName ) )
        {
            methods.add ( m );
        }
    }
    if ( methods.size () == 1 )
    {
        return methods.peek ();
    }
    else if ( methods.isEmpty () )
    {
        throw new IllegalStateException ( String.format ( "Method '%s' not found on class '%s'", methodName, clazz.getName () ) );
    }
    else
    {
        throw new IllegalStateException ( String.format ( "Method '%s' of class '%s' is polymorphic. This is now allowed for the recipe target classes.", methodName, clazz.getName () ) );
    }
}
 
Example 3
Source File: FirstPublicNode.java    From coding-interviews with MIT License 6 votes vote down vote up
/**
 * 方法1:两个辅助栈,从尾到头,找到最后一个相同的结点
 */
public ListNode findFirstCommonNodeStack(ListNode pHead1, ListNode pHead2) {
    ListNode cur1 = pHead1;
    ListNode cur2 = pHead2;
    LinkedList<ListNode> stack1 = new LinkedList<>();
    LinkedList<ListNode> stack2 = new LinkedList<>();
    // 分别存入两个栈中
    while (cur1 != null) {
        stack1.push(cur1);
        cur1 = cur1.next;
    }
    while (cur2 != null) {
        stack2.push(cur2);
        cur2 = cur2.next;
    }
    // 用于记录逆序的上一个公共结点
    ListNode publicNode = null;
    while (!stack1.isEmpty() && !stack2.isEmpty()) {
        if (stack1.peek() == stack2.pop()) publicNode = stack1.pop();
            // 当前比较的不相同时,返回逆序的最后一个公共结点(也就是正序的第一个公共结点)
        else return publicNode;
    }
    return publicNode;
}
 
Example 4
Source File: StackPopOrder.java    From coding-interviews with MIT License 6 votes vote down vote up
public boolean IsPopOrder(int [] pushA,int [] popA) {
    if (pushA == null || popA == null || pushA.length == 0 || popA.length == 0) {
        return false;
    }
    // 辅助栈
    LinkedList<Integer> stackAux = new LinkedList<>();
    int popIndex = 0;
    for (int i = 0;i < pushA.length;i++) {
        // 按照入栈序列依次压入辅助栈中
        stackAux.push(pushA[i]);
        // 每入栈一次和出栈序列比较,如果栈顶和当前出栈元素相同,则弹出同时当前弹出元素指针前移;
        // 如果下一个栈顶元素还和当前弹出元素相同,继续弹出
        while (!stackAux.isEmpty() && stackAux.peek() == popA[popIndex]) {
            stackAux.pop();
            popIndex++;
        }
    }
    // 如果出栈顺序正确,模拟一次进出栈后,辅助栈应该为空。不为空说明序列不正确
    return stackAux.isEmpty();
}
 
Example 5
Source File: BinaryTreeTraversal.java    From algorithm-primer with MIT License 6 votes vote down vote up
/**
 * 非递归方式后续遍历二叉树
 * 数据结构:栈
 * 思路:
 *      要保证根结点在左孩子和右孩子之后才能访问,因此对于任一结点node,先将其入栈。
 *      如果node不存在左孩子和右孩子,则可以直接访问它;
 *      或者node存在左孩子或者右孩子,但是其左孩子和右孩子都已经被访问过,则同样可以直接访问该结点。
 *      若非上述两种情况,则将node的右孩子和左孩子依次入栈,这样就保证了每次取栈顶元素时,左孩子在右孩子前面被访问,
 *      左孩子和右孩子都在根结点前面被访问。
 * @param root 二叉树的根结点
 */
public void iterativePostorder(Node root){
    if (root == null) return;
    Node currNode = null;
    Node pre = null;

    LinkedList<Node> stack = new LinkedList<>();
    stack.push(root);
    while (!stack.isEmpty()){
        currNode = stack.peek();
        if ((currNode.left == null && currNode.right == null) ||
                (pre != null && (pre == currNode.left || pre== currNode.right))){
            visit(currNode);
            stack.pop();
            pre = currNode;
        }
        else {
            if (currNode.right != null) stack.push(currNode.right);
            if (currNode.left != null) stack.push(currNode.left);
        }
    }
}
 
Example 6
Source File: DDSectionNodeView.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void setChildren(LinkedList<SectionNode> children) {
    if(children.peek() != null) {
        SectionNode firstNode = children.removeFirst();
        setRootNode(firstNode);

        if(children.peek() != null) {
            SectionNode [] remainingNodes = children.toArray(new SectionNode[0]);
            
            Node rootNode = getRoot();
            rootNode.getChildren().add(remainingNodes);
            for(int i = 0; i < remainingNodes.length; i++) {
                addSection(remainingNodes[i].getSectionNodePanel());
            }
        }
    }
}
 
Example 7
Source File: DashManifest.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
@Override
public final DashManifest copy(List<StreamKey> streamKeys) {
  LinkedList<StreamKey> keys = new LinkedList<>(streamKeys);
  Collections.sort(keys);
  keys.add(new StreamKey(-1, -1, -1)); // Add a stopper key to the end

  ArrayList<Period> copyPeriods = new ArrayList<>();
  long shiftMs = 0;
  for (int periodIndex = 0; periodIndex < getPeriodCount(); periodIndex++) {
    if (keys.peek().periodIndex != periodIndex) {
      // No representations selected in this period.
      long periodDurationMs = getPeriodDurationMs(periodIndex);
      if (periodDurationMs != C.TIME_UNSET) {
        shiftMs += periodDurationMs;
      }
    } else {
      Period period = getPeriod(periodIndex);
      ArrayList<AdaptationSet> copyAdaptationSets =
          copyAdaptationSets(period.adaptationSets, keys);
      Period copiedPeriod = new Period(period.id, period.startMs - shiftMs, copyAdaptationSets,
          period.eventStreams);
      copyPeriods.add(copiedPeriod);
    }
  }
  long newDuration = durationMs != C.TIME_UNSET ? durationMs - shiftMs : C.TIME_UNSET;
  return new DashManifest(
      availabilityStartTimeMs,
      newDuration,
      minBufferTimeMs,
      dynamic,
      minUpdatePeriodMs,
      timeShiftBufferDepthMs,
      suggestedPresentationDelayMs,
      publishTimeMs,
      programInformation,
      utcTiming,
      location,
      copyPeriods);
}
 
Example 8
Source File: CommandInjection.java    From Android_Code_Arbiter with GNU Lesser General Public License v3.0 5 votes vote down vote up
private String transferThroughList(String in, int index) {
    LinkedList<String> list = new LinkedList<String>();
    list.add(System.getenv("")); // taints the list
    list.clear(); // makes the list safe again
    list.add(1, "xx");
    list.addFirst(in); // can taint the list
    list.addLast("yy");
    list.push(in);
    return list.element() + list.get(index) + list.getFirst() + list.getLast()
            + list.peek() + list.peekFirst() + list.peekLast() + list.poll()
            + list.pollFirst() + list.pollLast() + list.pop() + list.remove()
            + list.remove(index) + list.removeFirst() + list.removeLast()
            + list.set(index, "safe") + list.toString();
}
 
Example 9
Source File: GroovyDbSwitcher.java    From nh-micro with Apache License 2.0 5 votes vote down vote up
public static String peekCurrentDataSource(String oldDbName) {  
	Map map=contextHolderMap.get();
	if(map==null){
		return null;
	}
	LinkedList list=(LinkedList) map.get(oldDbName);
	if(list!=null && list.size()>0){
		return (String) list.peek();
	}
    return null; 
}
 
Example 10
Source File: DashManifest.java    From K-Sonic with MIT License 5 votes vote down vote up
/**
 * Creates a copy of this manifest which includes only the representations identified by the given
 * keys.
 *
 * @param representationKeys List of keys for the representations to be included in the copy.
 * @return A copy of this manifest with the selected representations.
 * @throws IndexOutOfBoundsException If a key has an invalid index.
 */
public final DashManifest copy(List<RepresentationKey> representationKeys) {
  LinkedList<RepresentationKey> keys = new LinkedList<>(representationKeys);
  Collections.sort(keys);
  keys.add(new RepresentationKey(-1, -1, -1)); // Add a stopper key to the end

  ArrayList<Period> copyPeriods = new ArrayList<>();
  long shiftMs = 0;
  for (int periodIndex = 0; periodIndex < getPeriodCount(); periodIndex++) {
    if (keys.peek().periodIndex != periodIndex) {
      // No representations selected in this period.
      long periodDurationMs = getPeriodDurationMs(periodIndex);
      if (periodDurationMs != C.TIME_UNSET) {
        shiftMs += periodDurationMs;
      }
    } else {
      Period period = getPeriod(periodIndex);
      ArrayList<AdaptationSet> copyAdaptationSets =
          copyAdaptationSets(period.adaptationSets, keys);
      copyPeriods.add(new Period(period.id, period.startMs - shiftMs, copyAdaptationSets));
    }
  }
  long newDuration = duration != C.TIME_UNSET ? duration - shiftMs : C.TIME_UNSET;
  return new DashManifest(availabilityStartTime, newDuration, minBufferTime, dynamic,
      minUpdatePeriod, timeShiftBufferDepth, suggestedPresentationDelay, utcTiming, location,
      copyPeriods);
}
 
Example 11
Source File: RegenerationTracker.java    From packagedrone with Eclipse Public License 1.0 5 votes vote down vote up
public void mark ( final String artifactId )
{
    logger.debug ( "Mark '{}' for regeneration", artifactId );

    final LinkedList<Set<String>> state = this.states.get ();
    final Set<String> current = state.peek ();
    if ( current == null )
    {
        throw new IllegalStateException ( "No regeneration context" );
    }
    current.add ( artifactId );
}
 
Example 12
Source File: DashManifest.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
public final DashManifest copy(List<StreamKey> streamKeys) {
  LinkedList<StreamKey> keys = new LinkedList<>(streamKeys);
  Collections.sort(keys);
  keys.add(new StreamKey(-1, -1, -1)); // Add a stopper key to the end

  ArrayList<Period> copyPeriods = new ArrayList<>();
  long shiftMs = 0;
  for (int periodIndex = 0; periodIndex < getPeriodCount(); periodIndex++) {
    if (keys.peek().periodIndex != periodIndex) {
      // No representations selected in this period.
      long periodDurationMs = getPeriodDurationMs(periodIndex);
      if (periodDurationMs != C.TIME_UNSET) {
        shiftMs += periodDurationMs;
      }
    } else {
      Period period = getPeriod(periodIndex);
      ArrayList<AdaptationSet> copyAdaptationSets =
          copyAdaptationSets(period.adaptationSets, keys);
      Period copiedPeriod = new Period(period.id, period.startMs - shiftMs, copyAdaptationSets,
          period.eventStreams);
      copyPeriods.add(copiedPeriod);
    }
  }
  long newDuration = durationMs != C.TIME_UNSET ? durationMs - shiftMs : C.TIME_UNSET;
  return new DashManifest(availabilityStartTimeMs, newDuration, minBufferTimeMs, dynamic,
      minUpdatePeriodMs, timeShiftBufferDepthMs, suggestedPresentationDelayMs, publishTimeMs,
      utcTiming, location, copyPeriods);
}
 
Example 13
Source File: DashManifest.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
@Override
public final DashManifest copy(List<StreamKey> streamKeys) {
  LinkedList<StreamKey> keys = new LinkedList<>(streamKeys);
  Collections.sort(keys);
  keys.add(new StreamKey(-1, -1, -1)); // Add a stopper key to the end

  ArrayList<Period> copyPeriods = new ArrayList<>();
  long shiftMs = 0;
  for (int periodIndex = 0; periodIndex < getPeriodCount(); periodIndex++) {
    if (keys.peek().periodIndex != periodIndex) {
      // No representations selected in this period.
      long periodDurationMs = getPeriodDurationMs(periodIndex);
      if (periodDurationMs != C.TIME_UNSET) {
        shiftMs += periodDurationMs;
      }
    } else {
      Period period = getPeriod(periodIndex);
      ArrayList<AdaptationSet> copyAdaptationSets =
          copyAdaptationSets(period.adaptationSets, keys);
      Period copiedPeriod = new Period(period.id, period.startMs - shiftMs, copyAdaptationSets,
          period.eventStreams);
      copyPeriods.add(copiedPeriod);
    }
  }
  long newDuration = durationMs != C.TIME_UNSET ? durationMs - shiftMs : C.TIME_UNSET;
  return new DashManifest(
      availabilityStartTimeMs,
      newDuration,
      minBufferTimeMs,
      dynamic,
      minUpdatePeriodMs,
      timeShiftBufferDepthMs,
      suggestedPresentationDelayMs,
      publishTimeMs,
      programInformation,
      utcTiming,
      location,
      copyPeriods);
}
 
Example 14
Source File: Solution1.java    From code with Apache License 2.0 5 votes vote down vote up
/**
 * 题目地址:https://leetcode-cn.com/problems/bao-han-minhan-shu-de-zhan-lcof/
 * -------------------------------------------------------------------
 * 思考:
 * -------------------------------------------------------------------
 * 思路:
 * -------------------------------------------------------------------
 * 时间复杂度:
 * 空间复杂度:
 */
public boolean validateStackSequences(int[] pushed, int[] popped) {
    LinkedList<Integer> stack = new LinkedList<>();

    int index = 0;
    for (int item : pushed) {
        stack.push(item);
        while (index < popped.length && !stack.isEmpty() && stack.peek() == popped[index]) {
            stack.pop();
            index++;
        }
    }

    return index == popped.length;
}
 
Example 15
Source File: Solution1.java    From code with Apache License 2.0 5 votes vote down vote up
/**
 * 题目地址:https://leetcode-cn.com/problems/validate-stack-sequences/
 * -------------------------------------------------------------------
 * 思考:
 * -------------------------------------------------------------------
 * 思路:
 * -------------------------------------------------------------------
 * 时间复杂度:
 * 空间复杂度:
 */
public boolean validateStackSequences(int[] pushed, int[] popped) {
    LinkedList<Integer> stack = new LinkedList<>();

    int index = 0;
    for (int item : pushed) {
        stack.push(item);
        while (index < popped.length && !stack.isEmpty() && stack.peek() == popped[index]) {
            stack.pop();
            index++;
        }
    }

    return index == popped.length;
}
 
Example 16
Source File: FloatingToolbar.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
public List<MenuItem> layoutMainPanelItems(List<MenuItem> menuItems, final int toolbarWidth) {
    int availableWidth = toolbarWidth;
    final LinkedList<MenuItem> remainingMenuItems = new LinkedList<>(menuItems);
    /*final LinkedList<MenuItem> overflowMenuItems = new LinkedList<>();
    for (MenuItem menuItem : menuItems) {
        if (menuItem.requiresOverflow()) {
            overflowMenuItems.add(menuItem); TODO
        } else {
            remainingMenuItems.add(menuItem);
        }
    }
    remainingMenuItems.addAll(overflowMenuItems);*/
    mMainPanel.removeAllViews();
    mMainPanel.setPaddingRelative(0, 0, 0, 0);
    boolean isFirstItem = true;
    while (!remainingMenuItems.isEmpty()) {
        final MenuItem menuItem = remainingMenuItems.peek();
        /*if (!isFirstItem && menuItem.requiresOverflow()) {
            break;
        }*/
        final View menuItemButton = createMenuItemButton(mContext, menuItem, mIconTextSpacing);
        if (menuItemButton instanceof LinearLayout) {
            ((LinearLayout) menuItemButton).setGravity(Gravity.CENTER);
        }
        if (isFirstItem) {
            menuItemButton.setPaddingRelative((int) (1.5 * menuItemButton.getPaddingStart()), menuItemButton.getPaddingTop(), menuItemButton.getPaddingEnd(), menuItemButton.getPaddingBottom());
        }
        boolean isLastItem = remainingMenuItems.size() == 1;
        if (isLastItem) {
            menuItemButton.setPaddingRelative(menuItemButton.getPaddingStart(), menuItemButton.getPaddingTop(), (int) (1.5 * menuItemButton.getPaddingEnd()), menuItemButton.getPaddingBottom());
        }
        menuItemButton.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED);
        final int menuItemButtonWidth = Math.min(menuItemButton.getMeasuredWidth(), toolbarWidth);
        final boolean canFitWithOverflow = menuItemButtonWidth <= availableWidth - mOverflowButtonSize.getWidth();
        final boolean canFitNoOverflow = isLastItem && menuItemButtonWidth <= availableWidth;
        if (canFitWithOverflow || canFitNoOverflow) {
            setButtonTagAndClickListener(menuItemButton, menuItem);
            //menuItemButton.setTooltipText(menuItem.getTooltipText()); TODO
            mMainPanel.addView(menuItemButton);
            final ViewGroup.LayoutParams params = menuItemButton.getLayoutParams();
            params.width = menuItemButtonWidth;
            menuItemButton.setLayoutParams(params);
            availableWidth -= menuItemButtonWidth;
            remainingMenuItems.pop();
        } else {
            break;
        }
        isFirstItem = false;
    }
    if (!remainingMenuItems.isEmpty()) {
        mMainPanel.setPaddingRelative(0, 0, mOverflowButtonSize.getWidth(), 0);
    }
    mMainPanelSize = measure(mMainPanel);
    return remainingMenuItems;
}
 
Example 17
Source File: JPAMDefaultTableGenerator.java    From jeddict with Apache License 2.0 4 votes vote down vote up
/**
     *
     * @param baseDescriptor
     * @param intrinsicEntity defines the Entity Object that contains embedded
     * Object where Entity object will be intrinsicEntity and Embeddable object
     * will be descriptorManagedClass
     * @param intrinsicAttribute
     */
    protected void postInitTableSchema(ClassDescriptor baseDescriptor, LinkedList<Entity> intrinsicEntity, LinkedList<Attribute> intrinsicAttribute) {

        DBRelationalDescriptor descriptor = (DBRelationalDescriptor) baseDescriptor;
        ManagedClass descriptorManagedClass = null;

        if (intrinsicEntity == null) {
            if (descriptor.getAccessor() instanceof EntitySpecAccessor) {
                intrinsicEntity = new LinkedList<>();
                intrinsicAttribute = new LinkedList<>();
                intrinsicEntity.offer(((EntitySpecAccessor) descriptor.getAccessor()).getEntity());
                descriptorManagedClass = intrinsicEntity.peek();
            } else {
                throw new IllegalStateException(descriptor.getAccessor() + " not supported");
            }
        } else if (descriptor.getAccessor() instanceof EmbeddableSpecAccessor) {
            descriptorManagedClass = ((EmbeddableSpecAccessor) descriptor.getAccessor()).getEmbeddable();
        }  else if (descriptor.getAccessor() instanceof DefaultClassSpecAccessor) {
//            descriptorManagedClass = ((DefaultClassSpecAccessor) descriptor.getAccessor()).getDefaultClass();
        } else {
            throw new IllegalStateException(descriptor.getAccessor() + " not supported");
        }

        for (DatabaseMapping mapping : descriptor.getMappings()) {
            ManagedClass managedClass = descriptorManagedClass;
            Attribute managedAttribute = (Attribute) mapping.getProperty(Attribute.class);
            Boolean isInherited = (Boolean) mapping.getProperty(Inheritance.class);
            isInherited = isInherited == null ? false : isInherited;
            
            if (intrinsicAttribute.peek() == null) {
                intrinsicAttribute.offer(managedAttribute);
            }

           if(managedAttribute instanceof RelationAttribute && !((RelationAttribute)managedAttribute).isOwner()){
               //skip non-owner
           } else if (descriptor.isChildDescriptor() && descriptor.getInheritancePolicy().getParentDescriptor().getMappingForAttributeName(mapping.getAttributeName()) != null) {
                // If we are an inheritance subclass, do nothing. That is, don't
                // generate mappings that will be generated by our parent,
                // otherwise the fields for that mapping will be generated n
                // times for the same table.
            } else if (mapping.isManyToManyMapping()) {
                buildRelationTableDefinition(managedClass, managedAttribute, intrinsicEntity, intrinsicAttribute, isInherited, (ManyToManyMapping) mapping, ((ManyToManyMapping) mapping).getRelationTableMechanism(), ((ManyToManyMapping) mapping).getListOrderField(), mapping.getContainerPolicy());
            } else if (mapping.isDirectCollectionMapping()) {
                buildDirectCollectionTableDefinition(managedClass, managedAttribute, intrinsicEntity, intrinsicAttribute, isInherited, (DirectCollectionMapping) mapping, descriptor);
            } else if (mapping.isDirectToFieldMapping()) {
                Converter converter = ((DirectToFieldMapping) mapping).getConverter();
                if (converter != null) {
                    if (converter instanceof TypeConversionConverter) {
                        resetFieldTypeForLOB((DirectToFieldMapping) mapping);
                    }

                    // uncomment on upgrade to eclipselink v2.7.2+
//                    if (converter instanceof SerializedObjectConverter) {
//                        //serialized object mapping field should be BLOB/IMAGE
//                        getFieldDefFromDBField(mapping.getField()).setType(((SerializedObjectConverter) converter).getSerializer().getType());
//                    }
                }
            } else if (mapping.isAggregateCollectionMapping()) {
                //need to figure out the target foreign key field and add it into the aggregate target table
//               if(managedAttribute instanceof ElementCollection || ((ElementCollection)managedAttribute).getConnectedClass()!=null){
//                   ClassDescriptor refDescriptor = mapping.getReferenceDescriptor();
//                                    Attribute attribute = getManagedAttribute(refDescriptor, dbField, intrinsicAttribute);//TODO intrinsicAttribute nested path/attribute not set
//
//               }
                createAggregateTargetTable(managedClass, managedAttribute, intrinsicEntity, intrinsicAttribute, isInherited, (AggregateCollectionMapping) mapping);
            } else if (mapping.isForeignReferenceMapping()) {
                if (mapping.isOneToOneMapping()) {
                    RelationTableMechanism relationTableMechanism = ((OneToOneMapping) mapping).getRelationTableMechanism();
                    if (relationTableMechanism == null) {
                        addForeignKeyFieldToSourceTargetTable(managedClass, managedAttribute, intrinsicEntity, intrinsicAttribute, isInherited, (OneToOneMapping) mapping);
                    } else {
                        buildRelationTableDefinition(managedClass, managedAttribute, intrinsicEntity, intrinsicAttribute, isInherited, (OneToOneMapping) mapping, relationTableMechanism, null, null);
                    }
                } else if (mapping.isOneToManyMapping()) {
                    addForeignKeyFieldToSourceTargetTable(managedClass, managedAttribute, intrinsicEntity, intrinsicAttribute, isInherited, (OneToManyMapping) mapping);
                    TableDefinition targTblDef = getTableDefFromDBTable(((OneToManyMapping) mapping).getReferenceDescriptor().getDefaultTable());//TODO pass entity
                    addFieldsForMappedKeyMapContainerPolicy(managedClass, managedAttribute, intrinsicEntity, intrinsicAttribute, isInherited, mapping.getContainerPolicy(), targTblDef);
                }
            } else if (mapping.isTransformationMapping()) {
                resetTransformedFieldType((TransformationMapping) mapping);
            } else if (mapping.isAggregateObjectMapping()) {
                postInitTableSchema(((AggregateObjectMapping) mapping).getReferenceDescriptor(), new LinkedList<>(intrinsicEntity), new LinkedList<>(intrinsicAttribute));
            }
            intrinsicAttribute.clear();
        }

        processAdditionalTablePkFields(intrinsicEntity, descriptor);
        intrinsicEntity.clear();

    }
 
Example 18
Source File: 00162 Beggar My Neighbour.java    From UVA with GNU General Public License v3.0 4 votes vote down vote up
public static void main (String [] args) throws Exception {
	BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
	String s;
	while (!(s=br.readLine()).equals("#")) {
		LinkedList<Character> [] deck=new LinkedList [] {new LinkedList<Character>(), new LinkedList<Character>()}; //0 = dealer, 1 = player
		int pid=1;
		
		String [] lines= {s,br.readLine(),br.readLine(),br.readLine()};
		for (String line : lines) {
			StringTokenizer st=new StringTokenizer(line);
			while (st.hasMoreTokens()) {
				deck[pid%2].addFirst(st.nextToken().charAt(1));
				pid=(pid+1)%2;
			}
		}
		
		int [] faces=new int[128];
		faces['A']=4;
		faces['J']=1;
		faces['Q']=2;
		faces['K']=3;
		
		LinkedList<Character> played=new LinkedList<>();
		int winner=-1;
		int owe=0;
		pid=1;
		while (winner==-1) { //Round
			if (deck[pid].isEmpty()) {
				winner=(pid+1)%2;
				break;
			}

			if (owe>0) {
				while (owe>0 && !deck[pid].isEmpty()) {
					played.addFirst(deck[pid].pop());
					owe--;
					if (faces[played.peek()]>0) break;
				}
				if (faces[played.peek()]>0) owe=faces[played.peek()];
				else {
					if (owe==0) while (!played.isEmpty()) deck[(pid+1)%2].addLast(played.removeLast());
					else {
						winner=(pid+1)%2;
						break;
					}
				}
			} else {
				played.addFirst(deck[pid].pop());
				owe = faces[played.peek()];
			}
			pid=(pid+1)%2;

		}
		
		StringBuilder sb=new StringBuilder();
		sb.append(winner+1);
		
		int ansSize=deck[winner].size();
		sb.append(' ');
		if (ansSize<10) sb.append(' '); 
		sb.append(ansSize);
		System.out.println(sb.toString());
	}
}
 
Example 19
Source File: Script.java    From SchoolQuest with GNU General Public License v3.0 4 votes vote down vote up
boolean isCommandFinished(@NonNull GameCharacter actor, int index) {
    LinkedList<Command> commands = commandsCopy.get(actor);
    return commands.isEmpty() || commands.peek().lineIndex > index;
}
 
Example 20
Source File: FloatingToolbar.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
public List<MenuItem> layoutMainPanelItems(List<MenuItem> menuItems, final int toolbarWidth) {
    int availableWidth = toolbarWidth;
    final LinkedList<MenuItem> remainingMenuItems = new LinkedList<>(menuItems);
    /*final LinkedList<MenuItem> overflowMenuItems = new LinkedList<>();
    for (MenuItem menuItem : menuItems) {
        if (menuItem.requiresOverflow()) {
            overflowMenuItems.add(menuItem); TODO
        } else {
            remainingMenuItems.add(menuItem);
        }
    }
    remainingMenuItems.addAll(overflowMenuItems);*/
    mMainPanel.removeAllViews();
    mMainPanel.setPaddingRelative(0, 0, 0, 0);
    boolean isFirstItem = true;
    while (!remainingMenuItems.isEmpty()) {
        final MenuItem menuItem = remainingMenuItems.peek();
        /*if (!isFirstItem && menuItem.requiresOverflow()) {
            break;
        }*/
        final View menuItemButton = createMenuItemButton(mContext, menuItem, mIconTextSpacing);
        if (menuItemButton instanceof LinearLayout) {
            ((LinearLayout) menuItemButton).setGravity(Gravity.CENTER);
        }
        if (isFirstItem) {
            menuItemButton.setPaddingRelative((int) (1.5 * menuItemButton.getPaddingStart()), menuItemButton.getPaddingTop(), menuItemButton.getPaddingEnd(), menuItemButton.getPaddingBottom());
        }
        boolean isLastItem = remainingMenuItems.size() == 1;
        if (isLastItem) {
            menuItemButton.setPaddingRelative(menuItemButton.getPaddingStart(), menuItemButton.getPaddingTop(), (int) (1.5 * menuItemButton.getPaddingEnd()), menuItemButton.getPaddingBottom());
        }
        menuItemButton.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED);
        final int menuItemButtonWidth = Math.min(menuItemButton.getMeasuredWidth(), toolbarWidth);
        final boolean canFitWithOverflow = menuItemButtonWidth <= availableWidth - mOverflowButtonSize.getWidth();
        final boolean canFitNoOverflow = isLastItem && menuItemButtonWidth <= availableWidth;
        if (canFitWithOverflow || canFitNoOverflow) {
            setButtonTagAndClickListener(menuItemButton, menuItem);
            //menuItemButton.setTooltipText(menuItem.getTooltipText()); TODO
            mMainPanel.addView(menuItemButton);
            final ViewGroup.LayoutParams params = menuItemButton.getLayoutParams();
            params.width = menuItemButtonWidth;
            menuItemButton.setLayoutParams(params);
            availableWidth -= menuItemButtonWidth;
            remainingMenuItems.pop();
        } else {
            break;
        }
        isFirstItem = false;
    }
    if (!remainingMenuItems.isEmpty()) {
        mMainPanel.setPaddingRelative(0, 0, mOverflowButtonSize.getWidth(), 0);
    }
    mMainPanelSize = measure(mMainPanel);
    return remainingMenuItems;
}